@kaana.ai/contracts 0.0.0-stage → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/LICENSE +673 -0
  2. package/NOTICE +21 -0
  3. package/dist/index.d.ts +29 -0
  4. package/dist/index.js +29 -0
  5. package/dist/internal/attribution.d.ts +116 -0
  6. package/dist/internal/attribution.js +82 -0
  7. package/dist/internal/canonical.d.ts +31 -0
  8. package/dist/internal/canonical.js +57 -0
  9. package/dist/internal/catalogue.d.ts +1059 -0
  10. package/dist/internal/catalogue.js +389 -0
  11. package/dist/internal/credentialControl.d.ts +329 -0
  12. package/dist/internal/credentialControl.js +256 -0
  13. package/dist/internal/decisions.d.ts +245 -0
  14. package/dist/internal/decisions.js +69 -0
  15. package/dist/internal/economics.d.ts +27 -0
  16. package/dist/internal/economics.js +26 -0
  17. package/dist/internal/embeddings.d.ts +164 -0
  18. package/dist/internal/embeddings.js +59 -0
  19. package/dist/internal/errors.d.ts +185 -0
  20. package/dist/internal/errors.js +211 -0
  21. package/dist/internal/grant.d.ts +699 -0
  22. package/dist/internal/grant.js +445 -0
  23. package/dist/internal/identifiers.d.ts +63 -0
  24. package/dist/internal/identifiers.js +65 -0
  25. package/dist/internal/privateAutoExecution.d.ts +158 -0
  26. package/dist/internal/privateAutoExecution.js +188 -0
  27. package/dist/internal/realtime.d.ts +1005 -0
  28. package/dist/internal/realtime.js +187 -0
  29. package/dist/internal/request.d.ts +1079 -0
  30. package/dist/internal/request.js +404 -0
  31. package/dist/internal/routing.d.ts +90 -0
  32. package/dist/internal/routing.js +139 -0
  33. package/dist/internal/scopedExecution.d.ts +74 -0
  34. package/dist/internal/scopedExecution.js +61 -0
  35. package/dist/internal/settlement.d.ts +205 -0
  36. package/dist/internal/settlement.js +71 -0
  37. package/dist/internal/streamEvents.d.ts +422 -0
  38. package/dist/internal/streamEvents.js +171 -0
  39. package/dist/internal/usage.d.ts +127 -0
  40. package/dist/internal/usage.js +109 -0
  41. package/dist/internal.d.ts +30 -0
  42. package/dist/internal.js +30 -0
  43. package/dist/public/audio.d.ts +347 -0
  44. package/dist/public/audio.js +236 -0
  45. package/dist/public/audioFormats.d.ts +64 -0
  46. package/dist/public/audioFormats.js +60 -0
  47. package/dist/public/catalogue.d.ts +914 -0
  48. package/dist/public/catalogue.js +516 -0
  49. package/dist/public/chatCompletions.d.ts +381 -0
  50. package/dist/public/chatCompletions.js +321 -0
  51. package/dist/public/decisions.d.ts +182 -0
  52. package/dist/public/decisions.js +257 -0
  53. package/dist/public/embeddings.d.ts +34 -0
  54. package/dist/public/embeddings.js +66 -0
  55. package/dist/public/errors.d.ts +195 -0
  56. package/dist/public/errors.js +274 -0
  57. package/dist/public/generations.d.ts +330 -0
  58. package/dist/public/generations.js +121 -0
  59. package/dist/public/identifiers.d.ts +139 -0
  60. package/dist/public/identifiers.js +160 -0
  61. package/dist/public/images.d.ts +36 -0
  62. package/dist/public/images.js +36 -0
  63. package/dist/public/messages.d.ts +297 -0
  64. package/dist/public/messages.js +251 -0
  65. package/dist/public/money.d.ts +308 -0
  66. package/dist/public/money.js +237 -0
  67. package/dist/public/policy.d.ts +19 -0
  68. package/dist/public/policy.js +20 -0
  69. package/dist/public/realtime.d.ts +2006 -0
  70. package/dist/public/realtime.js +797 -0
  71. package/dist/public/responses.d.ts +253 -0
  72. package/dist/public/responses.js +95 -0
  73. package/dist/public/streamEvents.d.ts +372 -0
  74. package/dist/public/streamEvents.js +157 -0
  75. package/dist/public/version.d.ts +184 -0
  76. package/dist/public/version.js +184 -0
  77. package/openapi.json +6967 -0
  78. package/package.json +44 -4
  79. package/README.md +0 -3
