@oxyhq/contracts 0.25.0 → 0.27.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 (59) hide show
  1. package/NOTICE +10 -9
  2. package/dist/cjs/.tsbuildinfo +1 -1
  3. package/dist/cjs/accountGraph.js +4 -3
  4. package/dist/cjs/browserHub.js +215 -0
  5. package/dist/cjs/deviceDirectory.js +189 -0
  6. package/dist/cjs/index.js +172 -2
  7. package/dist/cjs/inference/attribution.js +101 -0
  8. package/dist/cjs/inference/catalogue.js +482 -0
  9. package/dist/cjs/inference/errors.js +195 -0
  10. package/dist/cjs/inference/identifiers.js +189 -0
  11. package/dist/cjs/inference/money.js +145 -0
  12. package/dist/cjs/inference/priceVersion.js +110 -0
  13. package/dist/cjs/inference/providerConnection.js +142 -0
  14. package/dist/cjs/inference/request.js +288 -0
  15. package/dist/cjs/inference/routingPolicy.js +213 -0
  16. package/dist/cjs/inference/streamEvents.js +219 -0
  17. package/dist/cjs/inference/usage.js +291 -0
  18. package/dist/cjs/inference/version.js +57 -0
  19. package/dist/cjs/oauth.js +66 -0
  20. package/dist/esm/.tsbuildinfo +1 -1
  21. package/dist/esm/accountGraph.js +4 -3
  22. package/dist/esm/browserHub.js +212 -0
  23. package/dist/esm/deviceDirectory.js +186 -0
  24. package/dist/esm/index.js +48 -0
  25. package/dist/esm/inference/attribution.js +98 -0
  26. package/dist/esm/inference/catalogue.js +479 -0
  27. package/dist/esm/inference/errors.js +192 -0
  28. package/dist/esm/inference/identifiers.js +186 -0
  29. package/dist/esm/inference/money.js +142 -0
  30. package/dist/esm/inference/priceVersion.js +107 -0
  31. package/dist/esm/inference/providerConnection.js +139 -0
  32. package/dist/esm/inference/request.js +285 -0
  33. package/dist/esm/inference/routingPolicy.js +210 -0
  34. package/dist/esm/inference/streamEvents.js +216 -0
  35. package/dist/esm/inference/usage.js +288 -0
  36. package/dist/esm/inference/version.js +54 -0
  37. package/dist/esm/oauth.js +63 -0
  38. package/dist/types/.tsbuildinfo +1 -1
  39. package/dist/types/accountGraph.d.ts +6 -5
  40. package/dist/types/browserHub.d.ts +856 -0
  41. package/dist/types/deviceDirectory.d.ts +1317 -0
  42. package/dist/types/deviceSession.d.ts +46 -46
  43. package/dist/types/index.d.ts +29 -0
  44. package/dist/types/inference/attribution.d.ts +171 -0
  45. package/dist/types/inference/catalogue.d.ts +1612 -0
  46. package/dist/types/inference/errors.d.ts +193 -0
  47. package/dist/types/inference/identifiers.d.ts +149 -0
  48. package/dist/types/inference/money.d.ts +142 -0
  49. package/dist/types/inference/priceVersion.d.ts +182 -0
  50. package/dist/types/inference/providerConnection.d.ts +297 -0
  51. package/dist/types/inference/request.d.ts +2364 -0
  52. package/dist/types/inference/routingPolicy.d.ts +426 -0
  53. package/dist/types/inference/streamEvents.d.ts +906 -0
  54. package/dist/types/inference/usage.d.ts +1133 -0
  55. package/dist/types/inference/version.d.ts +54 -0
  56. package/dist/types/oauth.d.ts +86 -0
  57. package/dist/types/sessionStatus.d.ts +8 -8
  58. package/dist/types/userResponse.d.ts +8 -8
  59. package/package.json +1 -1
