mirror of
https://github.com/HeyPuter/puter.git
synced 2026-11-26 15:48:41 +00:00
ai(alibaba): bill Omni prompt audio at the audio rate
This commit is contained in:
1 parent
32d5021c12
commit
5cc33ffc4a
4 files changed
+174
-2
No files matched your search
@@ -627,6 +627,147 @@ describe('AlibabaProvider.complete non-stream output', () => {
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
['qwen3-omni-flash', 381],
|
||||
['qwen3.5-omni-flash', 300],
|
||||
['qwen3.5-omni-plus', 1100],
|
||||
])('bills prompt audio on %s at its audio rate', async (modelId, audioRate) => {
|
||||
const { provider } = makeProvider();
|
||||
createMock.mockResolvedValueOnce({
|
||||
choices: [
|
||||
{
|
||||
message: { content: 'ok', role: 'assistant' },
|
||||
finish_reason: 'stop',
|
||||
},
|
||||
],
|
||||
usage: {
|
||||
prompt_tokens: 176,
|
||||
completion_tokens: 96,
|
||||
prompt_tokens_details: {
|
||||
cached_tokens: 0,
|
||||
audio_tokens: 114,
|
||||
text_tokens: 62,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const result = await withTestActor(() =>
|
||||
provider.complete({
|
||||
model: modelId,
|
||||
messages: [{ role: 'user', content: 'transcribe' }],
|
||||
}),
|
||||
);
|
||||
|
||||
const model = ALIBABA_MODELS.find((m) => m.id === modelId)!;
|
||||
expect(model.costs.audio_tokens).toBe(audioRate);
|
||||
const [usage, , , overrides] = recordSpy.mock.calls[0]!;
|
||||
expect(usage).toEqual({
|
||||
prompt_tokens: 62,
|
||||
audio_tokens: 114,
|
||||
completion_tokens: 96,
|
||||
cached_tokens: 0,
|
||||
});
|
||||
expect(overrides).toEqual({
|
||||
prompt_tokens: 62 * Number(model.costs.prompt_tokens),
|
||||
audio_tokens: 114 * audioRate,
|
||||
completion_tokens: 96 * Number(model.costs.completion_tokens),
|
||||
cached_tokens: 0,
|
||||
});
|
||||
expect(
|
||||
(result as { usageDetails?: unknown }).usageDetails,
|
||||
).toMatchObject({ inputTokens: 176, outputTokens: 96 });
|
||||
});
|
||||
|
||||
it('bills streamed prompt audio at the audio rate when the live catalog lists the model', async () => {
|
||||
axiosGetMock.mockResolvedValueOnce({
|
||||
data: {
|
||||
success: true,
|
||||
output: {
|
||||
total: 1,
|
||||
page_no: 1,
|
||||
models: [
|
||||
{
|
||||
model: 'qwen3.5-omni-flash',
|
||||
capabilities: ['TG', 'VU'],
|
||||
inference_metadata: {
|
||||
request_modality: [
|
||||
'Text',
|
||||
'Image',
|
||||
'Audio',
|
||||
'Video',
|
||||
],
|
||||
response_modality: ['Text', 'Audio'],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
const { provider } = makeProvider();
|
||||
createMock.mockReturnValueOnce(
|
||||
asAsyncIterable([
|
||||
{ choices: [{ delta: { content: 'ok' } }] },
|
||||
{
|
||||
choices: [],
|
||||
usage: {
|
||||
prompt_tokens: 176,
|
||||
completion_tokens: 96,
|
||||
prompt_tokens_details: { audio_tokens: 114 },
|
||||
},
|
||||
},
|
||||
]),
|
||||
);
|
||||
|
||||
const result = await withTestActor(() =>
|
||||
provider.complete({
|
||||
model: 'qwen3.5-omni-flash',
|
||||
messages: [{ role: 'user', content: 'transcribe' }],
|
||||
stream: true,
|
||||
}),
|
||||
);
|
||||
const harness = makeCapturingChatStream();
|
||||
await (
|
||||
result as {
|
||||
init_chat_stream: (p: { chatStream: unknown }) => Promise<void>;
|
||||
}
|
||||
).init_chat_stream({ chatStream: harness.chatStream });
|
||||
|
||||
const [usage, , , overrides] = recordSpy.mock.calls[0]!;
|
||||
expect(usage).toMatchObject({ prompt_tokens: 62, audio_tokens: 114 });
|
||||
expect(overrides).toMatchObject({ audio_tokens: 114 * 300 });
|
||||
});
|
||||
|
||||
it('keeps one input rate for prompt audio on qwen3.8-omni-flash', async () => {
|
||||
const { provider } = makeProvider();
|
||||
createMock.mockResolvedValueOnce({
|
||||
choices: [
|
||||
{
|
||||
message: { content: 'ok', role: 'assistant' },
|
||||
finish_reason: 'stop',
|
||||
},
|
||||
],
|
||||
usage: {
|
||||
prompt_tokens: 176,
|
||||
completion_tokens: 96,
|
||||
prompt_tokens_details: { cached_tokens: 0, audio_tokens: 114 },
|
||||
},
|
||||
});
|
||||
|
||||
await withTestActor(() =>
|
||||
provider.complete({
|
||||
model: 'qwen3.8-omni-flash',
|
||||
messages: [{ role: 'user', content: 'transcribe' }],
|
||||
}),
|
||||
);
|
||||
|
||||
const [usage] = recordSpy.mock.calls[0]!;
|
||||
expect(usage).toEqual({
|
||||
prompt_tokens: 176,
|
||||
completion_tokens: 96,
|
||||
cached_tokens: 0,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// ── Streaming deltas ────────────────────────────────────────────────
|
||||
|
||||
@@ -26,7 +26,9 @@ import { sdkClientOptions } from '../../../interfaces/chat/utils/sdkClient.js';
|
||||
import {
|
||||
type ChatProviderConfig,
|
||||
OpenAICompatProvider,
|
||||
type UsageSource,
|
||||
} from '../../../protocols/openaiCompatible/OpenAICompatProvider.js';
|
||||
import * as OpenAIUtil from '../../../protocols/openaiCompatible/OpenAIUtil.js';
|
||||
import { ALIBABA_MODELS } from './models.js';
|
||||
|
||||
export class AlibabaProvider extends OpenAICompatProvider {
|
||||
@@ -60,6 +62,27 @@ export class AlibabaProvider extends OpenAICompatProvider {
|
||||
return this.#catalog();
|
||||
}
|
||||
|
||||
/** Prompt audio is billed at the model's audio rate where it has one. */
|
||||
protected override meteredUsage(source: UsageSource, model: IChatModel) {
|
||||
const metered = super.meteredUsage(source, model);
|
||||
if (model.costs.audio_tokens === undefined) return metered;
|
||||
const { usage } = metered;
|
||||
const reported = source.usage?.prompt_tokens_details?.audio_tokens;
|
||||
const audioTokens =
|
||||
typeof reported === 'number' && Number.isFinite(reported)
|
||||
? Math.min(Math.max(0, reported), usage.prompt_tokens)
|
||||
: 0;
|
||||
return {
|
||||
...metered,
|
||||
usage: {
|
||||
...usage,
|
||||
prompt_tokens: usage.prompt_tokens - audioTokens,
|
||||
audio_tokens: audioTokens,
|
||||
},
|
||||
usageDetails: OpenAIUtil.usageDetailsFromTrackedUsage(usage),
|
||||
};
|
||||
}
|
||||
|
||||
#catalog = cachedRemoteCatalog({
|
||||
name: 'Alibaba catalog',
|
||||
fallback: ALIBABA_MODELS,
|
||||
|
||||
@@ -527,7 +527,8 @@ export const ALIBABA_MODELS: IChatModel[] = [
|
||||
completion_tokens: 160,
|
||||
},
|
||||
},
|
||||
// -- Omni models (text interface, audio costs excluded) ---------
|
||||
// -- Omni models ------------------------------------------------
|
||||
// Rates per input modality: https://www.alibabacloud.com/help/en/model-studio/model-pricing
|
||||
{
|
||||
puterId: 'alibaba:qwen/qwen3-omni-flash',
|
||||
id: 'qwen3-omni-flash',
|
||||
@@ -550,6 +551,7 @@ export const ALIBABA_MODELS: IChatModel[] = [
|
||||
costs: {
|
||||
tokens: 1_000_000,
|
||||
prompt_tokens: 43,
|
||||
audio_tokens: 381,
|
||||
completion_tokens: 166,
|
||||
},
|
||||
},
|
||||
@@ -907,7 +909,8 @@ export const ALIBABA_MODELS: IChatModel[] = [
|
||||
completion_tokens: 600,
|
||||
},
|
||||
},
|
||||
// -- Omni additions (text interface, audio costs excluded) ----
|
||||
// -- Omni additions ---------------------------------------------
|
||||
// Rates per input modality: https://www.alibabacloud.com/help/en/model-studio/model-pricing
|
||||
{
|
||||
puterId: 'alibaba:qwen/qwen3.5-omni-flash',
|
||||
id: 'qwen3.5-omni-flash',
|
||||
@@ -929,6 +932,7 @@ export const ALIBABA_MODELS: IChatModel[] = [
|
||||
costs: {
|
||||
tokens: 1_000_000,
|
||||
prompt_tokens: 40,
|
||||
audio_tokens: 300,
|
||||
completion_tokens: 220,
|
||||
},
|
||||
},
|
||||
@@ -953,6 +957,7 @@ export const ALIBABA_MODELS: IChatModel[] = [
|
||||
costs: {
|
||||
tokens: 1_000_000,
|
||||
prompt_tokens: 140,
|
||||
audio_tokens: 1100,
|
||||
completion_tokens: 830,
|
||||
},
|
||||
},
|
||||
@@ -974,6 +979,7 @@ export const ALIBABA_MODELS: IChatModel[] = [
|
||||
input_cost_key: 'prompt_tokens',
|
||||
output_cost_key: 'completion_tokens',
|
||||
serviceSpeedVariants: { fast: 'qwen3.8-omni-flash-prime' },
|
||||
// One input rate for every modality, audio included.
|
||||
costs: {
|
||||
tokens: 1_000_000,
|
||||
prompt_tokens: 15,
|
||||
|
||||
@@ -626,6 +626,8 @@ Passing `service_tier: "auto"` selects fast service, with the same prices as `se
|
||||
|
||||
Models with an equivalent Prime or Fast variant select that variant for fast service. Other models use standard service.
|
||||
|
||||
Qwen3-Omni Flash, Qwen3.5-Omni Flash, and Qwen3.5-Omni Plus charge audio input at the audio token rate, including the audio track of a video.
|
||||
|
||||
### OpenRouter models
|
||||
|
||||
Faster tiers come from the selected model's endpoint catalog. A tier can fall back upstream. Billing uses the endpoint that serves the request.
|
||||
|
||||
Reference in new issue
Block a user