@@ -0,0 +1,127 @@
1
+ /**
2
+ * The normalized usage report: what Kaana measured, and the only shape a
3
+ * settlement is written from.
4
+ *
5
+ * Moved from `@oxy.so/contracts` 4.12.0 (`src/inference/usage.ts`) by Kaana ADR 0002.
6
+ * Reservations, receipts and refunds are the ledger and stay in
7
+ * `@oxy.so/contracts`.
8
+ */
9
+ import { z } from 'zod';
10
+ /**
11
+ * The data plane's technical account of one request, and the ONLY shape a
12
+ * settlement is written from.
13
+ *
14
+ * `inferenceStreamUsageEventSchema` is not a narrower version of this one that
15
+ * could be widened into it — see that event's own comment. Its units are exact
16
+ * and settleable; the record around them is not inferable, so an edge settling
17
+ * from a stream event supplies the outcome itself and never promotes the event.
18
+ *
19
+ * No money and no price: the data plane measures units and names the route it
20
+ * used, and the control plane decides what that costs. Keeping the two apart is
21
+ * what allows a price to be corrected after the fact without re-running or
22
+ * re-measuring anything.
23
+ *
24
+ * `usageSource` is load-bearing when a provider returns no usage at all: the
25
+ * report still arrives, marked `estimated`, so settlement can apply the
26
+ * estimation policy knowingly instead of treating a reconstruction as fact.
27
+ *
28
+ * `units` is a PARTITION of what the request consumed, not a set of totals with
29
+ * details hanging off them — see `USAGE_UNITS` in `money.ts`. Reporting a provider's
30
+ * nested `prompt_tokens`/`completion_tokens` verbatim charges the cached and
31
+ * reasoning tokens twice, so subtracting the children out is part of what
32
+ * "normalized" means in this shape's name.
33
+ *
34
+ * **A `completed` report carries at least one unit, and the other outcomes need
35
+ * not.** `completed` is the one outcome that asserts the customer received the
36
+ * whole answer, so "delivered in full, consumed nothing measurable" is a
37
+ * contradiction — and it is one that BILLS NOTHING: settlement prices every
38
+ * reported unit and sums, so an empty list is a free request produced by a
39
+ * provider that simply omitted its usage block. The refinement makes that shape
40
+ * unparseable, and the policy behind it is refuse-and-release: the report is
41
+ * rejected and the hold is released, never estimated and charged.
42
+ *
43
+ * The three other outcomes legitimately carry none, which is why the rule is
44
+ * conditional rather than a `.min(1)` on the field. In the reference data plane
45
+ * `failed` is DERIVED from having no units — `outcomeFor` in
46
+ * Kaana's `internal/kaana/executor.go` returns `partial` when units exist and `failed`
47
+ * when they do not — and `cancelled` is reported for a client that stopped
48
+ * before anything was measured. An unconditional minimum would refuse those
49
+ * reports, and a refused report is a request that ran, cost money upstream and
50
+ * can never be settled or refunded.
51
+ */
52
+ export declare const normalizedUsageReportSchema: z.ZodObject<{
53
+ schemaVersion: z.ZodLiteral<2>;
54
+ requestId: z.ZodString;
55
+ generationId: z.ZodOptional<z.ZodString>;
56
+ attribution: z.ZodObject<{
57
+ principal: z.ZodObject<{
58
+ billing: z.ZodObject<{
59
+ accountId: z.core.$ZodBranded<z.ZodString, "OxyAccountId", "out">;
60
+ }, z.core.$strict>;
61
+ applicationId: z.ZodString;
62
+ credentialId: z.ZodString;
63
+ environment: z.ZodEnum<{
64
+ development: "development";
65
+ staging: "staging";
66
+ production: "production";
67
+ }>;
68
+ inferenceScopes: z.ZodArray<z.ZodEnum<{
69
+ "inference:invoke": "inference:invoke";
70
+ "inference:models:read": "inference:models:read";
71
+ "inference:usage:read": "inference:usage:read";
72
+ "inference:routing:read": "inference:routing:read";
73
+ "inference:routing:write": "inference:routing:write";
74
+ "inference:providers:read": "inference:providers:read";
75
+ "inference:providers:write": "inference:providers:write";
76
+ }>>;
77
+ }, z.core.$strip>;
78
+ userId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "DelegatedUserId", "out">>;
79
+ requestId: z.ZodString;
80
+ generationId: z.ZodOptional<z.ZodString>;
81
+ }, z.core.$strip>;
82
+ outcome: z.ZodEnum<{
83
+ cancelled: "cancelled";
84
+ completed: "completed";
85
+ partial: "partial";
86
+ failed: "failed";
87
+ }>;
88
+ units: z.ZodArray<z.ZodObject<{
89
+ unit: z.ZodEnum<{
90
+ input_tokens: "input_tokens";
91
+ cached_input_tokens: "cached_input_tokens";
92
+ output_tokens: "output_tokens";
93
+ reasoning_tokens: "reasoning_tokens";
94
+ requests: "requests";
95
+ images: "images";
96
+ audio_input_milliseconds: "audio_input_milliseconds";
97
+ audio_output_milliseconds: "audio_output_milliseconds";
98
+ video_milliseconds: "video_milliseconds";
99
+ characters: "characters";
100
+ embeddings: "embeddings";
101
+ audio_input_tokens: "audio_input_tokens";
102
+ cached_audio_input_tokens: "cached_audio_input_tokens";
103
+ audio_output_tokens: "audio_output_tokens";
104
+ session_milliseconds: "session_milliseconds";
105
+ input_transcription_milliseconds: "input_transcription_milliseconds";
106
+ }>;
107
+ quantity: z.ZodNumber;
108
+ }, z.core.$strict>>;
109
+ usageSource: z.ZodEnum<{
110
+ provider_reported: "provider_reported";
111
+ oxy_measured: "oxy_measured";
112
+ estimated: "estimated";
113
+ }>;
114
+ resolvedModelReference: z.ZodString;
115
+ servingProvider: z.ZodString;
116
+ deploymentId: z.ZodString;
117
+ routeSwitches: z.ZodNumber;
118
+ fundingTier: z.ZodOptional<z.ZodEnum<{
119
+ free: "free";
120
+ credit: "credit";
121
+ paid: "paid";
122
+ }>>;
123
+ startedAt: z.ZodString;
124
+ completedAt: z.ZodString;
125
+ timeToFirstTokenMs: z.ZodOptional<z.ZodNumber>;
126
+ }, z.core.$strip>;
127
+ export type NormalizedUsageReport = z.infer<typeof normalizedUsageReportSchema>;
@@ -0,0 +1,109 @@
1
+ /**
2
+ * The normalized usage report: what Kaana measured, and the only shape a
3
+ * settlement is written from.
4
+ *
5
+ * Moved from `@oxy.so/contracts` 4.12.0 (`src/inference/usage.ts`) by Kaana ADR 0002.
6
+ * Reservations, receipts and refunds are the ledger and stay in
7
+ * `@oxy.so/contracts`.
8
+ */
9
+ import { z } from 'zod';
10
+ import { inferenceRequestOutcomeSchema } from '../public/generations.js';
11
+ import { generationIdSchema, inferenceTimestampSchema, modelReferenceSchema, requestIdSchema, } from '../public/identifiers.js';
12
+ import { usageQuantitySchema, usageSourceSchema } from '../public/money.js';
13
+ import { inferenceAttributionSchema } from './attribution.js';
14
+ import { deploymentIdSchema, inferenceFundingTierSchema, inferenceProviderSlugSchema, } from './identifiers.js';
15
+ /**
16
+ * The data plane's technical account of one request, and the ONLY shape a
17
+ * settlement is written from.
18
+ *
19
+ * `inferenceStreamUsageEventSchema` is not a narrower version of this one that
20
+ * could be widened into it — see that event's own comment. Its units are exact
21
+ * and settleable; the record around them is not inferable, so an edge settling
22
+ * from a stream event supplies the outcome itself and never promotes the event.
23
+ *
24
+ * No money and no price: the data plane measures units and names the route it
25
+ * used, and the control plane decides what that costs. Keeping the two apart is
26
+ * what allows a price to be corrected after the fact without re-running or
27
+ * re-measuring anything.
28
+ *
29
+ * `usageSource` is load-bearing when a provider returns no usage at all: the
30
+ * report still arrives, marked `estimated`, so settlement can apply the
31
+ * estimation policy knowingly instead of treating a reconstruction as fact.
32
+ *
33
+ * `units` is a PARTITION of what the request consumed, not a set of totals with
34
+ * details hanging off them — see `USAGE_UNITS` in `money.ts`. Reporting a provider's
35
+ * nested `prompt_tokens`/`completion_tokens` verbatim charges the cached and
36
+ * reasoning tokens twice, so subtracting the children out is part of what
37
+ * "normalized" means in this shape's name.
38
+ *
39
+ * **A `completed` report carries at least one unit, and the other outcomes need
40
+ * not.** `completed` is the one outcome that asserts the customer received the
41
+ * whole answer, so "delivered in full, consumed nothing measurable" is a
42
+ * contradiction — and it is one that BILLS NOTHING: settlement prices every
43
+ * reported unit and sums, so an empty list is a free request produced by a
44
+ * provider that simply omitted its usage block. The refinement makes that shape
45
+ * unparseable, and the policy behind it is refuse-and-release: the report is
46
+ * rejected and the hold is released, never estimated and charged.
47
+ *
48
+ * The three other outcomes legitimately carry none, which is why the rule is
49
+ * conditional rather than a `.min(1)` on the field. In the reference data plane
50
+ * `failed` is DERIVED from having no units — `outcomeFor` in
51
+ * Kaana's `internal/kaana/executor.go` returns `partial` when units exist and `failed`
52
+ * when they do not — and `cancelled` is reported for a client that stopped
53
+ * before anything was measured. An unconditional minimum would refuse those
54
+ * reports, and a refused report is a request that ran, cost money upstream and
55
+ * can never be settled or refunded.
56
+ */
57
+ export const normalizedUsageReportSchema = z
58
+ .object({
59
+ /** See `version.ts`: emitted by the data plane as a whole message. */
60
+ schemaVersion: z.literal(2),
61
+ requestId: requestIdSchema,
62
+ generationId: generationIdSchema.optional(),
63
+ attribution: inferenceAttributionSchema,
64
+ outcome: inferenceRequestOutcomeSchema,
65
+ units: z.array(usageQuantitySchema),
66
+ usageSource: usageSourceSchema,
67
+ resolvedModelReference: modelReferenceSchema,
68
+ servingProvider: inferenceProviderSlugSchema,
69
+ /** Exact Kaana deployment that attempted the request; never inferred from names. */
70
+ deploymentId: deploymentIdSchema,
71
+ /** How many allowed route switches occurred while serving this request. */
72
+ routeSwitches: z.number().int().nonnegative().max(100),
73
+ /**
74
+ * The funding tier of the platform key that served the final attempt, as
75
+ * the data plane states it (ADR 0038). Absent when the key's economics
76
+ * were never stated, when a customer credential served, or when nothing
77
+ * was served. Oxy reads it to account for what the request cost the
78
+ * platform; it is never a key identity and never reaches a customer.
79
+ */
80
+ fundingTier: inferenceFundingTierSchema.optional(),
81
+ startedAt: inferenceTimestampSchema,
82
+ completedAt: inferenceTimestampSchema,
83
+ timeToFirstTokenMs: z.number().int().nonnegative().safe().optional(),
84
+ })
85
+ .superRefine((report, ctx) => {
86
+ // Compared as instants: two spellings of one moment sort differently as text.
87
+ if (Date.parse(report.completedAt) < Date.parse(report.startedAt)) {
88
+ ctx.addIssue({
89
+ code: 'custom',
90
+ path: ['completedAt'],
91
+ message: 'a request cannot complete before it started',
92
+ });
93
+ }
94
+ const units = report.units.map((quantity) => quantity.unit);
95
+ if (new Set(units).size !== units.length) {
96
+ ctx.addIssue({
97
+ code: 'custom',
98
+ path: ['units'],
99
+ message: 'each unit is reported once, as a total',
100
+ });
101
+ }
102
+ if (report.outcome === 'completed' && report.units.length === 0) {
103
+ ctx.addIssue({
104
+ code: 'custom',
105
+ path: ['units'],
106
+ message: 'a completed request consumed something; report at least one unit',
107
+ });
108
+ }
109
+ });
@@ -0,0 +1,30 @@
1
+ /**
2
+ * `@kaana.ai/contracts/internal` — what Oxy and Kaana exchange privately.
3
+ *
4
+ * The grant and its authorization request, the settlement, the canonical
5
+ * input hash, the operational catalogue, customer-credential control and the
6
+ * signed v1–v4 envelope with its stream and usage report (retired at the end
7
+ * of the cut, Kaana ADR 0002 phase 5). Nothing here is a public API: it names
8
+ * providers, deployments, keys and billing accounts.
9
+ *
10
+ * Shared vocabulary (identifiers, messages, money) is imported from the
11
+ * package root; this entry point exports only what is internal.
12
+ */
13
+ export * from './internal/attribution.js';
14
+ export * from './internal/canonical.js';
15
+ export * from './internal/catalogue.js';
16
+ export * from './internal/credentialControl.js';
17
+ export * from './internal/decisions.js';
18
+ export * from './internal/economics.js';
19
+ export * from './internal/embeddings.js';
20
+ export * from './internal/errors.js';
21
+ export * from './internal/grant.js';
22
+ export * from './internal/identifiers.js';
23
+ export * from './internal/privateAutoExecution.js';
24
+ export * from './internal/realtime.js';
25
+ export * from './internal/request.js';
26
+ export * from './internal/routing.js';
27
+ export * from './internal/scopedExecution.js';
28
+ export * from './internal/settlement.js';
29
+ export * from './internal/streamEvents.js';
30
+ export * from './internal/usage.js';
@@ -0,0 +1,30 @@
1
+ /**
2
+ * `@kaana.ai/contracts/internal` — what Oxy and Kaana exchange privately.
3
+ *
4
+ * The grant and its authorization request, the settlement, the canonical
5
+ * input hash, the operational catalogue, customer-credential control and the
6
+ * signed v1–v4 envelope with its stream and usage report (retired at the end
7
+ * of the cut, Kaana ADR 0002 phase 5). Nothing here is a public API: it names
8
+ * providers, deployments, keys and billing accounts.
9
+ *
10
+ * Shared vocabulary (identifiers, messages, money) is imported from the
11
+ * package root; this entry point exports only what is internal.
12
+ */
13
+ export * from './internal/attribution.js';
14
+ export * from './internal/canonical.js';
15
+ export * from './internal/catalogue.js';
16
+ export * from './internal/credentialControl.js';
17
+ export * from './internal/decisions.js';
18
+ export * from './internal/economics.js';
19
+ export * from './internal/embeddings.js';
20
+ export * from './internal/errors.js';
21
+ export * from './internal/grant.js';
22
+ export * from './internal/identifiers.js';
23
+ export * from './internal/privateAutoExecution.js';
24
+ export * from './internal/realtime.js';
25
+ export * from './internal/request.js';
26
+ export * from './internal/routing.js';
27
+ export * from './internal/scopedExecution.js';
28
+ export * from './internal/settlement.js';
29
+ export * from './internal/streamEvents.js';
30
+ export * from './internal/usage.js';
@@ -0,0 +1,347 @@
1
+ /**
2
+ * `POST /v1/audio/speech` (with and without streaming) and
3
+ * `POST /v1/audio/transcriptions`.
4
+ *
5
+ * The speech request is moved from the Oxy edge
6
+ * (`packages/api/src/schemas/inferenceEdge.schemas.ts`) by Kaana ADR 0002;
7
+ * streaming speech (decision 8), the voice limits checked before a grant
8
+ * (decision 9) and transcription are new in contract set 4.0.0.
9
+ */
10
+ import { z } from 'zod';
11
+ import type { ModelAudioCapabilities } from './catalogue.js';
12
+ /** The longest text one speech request may carry, before any model's own limit. */
13
+ export declare const MAX_SPEECH_INPUT_CHARACTERS = 100000;
14
+ /**
15
+ * How a streamed speech response is carried:
16
+ *
17
+ * - `audio` (OpenAI-compatible): `200` with `Transfer-Encoding: chunked` and the
18
+ * raw bytes. A failure before the first byte is an HTTP status with an error
19
+ * body; one after it cuts the connection and the generation record keeps the
20
+ * code.
21
+ * - `sse` (what `@kaana.ai/sdk` uses): {@link speechStreamEventSchema} frames,
22
+ * so a failure mid-stream arrives typed.
23
+ */
24
+ export declare const speechStreamFormatSchema: z.ZodEnum<{
25
+ audio: "audio";
26
+ sse: "sse";
27
+ }>;
28
+ /**
29
+ * The formats speech can be streamed in: `audio/mpeg` and
30
+ * `audio/pcm;rate=24000`, the two containers that can be played as they arrive.
31
+ */
32
+ export declare const STREAMABLE_SPEECH_FORMATS: readonly ["mp3", "pcm"];
33
+ /**
34
+ * The request, in the shape a stock OpenAI client sends.
35
+ *
36
+ * `model` is a concrete model: a voice belongs to a model, so a power level,
37
+ * which may choose any of several, could not be validated against one.
38
+ */
39
+ export declare const speechRequestSchema: z.ZodObject<{
40
+ model: z.ZodString;
41
+ input: z.ZodString;
42
+ voice: z.ZodString;
43
+ response_format: z.ZodOptional<z.ZodEnum<{
44
+ mp3: "mp3";
45
+ opus: "opus";
46
+ aac: "aac";
47
+ flac: "flac";
48
+ wav: "wav";
49
+ pcm: "pcm";
50
+ }>>;
51
+ speed: z.ZodOptional<z.ZodNumber>;
52
+ stream: z.ZodOptional<z.ZodBoolean>;
53
+ stream_format: z.ZodOptional<z.ZodEnum<{
54
+ audio: "audio";
55
+ sse: "sse";
56
+ }>>;
57
+ user: z.ZodOptional<z.ZodString>;
58
+ }, z.core.$strict>;
59
+ /** One chunk of audio, in order, as soon as the provider produced it. */
60
+ export declare const speechAudioDeltaEventSchema: z.ZodObject<{
61
+ type: z.ZodLiteral<"speech.audio.delta">;
62
+ audio: z.ZodString;
63
+ }, z.core.$strict>;
64
+ /** The last event of a successful stream: what served it and what it consumed. */
65
+ export declare const speechAudioDoneEventSchema: z.ZodObject<{
66
+ type: z.ZodLiteral<"speech.audio.done">;
67
+ requestId: z.ZodString;
68
+ model: z.ZodString;
69
+ usage: z.ZodArray<z.ZodObject<{
70
+ unit: z.ZodEnum<{
71
+ input_tokens: "input_tokens";
72
+ cached_input_tokens: "cached_input_tokens";
73
+ output_tokens: "output_tokens";
74
+ reasoning_tokens: "reasoning_tokens";
75
+ requests: "requests";
76
+ images: "images";
77
+ audio_input_milliseconds: "audio_input_milliseconds";
78
+ audio_output_milliseconds: "audio_output_milliseconds";
79
+ video_milliseconds: "video_milliseconds";
80
+ characters: "characters";
81
+ embeddings: "embeddings";
82
+ audio_input_tokens: "audio_input_tokens";
83
+ cached_audio_input_tokens: "cached_audio_input_tokens";
84
+ audio_output_tokens: "audio_output_tokens";
85
+ session_milliseconds: "session_milliseconds";
86
+ input_transcription_milliseconds: "input_transcription_milliseconds";
87
+ }>;
88
+ quantity: z.ZodNumber;
89
+ }, z.core.$strict>>;
90
+ }, z.core.$strict>;
91
+ /** The terminal failure of a stream, after which nothing follows. */
92
+ export declare const speechStreamErrorEventSchema: z.ZodObject<{
93
+ type: z.ZodLiteral<"error">;
94
+ error: z.ZodObject<{
95
+ schemaVersion: z.ZodLiteral<1>;
96
+ code: z.ZodEnum<{
97
+ invalid_request: "invalid_request";
98
+ authentication_failed: "authentication_failed";
99
+ permission_denied: "permission_denied";
100
+ insufficient_scope: "insufficient_scope";
101
+ model_not_found: "model_not_found";
102
+ unsupported_modality: "unsupported_modality";
103
+ context_length_exceeded: "context_length_exceeded";
104
+ request_too_large: "request_too_large";
105
+ output_limit_exceeded: "output_limit_exceeded";
106
+ idempotency_conflict: "idempotency_conflict";
107
+ insufficient_balance: "insufficient_balance";
108
+ spending_limit_exceeded: "spending_limit_exceeded";
109
+ quota_exceeded: "quota_exceeded";
110
+ byok_credential_invalid: "byok_credential_invalid";
111
+ policy_violation: "policy_violation";
112
+ commercial_permission_denied: "commercial_permission_denied";
113
+ no_route_available: "no_route_available";
114
+ upstream_content_filtered: "upstream_content_filtered";
115
+ cancelled: "cancelled";
116
+ rate_limited: "rate_limited";
117
+ provider_error: "provider_error";
118
+ provider_timeout: "provider_timeout";
119
+ provider_overloaded: "provider_overloaded";
120
+ service_unavailable: "service_unavailable";
121
+ internal_error: "internal_error";
122
+ }>;
123
+ message: z.ZodString;
124
+ retryable: z.ZodBoolean;
125
+ requestId: z.ZodString;
126
+ retryAfterMs: z.ZodOptional<z.ZodNumber>;
127
+ param: z.ZodOptional<z.ZodString>;
128
+ upstreamCategory: z.ZodOptional<z.ZodEnum<{
129
+ rate_limit: "rate_limit";
130
+ quota: "quota";
131
+ timeout: "timeout";
132
+ overloaded: "overloaded";
133
+ server_error: "server_error";
134
+ content_filter: "content_filter";
135
+ invalid_request: "invalid_request";
136
+ authentication: "authentication";
137
+ unknown: "unknown";
138
+ }>>;
139
+ }, z.core.$strict>;
140
+ }, z.core.$strict>;
141
+ /**
142
+ * The frames of `stream_format: 'sse'`. The media type is not repeated: it is
143
+ * a function of the request's `response_format` ({@link speechMediaType}).
144
+ */
145
+ export declare const speechStreamEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
146
+ type: z.ZodLiteral<"speech.audio.delta">;
147
+ audio: z.ZodString;
148
+ }, z.core.$strict>, z.ZodObject<{
149
+ type: z.ZodLiteral<"speech.audio.done">;
150
+ requestId: z.ZodString;
151
+ model: z.ZodString;
152
+ usage: z.ZodArray<z.ZodObject<{
153
+ unit: z.ZodEnum<{
154
+ input_tokens: "input_tokens";
155
+ cached_input_tokens: "cached_input_tokens";
156
+ output_tokens: "output_tokens";
157
+ reasoning_tokens: "reasoning_tokens";
158
+ requests: "requests";
159
+ images: "images";
160
+ audio_input_milliseconds: "audio_input_milliseconds";
161
+ audio_output_milliseconds: "audio_output_milliseconds";
162
+ video_milliseconds: "video_milliseconds";
163
+ characters: "characters";
164
+ embeddings: "embeddings";
165
+ audio_input_tokens: "audio_input_tokens";
166
+ cached_audio_input_tokens: "cached_audio_input_tokens";
167
+ audio_output_tokens: "audio_output_tokens";
168
+ session_milliseconds: "session_milliseconds";
169
+ input_transcription_milliseconds: "input_transcription_milliseconds";
170
+ }>;
171
+ quantity: z.ZodNumber;
172
+ }, z.core.$strict>>;
173
+ }, z.core.$strict>, z.ZodObject<{
174
+ type: z.ZodLiteral<"error">;
175
+ error: z.ZodObject<{
176
+ schemaVersion: z.ZodLiteral<1>;
177
+ code: z.ZodEnum<{
178
+ invalid_request: "invalid_request";
179
+ authentication_failed: "authentication_failed";
180
+ permission_denied: "permission_denied";
181
+ insufficient_scope: "insufficient_scope";
182
+ model_not_found: "model_not_found";
183
+ unsupported_modality: "unsupported_modality";
184
+ context_length_exceeded: "context_length_exceeded";
185
+ request_too_large: "request_too_large";
186
+ output_limit_exceeded: "output_limit_exceeded";
187
+ idempotency_conflict: "idempotency_conflict";
188
+ insufficient_balance: "insufficient_balance";
189
+ spending_limit_exceeded: "spending_limit_exceeded";
190
+ quota_exceeded: "quota_exceeded";
191
+ byok_credential_invalid: "byok_credential_invalid";
192
+ policy_violation: "policy_violation";
193
+ commercial_permission_denied: "commercial_permission_denied";
194
+ no_route_available: "no_route_available";
195
+ upstream_content_filtered: "upstream_content_filtered";
196
+ cancelled: "cancelled";
197
+ rate_limited: "rate_limited";
198
+ provider_error: "provider_error";
199
+ provider_timeout: "provider_timeout";
200
+ provider_overloaded: "provider_overloaded";
201
+ service_unavailable: "service_unavailable";
202
+ internal_error: "internal_error";
203
+ }>;
204
+ message: z.ZodString;
205
+ retryable: z.ZodBoolean;
206
+ requestId: z.ZodString;
207
+ retryAfterMs: z.ZodOptional<z.ZodNumber>;
208
+ param: z.ZodOptional<z.ZodString>;
209
+ upstreamCategory: z.ZodOptional<z.ZodEnum<{
210
+ rate_limit: "rate_limit";
211
+ quota: "quota";
212
+ timeout: "timeout";
213
+ overloaded: "overloaded";
214
+ server_error: "server_error";
215
+ content_filter: "content_filter";
216
+ invalid_request: "invalid_request";
217
+ authentication: "authentication";
218
+ unknown: "unknown";
219
+ }>>;
220
+ }, z.core.$strict>;
221
+ }, z.core.$strict>], "type">;
222
+ /** Why a speech request cannot be served by a model, before anything is held. */
223
+ export interface SpeechRequestIssue {
224
+ /** The request field at fault, as `invalid_request.param` names it. */
225
+ readonly param: 'input' | 'voice' | 'response_format' | 'speed';
226
+ readonly message: string;
227
+ }
228
+ /**
229
+ * Check a speech request against the model's published audio capabilities
230
+ * (Kaana ADR 0002, decision 9). Kaana's handler refuses the request with
231
+ * `invalid_request` and the first issue's `param` BEFORE asking Oxy for a
232
+ * grant, so a `speed` of 1.5 for a model that publishes 0.7–1.2 holds no money;
233
+ * a client may run the same check first.
234
+ *
235
+ * Returns every issue, in field order; an empty list means the model accepts
236
+ * the request. Characters are counted in UTF-16 code units, as `length` does.
237
+ */
238
+ export declare function checkSpeechRequest(request: z.infer<typeof speechRequestSchema>, audio: ModelAudioCapabilities): SpeechRequestIssue[];
239
+ /** The largest audio file one transcription request may upload: 20 MiB. */
240
+ export declare const MAX_TRANSCRIPTION_FILE_BYTES: number;
241
+ /**
242
+ * The text fields of the `multipart/form-data` request. The audio itself is the
243
+ * `file` part, at most {@link MAX_TRANSCRIPTION_FILE_BYTES}, whose content type
244
+ * is one of `audioInputMediaTypeSchema`; it is binary and so is not a Zod shape.
245
+ * Synchronous: the transcription is the response.
246
+ */
247
+ export declare const transcriptionRequestSchema: z.ZodObject<{
248
+ model: z.ZodString;
249
+ language: z.ZodOptional<z.ZodString>;
250
+ prompt: z.ZodOptional<z.ZodString>;
251
+ timestamps: z.ZodOptional<z.ZodEnum<{
252
+ none: "none";
253
+ segment: "segment";
254
+ word: "word";
255
+ }>>;
256
+ }, z.core.$strict>;
257
+ /**
258
+ * The longest audio one transcription request may carry, when its container
259
+ * states a duration (WAV, raw PCM at a known rate). A file whose container does
260
+ * not state one is bounded by {@link MAX_TRANSCRIPTION_FILE_BYTES} alone: Kaana
261
+ * never guesses a duration from a byte count. New in contract set 4.2.0.
262
+ */
263
+ export declare const MAX_TRANSCRIPTION_AUDIO_MILLISECONDS: number;
264
+ /**
265
+ * The longest padded base64 the JSON form may carry: exactly the encoding of
266
+ * {@link MAX_TRANSCRIPTION_FILE_BYTES}.
267
+ */
268
+ export declare const MAX_TRANSCRIPTION_AUDIO_BASE64_LENGTH: number;
269
+ /**
270
+ * The JSON form of `POST /v1/audio/transcriptions` (`Content-Type:
271
+ * application/json`): the same fields as the multipart form, with the audio
272
+ * inline as padded base64. For runtimes where building a multipart body from
273
+ * bytes is unreliable (React Native); the two forms mean the same request and
274
+ * hash the same way. New in contract set 4.2.0.
275
+ */
276
+ export declare const transcriptionJsonRequestSchema: z.ZodObject<{
277
+ model: z.ZodString;
278
+ language: z.ZodOptional<z.ZodString>;
279
+ prompt: z.ZodOptional<z.ZodString>;
280
+ timestamps: z.ZodOptional<z.ZodEnum<{
281
+ none: "none";
282
+ segment: "segment";
283
+ word: "word";
284
+ }>>;
285
+ audio: z.ZodObject<{
286
+ mediaType: z.ZodEnum<{
287
+ "audio/mpeg": "audio/mpeg";
288
+ "audio/wav": "audio/wav";
289
+ "audio/ogg": "audio/ogg";
290
+ "audio/aac": "audio/aac";
291
+ "audio/flac": "audio/flac";
292
+ "audio/pcm": "audio/pcm";
293
+ "audio/mp4": "audio/mp4";
294
+ "audio/webm": "audio/webm";
295
+ }>;
296
+ data: z.ZodString;
297
+ }, z.core.$strict>;
298
+ }, z.core.$strict>;
299
+ /** The response. Segments or words are present only when the request asked for them. */
300
+ export declare const transcriptionSchema: z.ZodObject<{
301
+ schemaVersion: z.ZodLiteral<1>;
302
+ requestId: z.ZodString;
303
+ model: z.ZodString;
304
+ text: z.ZodString;
305
+ language: z.ZodOptional<z.ZodString>;
306
+ durationMs: z.ZodOptional<z.ZodNumber>;
307
+ segments: z.ZodOptional<z.ZodArray<z.ZodObject<{
308
+ text: z.ZodString;
309
+ startMs: z.ZodNumber;
310
+ endMs: z.ZodNumber;
311
+ }, z.core.$strict>>>;
312
+ words: z.ZodOptional<z.ZodArray<z.ZodObject<{
313
+ word: z.ZodString;
314
+ startMs: z.ZodNumber;
315
+ endMs: z.ZodNumber;
316
+ }, z.core.$strict>>>;
317
+ usage: z.ZodArray<z.ZodObject<{
318
+ unit: z.ZodEnum<{
319
+ input_tokens: "input_tokens";
320
+ cached_input_tokens: "cached_input_tokens";
321
+ output_tokens: "output_tokens";
322
+ reasoning_tokens: "reasoning_tokens";
323
+ requests: "requests";
324
+ images: "images";
325
+ audio_input_milliseconds: "audio_input_milliseconds";
326
+ audio_output_milliseconds: "audio_output_milliseconds";
327
+ video_milliseconds: "video_milliseconds";
328
+ characters: "characters";
329
+ embeddings: "embeddings";
330
+ audio_input_tokens: "audio_input_tokens";
331
+ cached_audio_input_tokens: "cached_audio_input_tokens";
332
+ audio_output_tokens: "audio_output_tokens";
333
+ session_milliseconds: "session_milliseconds";
334
+ input_transcription_milliseconds: "input_transcription_milliseconds";
335
+ }>;
336
+ quantity: z.ZodNumber;
337
+ }, z.core.$strict>>;
338
+ }, z.core.$strict>;
339
+ export type SpeechStreamFormat = z.infer<typeof speechStreamFormatSchema>;
340
+ export type SpeechRequest = z.infer<typeof speechRequestSchema>;
341
+ export type SpeechAudioDeltaEvent = z.infer<typeof speechAudioDeltaEventSchema>;
342
+ export type SpeechAudioDoneEvent = z.infer<typeof speechAudioDoneEventSchema>;
343
+ export type SpeechStreamErrorEvent = z.infer<typeof speechStreamErrorEventSchema>;
344
+ export type SpeechStreamEvent = z.infer<typeof speechStreamEventSchema>;
345
+ export type TranscriptionRequestFields = z.infer<typeof transcriptionRequestSchema>;
346
+ export type TranscriptionJsonRequest = z.infer<typeof transcriptionJsonRequestSchema>;
347
+ export type Transcription = z.infer<typeof transcriptionSchema>;