@@ -0,0 +1,193 @@
1
+ /**
2
+ * Inference errors and retryability.
3
+ *
4
+ * One closed set of codes, shared by the Oxy public edge, the data plane and
5
+ * every SDK.
6
+ * Closed because the alternative — a free-form `code` string — makes a client's
7
+ * error handling a guess about the producer's spelling, and makes "is this
8
+ * worth retrying" a decision every consumer re-derives from prose.
9
+ *
10
+ * Retryability is carried explicitly and is CONSTRAINED by the code: a code
11
+ * that can never succeed on a bare retry (an invalid request, a denied
12
+ * permission, an insufficient balance) cannot claim `retryable: true`. Without
13
+ * that constraint the field is advisory, and one producer setting it optimistically
14
+ * turns every client into a retry storm against a request that will never pass.
15
+ *
16
+ * The provider passthrough exists so a customer can see what the upstream said
17
+ * without Oxy having to interpret every provider's error vocabulary — but it is
18
+ * the single most likely place for an upstream credential to escape, because
19
+ * provider errors routinely echo the request that caused them. It is therefore
20
+ * a `.strict()` object of four fields with no room for headers or a request
21
+ * body, and its free text is refused if it looks like it contains a credential.
22
+ *
23
+ * Decided in: docs/adr/0010-public-api-compatibility.md.
24
+ */
25
+ import { z } from 'zod';
26
+ /**
27
+ * The closed set of inference error codes.
28
+ *
29
+ * Grouped by who must act: the caller (`invalid_request` … `idempotency_conflict`),
30
+ * the account owner (`insufficient_balance`, `spending_limit_exceeded`,
31
+ * `quota_exceeded`, `byok_credential_invalid`), routing/permission policy
32
+ * (`policy_violation`, `commercial_permission_denied`, `no_route_available`),
33
+ * and the platform or its upstreams (everything from `deployment_unavailable`).
34
+ */
35
+ export declare const INFERENCE_ERROR_CODES: readonly ["invalid_request", "authentication_failed", "permission_denied", "insufficient_scope", "model_not_found", "unsupported_modality", "context_length_exceeded", "request_too_large", "output_limit_exceeded", "idempotency_conflict", "insufficient_balance", "spending_limit_exceeded", "quota_exceeded", "byok_credential_invalid", "policy_violation", "commercial_permission_denied", "no_route_available", "upstream_content_filtered", "cancelled", "rate_limited", "deployment_unavailable", "provider_error", "provider_timeout", "provider_overloaded", "service_unavailable", "internal_error"];
36
+ export declare const inferenceErrorCodeSchema: z.ZodEnum<["invalid_request", "authentication_failed", "permission_denied", "insufficient_scope", "model_not_found", "unsupported_modality", "context_length_exceeded", "request_too_large", "output_limit_exceeded", "idempotency_conflict", "insufficient_balance", "spending_limit_exceeded", "quota_exceeded", "byok_credential_invalid", "policy_violation", "commercial_permission_denied", "no_route_available", "upstream_content_filtered", "cancelled", "rate_limited", "deployment_unavailable", "provider_error", "provider_timeout", "provider_overloaded", "service_unavailable", "internal_error"]>;
37
+ /**
38
+ * Codes for which an identical retried request cannot succeed.
39
+ *
40
+ * `rate_limited` and `quota_exceeded` sit on opposite sides of this line
41
+ * deliberately: a rate limit clears on its own within the window the response
42
+ * names, while a quota is an account-level ceiling that only a human raises.
43
+ * `cancelled` is here because the caller already withdrew the request; a client
44
+ * that retries it is contradicting its own cancellation.
45
+ */
46
+ export declare const NON_RETRYABLE_INFERENCE_ERROR_CODES: readonly ["invalid_request", "authentication_failed", "permission_denied", "insufficient_scope", "model_not_found", "unsupported_modality", "context_length_exceeded", "request_too_large", "output_limit_exceeded", "idempotency_conflict", "insufficient_balance", "spending_limit_exceeded", "quota_exceeded", "byok_credential_invalid", "policy_violation", "commercial_permission_denied", "no_route_available", "upstream_content_filtered", "cancelled"];
47
+ /**
48
+ * Free text that is safe to hand a customer: bounded, and refused outright if a
49
+ * credential marker appears in it. Applied to BOTH the Oxy message and the
50
+ * upstream one — a leak is no less a leak for having been written by a provider.
51
+ */
52
+ export declare const safeErrorTextSchema: z.ZodEffects<z.ZodString, string, string>;
53
+ /**
54
+ * A coarse classification of an upstream failure (ADR 0010's `upstreamCategory`).
55
+ *
56
+ * Distinct from {@link providerErrorPassthroughSchema}, which carries the
57
+ * upstream's OWN code and text: this is Oxy's reading of what kind of failure it
58
+ * was, in a vocabulary that is the same across every provider, so a client can
59
+ * branch on it without knowing who served the request.
60
+ */
61
+ export declare const upstreamErrorCategorySchema: z.ZodEnum<["rate_limit", "quota", "timeout", "overloaded", "server_error", "content_filter", "invalid_request", "authentication", "unknown"]>;
62
+ /**
63
+ * What the upstream provider said, reduced to the four fields a customer can
64
+ * act on.
65
+ *
66
+ * `.strict()` is the security control here, not a tidiness preference: it means
67
+ * a producer cannot widen this by attaching `requestHeaders`, `curl`, `body` or
68
+ * `raw` and have it silently pass. Adding a field is a contract change with a
69
+ * version bump and a review, which is the point.
70
+ */
71
+ export declare const providerErrorPassthroughSchema: z.ZodObject<{
72
+ provider: z.ZodString;
73
+ /** The upstream HTTP status, when the upstream spoke HTTP. */
74
+ status: z.ZodOptional<z.ZodNumber>;
75
+ /** The upstream's own error code, verbatim and uninterpreted. */
76
+ code: z.ZodOptional<z.ZodString>;
77
+ /** The upstream's message, subject to the same credential refusal. */
78
+ message: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
79
+ }, "strict", z.ZodTypeAny, {
80
+ provider: string;
81
+ code?: string | undefined;
82
+ message?: string | undefined;
83
+ status?: number | undefined;
84
+ }, {
85
+ provider: string;
86
+ code?: string | undefined;
87
+ message?: string | undefined;
88
+ status?: number | undefined;
89
+ }>;
90
+ /**
91
+ * The error body every inference surface returns and every stream error event
92
+ * carries.
93
+ *
94
+ * `requestId` is always present — an error a customer cannot correlate with a
95
+ * log line is an error they have to reproduce to report.
96
+ */
97
+ export declare const inferenceErrorSchema: z.ZodEffects<z.ZodObject<{
98
+ /** See `version.ts`: this shape appears alone on the wire, so it is versioned. */
99
+ schemaVersion: z.ZodLiteral<1>;
100
+ code: z.ZodEnum<["invalid_request", "authentication_failed", "permission_denied", "insufficient_scope", "model_not_found", "unsupported_modality", "context_length_exceeded", "request_too_large", "output_limit_exceeded", "idempotency_conflict", "insufficient_balance", "spending_limit_exceeded", "quota_exceeded", "byok_credential_invalid", "policy_violation", "commercial_permission_denied", "no_route_available", "upstream_content_filtered", "cancelled", "rate_limited", "deployment_unavailable", "provider_error", "provider_timeout", "provider_overloaded", "service_unavailable", "internal_error"]>;
101
+ message: z.ZodEffects<z.ZodString, string, string>;
102
+ retryable: z.ZodBoolean;
103
+ requestId: z.ZodString;
104
+ /** How long to wait before retrying. Only meaningful when `retryable`. */
105
+ retryAfterMs: z.ZodOptional<z.ZodNumber>;
106
+ /** The request field at fault, for `invalid_request`. */
107
+ param: z.ZodOptional<z.ZodString>;
108
+ /** Present only when an upstream provider was reached and failed. */
109
+ upstreamCategory: z.ZodOptional<z.ZodEnum<["rate_limit", "quota", "timeout", "overloaded", "server_error", "content_filter", "invalid_request", "authentication", "unknown"]>>;
110
+ providerError: z.ZodOptional<z.ZodObject<{
111
+ provider: z.ZodString;
112
+ /** The upstream HTTP status, when the upstream spoke HTTP. */
113
+ status: z.ZodOptional<z.ZodNumber>;
114
+ /** The upstream's own error code, verbatim and uninterpreted. */
115
+ code: z.ZodOptional<z.ZodString>;
116
+ /** The upstream's message, subject to the same credential refusal. */
117
+ message: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
118
+ }, "strict", z.ZodTypeAny, {
119
+ provider: string;
120
+ code?: string | undefined;
121
+ message?: string | undefined;
122
+ status?: number | undefined;
123
+ }, {
124
+ provider: string;
125
+ code?: string | undefined;
126
+ message?: string | undefined;
127
+ status?: number | undefined;
128
+ }>>;
129
+ }, "strip", z.ZodTypeAny, {
130
+ code: "invalid_request" | "authentication_failed" | "permission_denied" | "insufficient_scope" | "model_not_found" | "unsupported_modality" | "context_length_exceeded" | "request_too_large" | "output_limit_exceeded" | "idempotency_conflict" | "insufficient_balance" | "spending_limit_exceeded" | "quota_exceeded" | "byok_credential_invalid" | "policy_violation" | "commercial_permission_denied" | "no_route_available" | "upstream_content_filtered" | "cancelled" | "rate_limited" | "deployment_unavailable" | "provider_error" | "provider_timeout" | "provider_overloaded" | "service_unavailable" | "internal_error";
131
+ message: string;
132
+ requestId: string;
133
+ schemaVersion: 1;
134
+ retryable: boolean;
135
+ retryAfterMs?: number | undefined;
136
+ param?: string | undefined;
137
+ upstreamCategory?: "unknown" | "authentication" | "invalid_request" | "rate_limit" | "quota" | "timeout" | "overloaded" | "server_error" | "content_filter" | undefined;
138
+ providerError?: {
139
+ provider: string;
140
+ code?: string | undefined;
141
+ message?: string | undefined;
142
+ status?: number | undefined;
143
+ } | undefined;
144
+ }, {
145
+ code: "invalid_request" | "authentication_failed" | "permission_denied" | "insufficient_scope" | "model_not_found" | "unsupported_modality" | "context_length_exceeded" | "request_too_large" | "output_limit_exceeded" | "idempotency_conflict" | "insufficient_balance" | "spending_limit_exceeded" | "quota_exceeded" | "byok_credential_invalid" | "policy_violation" | "commercial_permission_denied" | "no_route_available" | "upstream_content_filtered" | "cancelled" | "rate_limited" | "deployment_unavailable" | "provider_error" | "provider_timeout" | "provider_overloaded" | "service_unavailable" | "internal_error";
146
+ message: string;
147
+ requestId: string;
148
+ schemaVersion: 1;
149
+ retryable: boolean;
150
+ retryAfterMs?: number | undefined;
151
+ param?: string | undefined;
152
+ upstreamCategory?: "unknown" | "authentication" | "invalid_request" | "rate_limit" | "quota" | "timeout" | "overloaded" | "server_error" | "content_filter" | undefined;
153
+ providerError?: {
154
+ provider: string;
155
+ code?: string | undefined;
156
+ message?: string | undefined;
157
+ status?: number | undefined;
158
+ } | undefined;
159
+ }>, {
160
+ code: "invalid_request" | "authentication_failed" | "permission_denied" | "insufficient_scope" | "model_not_found" | "unsupported_modality" | "context_length_exceeded" | "request_too_large" | "output_limit_exceeded" | "idempotency_conflict" | "insufficient_balance" | "spending_limit_exceeded" | "quota_exceeded" | "byok_credential_invalid" | "policy_violation" | "commercial_permission_denied" | "no_route_available" | "upstream_content_filtered" | "cancelled" | "rate_limited" | "deployment_unavailable" | "provider_error" | "provider_timeout" | "provider_overloaded" | "service_unavailable" | "internal_error";
161
+ message: string;
162
+ requestId: string;
163
+ schemaVersion: 1;
164
+ retryable: boolean;
165
+ retryAfterMs?: number | undefined;
166
+ param?: string | undefined;
167
+ upstreamCategory?: "unknown" | "authentication" | "invalid_request" | "rate_limit" | "quota" | "timeout" | "overloaded" | "server_error" | "content_filter" | undefined;
168
+ providerError?: {
169
+ provider: string;
170
+ code?: string | undefined;
171
+ message?: string | undefined;
172
+ status?: number | undefined;
173
+ } | undefined;
174
+ }, {
175
+ code: "invalid_request" | "authentication_failed" | "permission_denied" | "insufficient_scope" | "model_not_found" | "unsupported_modality" | "context_length_exceeded" | "request_too_large" | "output_limit_exceeded" | "idempotency_conflict" | "insufficient_balance" | "spending_limit_exceeded" | "quota_exceeded" | "byok_credential_invalid" | "policy_violation" | "commercial_permission_denied" | "no_route_available" | "upstream_content_filtered" | "cancelled" | "rate_limited" | "deployment_unavailable" | "provider_error" | "provider_timeout" | "provider_overloaded" | "service_unavailable" | "internal_error";
176
+ message: string;
177
+ requestId: string;
178
+ schemaVersion: 1;
179
+ retryable: boolean;
180
+ retryAfterMs?: number | undefined;
181
+ param?: string | undefined;
182
+ upstreamCategory?: "unknown" | "authentication" | "invalid_request" | "rate_limit" | "quota" | "timeout" | "overloaded" | "server_error" | "content_filter" | undefined;
183
+ providerError?: {
184
+ provider: string;
185
+ code?: string | undefined;
186
+ message?: string | undefined;
187
+ status?: number | undefined;
188
+ } | undefined;
189
+ }>;
190
+ export type InferenceErrorCode = z.infer<typeof inferenceErrorCodeSchema>;
191
+ export type UpstreamErrorCategory = z.infer<typeof upstreamErrorCategorySchema>;
192
+ export type ProviderErrorPassthrough = z.infer<typeof providerErrorPassthroughSchema>;
193
+ export type InferenceError = z.infer<typeof inferenceErrorSchema>;
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Identifiers, references and wire primitives shared by every Oxy↔data-plane
3
+ * inference contract.
4
+ *
5
+ * Two kinds of identifier live here, and the difference matters:
6
+ *
7
+ * - **Principal identifiers** owned by Oxy (`accountId`, `applicationId`,
8
+ * `credentialId`, the optional delegated `userId`). The data plane may store
9
+ * them as immutable references; it never owns, mints or mutates them.
10
+ * - **Catalogue references** (`<publisher>/<model>`, `<publisher>/<model>@<revision>`,
11
+ * a routing-profile slug). These are the strings a customer types, so their
12
+ * grammar is part of the public contract, not an implementation detail.
13
+ *
14
+ * Platform-agnostic — zod only. Every regex here is plain ASCII: this package
15
+ * is imported by React Native apps running on Hermes, which rejects Unicode
16
+ * property escapes (`\p{…}`) at runtime.
17
+ *
18
+ * Decided in: docs/adr/0007-canonical-request-attribution.md, docs/adr/0008-catalogue-concept-separation.md.
19
+ */
20
+ import { z } from 'zod';
21
+ /**
22
+ * An Oxy account id — the account that owns the workload and is financially
23
+ * responsible for it.
24
+ *
25
+ * Branded, and that brand is load-bearing rather than decorative: it is the
26
+ * type-level half of the rule that a delegated end-user identity can never
27
+ * become the billing identity (see {@link delegatedUserIdSchema} and
28
+ * `billingPrincipalSchema`). A plain `string` — and therefore any id read out
29
+ * of a header, a JWT claim or a request body — is not assignable to it; the
30
+ * only way to obtain one is to parse a value through this schema.
31
+ */
32
+ export declare const oxyAccountIdSchema: z.ZodBranded<z.ZodString, "OxyAccountId">;
33
+ /**
34
+ * A delegated end-user identity (Alia's `X-Oxy-User-Id`), branded with a
35
+ * DIFFERENT brand from {@link oxyAccountIdSchema} so the two cannot be
36
+ * substituted for one another in either direction, in any consumer, without a
37
+ * cast that review would catch.
38
+ *
39
+ * It exists for attribution and product-side personalisation only. It is never
40
+ * a billing principal, never an access-control principal, and its presence
41
+ * never changes which account is charged.
42
+ */
43
+ export declare const delegatedUserIdSchema: z.ZodBranded<z.ZodString, "DelegatedUserId">;
44
+ /**
45
+ * An Oxy `Application._id`. Not branded: no invariant in this contract turns on
46
+ * confusing it with another id, and brand inflation costs every producer a
47
+ * parse call for no safety. The two ids above are branded because ADR 0007's
48
+ * rule is exactly that they must not be interchangeable.
49
+ */
50
+ export declare const oxyApplicationIdSchema: z.ZodString;
51
+ /** An Oxy `ApplicationCredential._id` — the credential used for this request. */
52
+ export declare const oxyCredentialIdSchema: z.ZodString;
53
+ /**
54
+ * A request id generated by the data plane. Correlates the Oxy edge, the data
55
+ * plane, the financial ledger and the customer-visible receipt, so it appears on
56
+ * every stream event and every ledger record.
57
+ */
58
+ export declare const requestIdSchema: z.ZodString;
59
+ /**
60
+ * A generation id generated by the data plane, present when a request produced
61
+ * a generation that can be looked up later (`GET /v1/generations/:id`).
62
+ */
63
+ export declare const generationIdSchema: z.ZodString;
64
+ /**
65
+ * A caller-supplied idempotency key. Every reserve/settle/refund call is keyed
66
+ * on one so a retry, a redelivered event or a duplicated webhook can never
67
+ * charge twice.
68
+ */
69
+ export declare const idempotencyKeySchema: z.ZodString;
70
+ /** Credential environments. A credential is issued into exactly one of them. */
71
+ export declare const inferenceEnvironmentSchema: z.ZodEnum<["development", "staging", "production"]>;
72
+ /**
73
+ * An instant, as an ISO 8601 string in UTC (`2026-08-15T09:41:00.000Z`).
74
+ *
75
+ * Validated rather than left free-form — unlike the session contracts, which
76
+ * carry legacy expiry strings no consumer interprets, every instant here is
77
+ * read: a reservation expires, a price version starts applying, a receipt is
78
+ * settled. One canonical spelling (UTC, `Z`) so two records that describe the
79
+ * same moment compare and sort as equal, which a mix of offsets would not.
80
+ */
81
+ export declare const inferenceTimestampSchema: z.ZodString;
82
+ /**
83
+ * A calendar DATE with no instant attached (`2026-05-01`) — a knowledge cutoff
84
+ * or a release date, which are published as days and become wrong when a
85
+ * timezone is invented for them.
86
+ */
87
+ export declare const inferenceDateSchema: z.ZodString;
88
+ /** An absolute https URL, for model cards, licenses and provider documentation. */
89
+ export declare const inferenceHttpsUrlSchema: z.ZodString;
90
+ /** A publisher slug, e.g. `openai`, `anthropic`, `meta`, `alia`. */
91
+ export declare const publisherSlugSchema: z.ZodString;
92
+ /** A model slug within its publisher's namespace, e.g. `gpt-5`, `llama-3.1-70b`. */
93
+ export declare const modelSlugSchema: z.ZodString;
94
+ /**
95
+ * A canonical model id, `<publisher>/<model>`. This names a MODEL — a
96
+ * long-lived product identity whose behaviour changes as revisions ship. It
97
+ * does not name a revision, a deployment or a provider.
98
+ */
99
+ export declare const modelIdSchema: z.ZodString;
100
+ /** An immutable revision label, unique within its model, e.g. `2026-05-01`. */
101
+ export declare const modelRevisionLabelSchema: z.ZodString;
102
+ /**
103
+ * A model reference as a customer writes it: `<publisher>/<model>` (the model's
104
+ * current revision, chosen by Oxy) or `<publisher>/<model>@<revision>` (an
105
+ * immutable revision the customer pinned).
106
+ *
107
+ * Both forms name a CONCRETE MODEL. Neither can name a routing profile — see
108
+ * {@link routingProfileSlugSchema} — which is what makes "a request for a
109
+ * concrete model is never silently replaced with a different model" a
110
+ * distinction the type system can carry rather than a convention.
111
+ */
112
+ export declare const modelReferenceSchema: z.ZodString;
113
+ /**
114
+ * A routing-profile slug, e.g. `auto`, `fast`, `quality`.
115
+ *
116
+ * Deliberately refuses a `/`, so a profile can never be written in the shape of
117
+ * a model id and no caller can be confused about whether they asked for a
118
+ * concrete model or for Oxy to choose one. Modes like `auto`/`fast`/`quality`
119
+ * are profiles or product presets; they are never model objects.
120
+ */
121
+ export declare const routingProfileSlugSchema: z.ZodString;
122
+ /** An inference provider slug, e.g. `openai`, `bedrock`, `oxy-hosted`. */
123
+ export declare const inferenceProviderSlugSchema: z.ZodString;
124
+ /**
125
+ * A deployment/endpoint id. Opaque to customers: which concrete endpoint served
126
+ * a request is the data plane's operational detail, and only the customer-safe
127
+ * subset of it is ever attributed back (see the catalogue's serving-boundary
128
+ * rules).
129
+ */
130
+ export declare const deploymentIdSchema: z.ZodString;
131
+ /**
132
+ * A region identifier, e.g. `us-west-2`, `eu-central-1`. Free-form rather than
133
+ * a closed enum because the set is provider-defined and grows without any
134
+ * contract change; residency policies match on exact strings.
135
+ */
136
+ export declare const inferenceRegionSchema: z.ZodString;
137
+ /**
138
+ * The publisher namespace reserved for models Alia actually owns or derives.
139
+ *
140
+ * `alia/*` is never a re-badged third-party route and never a prompt preset —
141
+ * enforcing that is the job of `modelSchema`'s provenance refinement, which
142
+ * this constant exists to be checked against.
143
+ */
144
+ export declare const RESERVED_ALIA_PUBLISHER = "alia";
145
+ export type OxyAccountId = z.infer<typeof oxyAccountIdSchema>;
146
+ export type DelegatedUserId = z.infer<typeof delegatedUserIdSchema>;
147
+ export type InferenceEnvironment = z.infer<typeof inferenceEnvironmentSchema>;
148
+ export type ModelReference = z.infer<typeof modelReferenceSchema>;
149
+ export type ModelId = z.infer<typeof modelIdSchema>;
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Money and usage units for the inference contracts.
3
+ *
4
+ * The non-negotiable invariant this file exists to make structural: **customer
5
+ * charges never use floating-point values as the financial source of truth.**
6
+ * A JS `number` cannot represent `0.1 + 0.2` exactly, and an inference ledger
7
+ * adds millions of small amounts, so a float total is wrong by construction
8
+ * rather than by accident.
9
+ *
10
+ * Every amount and every price is one representation: {@link exactDecimalSchema},
11
+ * an exact decimal STRING at the scale ADR 0009 declares. Amounts are not
12
+ * integer minor units, and that is the ADR's decision rather than an oversight:
13
+ * one token costs several orders of magnitude less than one cent, so rounding
14
+ * per request would make a customer's bill depend on how their client chunked
15
+ * its work. Rounding happens ONCE, at the invoice boundary, and is itself a
16
+ * ledger entry.
17
+ *
18
+ * A string is also what the driver hands back — `postgres.js` decodes `NUMERIC`
19
+ * as a string — so keeping it a string on the wire means accidental JS
20
+ * arithmetic fails loudly instead of silently losing precision. Money
21
+ * arithmetic happens in SQL or in a decimal type, never in a JS `number`.
22
+ *
23
+ * Units are carried separately from money in every shape: a receipt says both
24
+ * "204 output tokens" and "0.003060000000 USD", and neither is derived from the
25
+ * other at read time. That separation is what lets a price version change
26
+ * without rewriting settled history.
27
+ *
28
+ * Decided in: docs/adr/0009-usage-reservation-and-settlement.md.
29
+ */
30
+ import { z } from 'zod';
31
+ /** ISO 4217 alpha-3 currency code, e.g. `USD`. */
32
+ export declare const currencyCodeSchema: z.ZodString;
33
+ /**
34
+ * The declared fractional scale of every amount and price in this contract, and
35
+ * of the `NUMERIC` columns the ledger stores them in.
36
+ *
37
+ * Twelve digits is sub-minor-unit precision by a wide margin: at $3 per million
38
+ * input tokens, one token costs `0.000003000000`, which this scale represents
39
+ * exactly. Amounts are compared and summed NUMERICALLY, never as text — `3.0`
40
+ * and `3.000000000000` are one amount written two ways.
41
+ */
42
+ export declare const INFERENCE_MONEY_SCALE = 12;
43
+ /**
44
+ * An exact non-negative decimal, carried as a STRING so no parse step can turn
45
+ * it into a float on the way past. Up to 18 integer digits and
46
+ * {@link INFERENCE_MONEY_SCALE} fractional digits.
47
+ *
48
+ * Non-negative: direction is carried by the SHAPE — a receipt debits, a refund
49
+ * credits — so a stray sign can never silently invert an entry.
50
+ *
51
+ * No exponent form: `1e-6` and `0.000001` are the same number, but only one of
52
+ * them survives a naive string comparison, a cache key or a log grep intact.
53
+ *
54
+ * Branded, so a bare `string` is not assignable and an amount cannot arrive
55
+ * from string concatenation that was never checked. Producers construct one
56
+ * with `exactDecimalSchema.parse(value)`.
57
+ */
58
+ export declare const exactDecimalSchema: z.ZodBranded<z.ZodString, "ExactDecimal">;
59
+ /**
60
+ * An amount of money: the exact decimal plus the currency it is in.
61
+ *
62
+ * `.strict()` so a payload carrying a convenience float beside the exact value
63
+ * (`{ amount: '18.06', amountFloat: 18.06 }`) is REJECTED rather than stripped.
64
+ * A stripped float is the more dangerous outcome: it disappears silently here
65
+ * and survives in the producer, where it is the value somebody eventually
66
+ * displays.
67
+ */
68
+ export declare const moneySchema: z.ZodObject<{
69
+ amount: z.ZodBranded<z.ZodString, "ExactDecimal">;
70
+ currency: z.ZodString;
71
+ }, "strict", z.ZodTypeAny, {
72
+ amount: string & z.BRAND<"ExactDecimal">;
73
+ currency: string;
74
+ }, {
75
+ amount: string;
76
+ currency: string;
77
+ }>;
78
+ /**
79
+ * The closed set of units inference is metered in.
80
+ *
81
+ * Time is carried in integer MILLISECONDS rather than seconds so that no unit
82
+ * quantity is ever fractional: a 12.5-second transcription is `12500`, exactly,
83
+ * and the "units are integers" rule holds for every modality instead of holding
84
+ * for tokens and being quietly broken by audio.
85
+ */
86
+ export declare const USAGE_UNITS: readonly ["input_tokens", "cached_input_tokens", "output_tokens", "reasoning_tokens", "requests", "images", "audio_input_milliseconds", "audio_output_milliseconds", "video_milliseconds", "characters", "embeddings"];
87
+ export declare const usageUnitSchema: z.ZodEnum<["input_tokens", "cached_input_tokens", "output_tokens", "reasoning_tokens", "requests", "images", "audio_input_milliseconds", "audio_output_milliseconds", "video_milliseconds", "characters", "embeddings"]>;
88
+ /**
89
+ * A metered quantity of ONE unit. Never money — a quantity carries no price and
90
+ * no currency, so a consumer cannot mistake a token count for an amount owed.
91
+ */
92
+ export declare const usageQuantitySchema: z.ZodObject<{
93
+ unit: z.ZodEnum<["input_tokens", "cached_input_tokens", "output_tokens", "reasoning_tokens", "requests", "images", "audio_input_milliseconds", "audio_output_milliseconds", "video_milliseconds", "characters", "embeddings"]>;
94
+ quantity: z.ZodNumber;
95
+ }, "strict", z.ZodTypeAny, {
96
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
97
+ quantity: number;
98
+ }, {
99
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
100
+ quantity: number;
101
+ }>;
102
+ /**
103
+ * Where a metered quantity came from.
104
+ *
105
+ * Kept explicit because the three are not interchangeable when a charge is
106
+ * disputed: `provider_reported` is the upstream's own count, `oxy_measured` is
107
+ * counted by the platform (streamed bytes, wall-clock milliseconds), and
108
+ * `estimated` is a reconstruction used when a provider returned no usage at
109
+ * all. An estimate that is indistinguishable from a reported number is an
110
+ * estimate nobody can later reconcile or refund against.
111
+ */
112
+ export declare const USAGE_SOURCES: readonly ["provider_reported", "oxy_measured", "estimated"];
113
+ export declare const usageSourceSchema: z.ZodEnum<["provider_reported", "oxy_measured", "estimated"]>;
114
+ /**
115
+ * A price for one unit, as `amount` per `per` units — `per` because a price
116
+ * quoted per single token would need more fractional digits than it is worth
117
+ * ("$3.00 per 1000000 input_tokens" is how every provider quotes it, and how
118
+ * every customer reads it).
119
+ */
120
+ export declare const unitPriceSchema: z.ZodObject<{
121
+ unit: z.ZodEnum<["input_tokens", "cached_input_tokens", "output_tokens", "reasoning_tokens", "requests", "images", "audio_input_milliseconds", "audio_output_milliseconds", "video_milliseconds", "characters", "embeddings"]>;
122
+ amount: z.ZodBranded<z.ZodString, "ExactDecimal">;
123
+ per: z.ZodNumber;
124
+ currency: z.ZodString;
125
+ }, "strict", z.ZodTypeAny, {
126
+ amount: string & z.BRAND<"ExactDecimal">;
127
+ currency: string;
128
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
129
+ per: number;
130
+ }, {
131
+ amount: string;
132
+ currency: string;
133
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
134
+ per: number;
135
+ }>;
136
+ export type CurrencyCode = z.infer<typeof currencyCodeSchema>;
137
+ export type ExactDecimal = z.infer<typeof exactDecimalSchema>;
138
+ export type Money = z.infer<typeof moneySchema>;
139
+ export type UsageUnit = z.infer<typeof usageUnitSchema>;
140
+ export type UsageSource = z.infer<typeof usageSourceSchema>;
141
+ export type UsageQuantity = z.infer<typeof usageQuantitySchema>;
142
+ export type UnitPrice = z.infer<typeof unitPriceSchema>;