@oxy.so/contracts 1.0.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.
- package/LICENSE +202 -0
- package/NOTICE +16 -0
- package/dist/cjs/.tsbuildinfo +1 -0
- package/dist/cjs/accountGraph.js +489 -0
- package/dist/cjs/agency.js +439 -0
- package/dist/cjs/browserHub.js +215 -0
- package/dist/cjs/civic.js +163 -0
- package/dist/cjs/commonsSignIn.js +59 -0
- package/dist/cjs/deviceBoot.js +50 -0
- package/dist/cjs/deviceDirectory.js +189 -0
- package/dist/cjs/devicePairing.js +138 -0
- package/dist/cjs/deviceSession.js +164 -0
- package/dist/cjs/emailAgentContext.js +32 -0
- package/dist/cjs/followGraph.js +28 -0
- package/dist/cjs/identity.js +258 -0
- package/dist/cjs/inboxPush.js +24 -0
- package/dist/cjs/index.js +618 -0
- package/dist/cjs/inference/accountBilling.js +334 -0
- package/dist/cjs/inference/aliaModelRelease.js +262 -0
- package/dist/cjs/inference/attribution.js +106 -0
- package/dist/cjs/inference/catalogue.js +487 -0
- package/dist/cjs/inference/entitlement.js +217 -0
- package/dist/cjs/inference/errors.js +309 -0
- package/dist/cjs/inference/identifiers.js +224 -0
- package/dist/cjs/inference/inbox.js +105 -0
- package/dist/cjs/inference/modelDocumentation.js +433 -0
- package/dist/cjs/inference/money.js +188 -0
- package/dist/cjs/inference/priceVersion.js +110 -0
- package/dist/cjs/inference/providerConnection.js +455 -0
- package/dist/cjs/inference/request.js +477 -0
- package/dist/cjs/inference/routingPolicy.js +318 -0
- package/dist/cjs/inference/streamEvents.js +258 -0
- package/dist/cjs/inference/usage.js +329 -0
- package/dist/cjs/inference/version.js +105 -0
- package/dist/cjs/keyRecovery.js +91 -0
- package/dist/cjs/keyRotation.js +75 -0
- package/dist/cjs/links.js +68 -0
- package/dist/cjs/moderationReputation.js +298 -0
- package/dist/cjs/oauth.js +66 -0
- package/dist/cjs/oxyRecordTypes.js +71 -0
- package/dist/cjs/protocol.js +53 -0
- package/dist/cjs/recommendations.js +168 -0
- package/dist/cjs/reputation.js +297 -0
- package/dist/cjs/sessionStatus.js +121 -0
- package/dist/cjs/transparency.js +89 -0
- package/dist/cjs/updates.js +252 -0
- package/dist/cjs/userInvalidation.js +89 -0
- package/dist/cjs/userResponse.js +245 -0
- package/dist/cjs/username.js +290 -0
- package/dist/cjs/webauthn.js +71 -0
- package/dist/esm/.tsbuildinfo +1 -0
- package/dist/esm/accountGraph.js +480 -0
- package/dist/esm/agency.js +436 -0
- package/dist/esm/browserHub.js +212 -0
- package/dist/esm/civic.js +160 -0
- package/dist/esm/commonsSignIn.js +56 -0
- package/dist/esm/deviceBoot.js +47 -0
- package/dist/esm/deviceDirectory.js +186 -0
- package/dist/esm/devicePairing.js +135 -0
- package/dist/esm/deviceSession.js +161 -0
- package/dist/esm/emailAgentContext.js +29 -0
- package/dist/esm/followGraph.js +27 -0
- package/dist/esm/identity.js +255 -0
- package/dist/esm/inboxPush.js +21 -0
- package/dist/esm/index.js +172 -0
- package/dist/esm/inference/accountBilling.js +331 -0
- package/dist/esm/inference/aliaModelRelease.js +259 -0
- package/dist/esm/inference/attribution.js +103 -0
- package/dist/esm/inference/catalogue.js +484 -0
- package/dist/esm/inference/entitlement.js +214 -0
- package/dist/esm/inference/errors.js +306 -0
- package/dist/esm/inference/identifiers.js +221 -0
- package/dist/esm/inference/inbox.js +102 -0
- package/dist/esm/inference/modelDocumentation.js +430 -0
- package/dist/esm/inference/money.js +185 -0
- package/dist/esm/inference/priceVersion.js +107 -0
- package/dist/esm/inference/providerConnection.js +452 -0
- package/dist/esm/inference/request.js +474 -0
- package/dist/esm/inference/routingPolicy.js +315 -0
- package/dist/esm/inference/streamEvents.js +255 -0
- package/dist/esm/inference/usage.js +326 -0
- package/dist/esm/inference/version.js +102 -0
- package/dist/esm/keyRecovery.js +88 -0
- package/dist/esm/keyRotation.js +72 -0
- package/dist/esm/links.js +65 -0
- package/dist/esm/moderationReputation.js +295 -0
- package/dist/esm/oauth.js +63 -0
- package/dist/esm/oxyRecordTypes.js +68 -0
- package/dist/esm/protocol.js +50 -0
- package/dist/esm/recommendations.js +165 -0
- package/dist/esm/reputation.js +293 -0
- package/dist/esm/sessionStatus.js +118 -0
- package/dist/esm/transparency.js +86 -0
- package/dist/esm/updates.js +249 -0
- package/dist/esm/userInvalidation.js +85 -0
- package/dist/esm/userResponse.js +240 -0
- package/dist/esm/username.js +283 -0
- package/dist/esm/webauthn.js +68 -0
- package/dist/types/.tsbuildinfo +1 -0
- package/dist/types/accountGraph.d.ts +378 -0
- package/dist/types/agency.d.ts +2162 -0
- package/dist/types/browserHub.d.ts +856 -0
- package/dist/types/civic.d.ts +338 -0
- package/dist/types/commonsSignIn.d.ts +58 -0
- package/dist/types/deviceBoot.d.ts +74 -0
- package/dist/types/deviceDirectory.d.ts +1317 -0
- package/dist/types/devicePairing.d.ts +130 -0
- package/dist/types/deviceSession.d.ts +411 -0
- package/dist/types/emailAgentContext.d.ts +248 -0
- package/dist/types/followGraph.d.ts +150 -0
- package/dist/types/identity.d.ts +402 -0
- package/dist/types/inboxPush.d.ts +30 -0
- package/dist/types/index.d.ts +100 -0
- package/dist/types/inference/accountBilling.d.ts +738 -0
- package/dist/types/inference/aliaModelRelease.d.ts +609 -0
- package/dist/types/inference/attribution.d.ts +176 -0
- package/dist/types/inference/catalogue.d.ts +1618 -0
- package/dist/types/inference/entitlement.d.ts +519 -0
- package/dist/types/inference/errors.d.ts +242 -0
- package/dist/types/inference/identifiers.d.ts +182 -0
- package/dist/types/inference/inbox.d.ts +374 -0
- package/dist/types/inference/modelDocumentation.d.ts +1603 -0
- package/dist/types/inference/money.d.ts +185 -0
- package/dist/types/inference/priceVersion.d.ts +182 -0
- package/dist/types/inference/providerConnection.d.ts +968 -0
- package/dist/types/inference/request.d.ts +2800 -0
- package/dist/types/inference/routingPolicy.d.ts +616 -0
- package/dist/types/inference/streamEvents.d.ts +950 -0
- package/dist/types/inference/usage.d.ts +1164 -0
- package/dist/types/inference/version.d.ts +102 -0
- package/dist/types/keyRecovery.d.ts +138 -0
- package/dist/types/keyRotation.d.ts +103 -0
- package/dist/types/links.d.ts +96 -0
- package/dist/types/moderationReputation.d.ts +487 -0
- package/dist/types/oauth.d.ts +86 -0
- package/dist/types/oxyRecordTypes.d.ts +62 -0
- package/dist/types/protocol.d.ts +86 -0
- package/dist/types/recommendations.d.ts +542 -0
- package/dist/types/reputation.d.ts +457 -0
- package/dist/types/sessionStatus.d.ts +231 -0
- package/dist/types/transparency.d.ts +392 -0
- package/dist/types/updates.d.ts +545 -0
- package/dist/types/userInvalidation.d.ts +94 -0
- package/dist/types/userResponse.d.ts +1706 -0
- package/dist/types/username.d.ts +265 -0
- package/dist/types/webauthn.d.ts +77 -0
- package/package.json +87 -0
|
@@ -0,0 +1,242 @@
|
|
|
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
|
+
* The platform group is NOT uniformly retryable, and that is the point of
|
|
36
|
+
* `provider_credential_invalid` sitting in it: an upstream that refuses the
|
|
37
|
+
* PLATFORM's own credential fails every identical retry until an operator
|
|
38
|
+
* rotates a key, so classifying it as `provider_error` would send every client
|
|
39
|
+
* into a retry loop against a request that cannot succeed.
|
|
40
|
+
*
|
|
41
|
+
* `provider_billing_refused` is in that group for the same reason and was found
|
|
42
|
+
* the same way — an upstream declining to bill OXY (Anthropic answers 402) has
|
|
43
|
+
* to be distinguishable from the customer's own balance running out, or the
|
|
44
|
+
* error tells them to go and top up an account that is not the one at fault.
|
|
45
|
+
*/
|
|
46
|
+
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", "provider_credential_invalid", "provider_billing_refused", "service_unavailable", "internal_error"];
|
|
47
|
+
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", "provider_credential_invalid", "provider_billing_refused", "service_unavailable", "internal_error"]>;
|
|
48
|
+
/**
|
|
49
|
+
* Codes for which an identical retried request cannot succeed.
|
|
50
|
+
*
|
|
51
|
+
* `rate_limited` and `quota_exceeded` sit on opposite sides of this line
|
|
52
|
+
* deliberately: a rate limit clears on its own within the window the response
|
|
53
|
+
* names, while a quota is an account-level ceiling that only a human raises.
|
|
54
|
+
* `cancelled` is here because the caller already withdrew the request; a client
|
|
55
|
+
* that retries it is contradicting its own cancellation.
|
|
56
|
+
*
|
|
57
|
+
* `byok_credential_invalid` and `provider_credential_invalid` are the same
|
|
58
|
+
* failure seen from the two sides of the BYOK boundary — the customer's own
|
|
59
|
+
* upstream credential and the platform's — and they are two codes rather than
|
|
60
|
+
* one because only the first names an action the customer can take. Both are
|
|
61
|
+
* non-retryable for the same reason: a credential an upstream has refused keeps
|
|
62
|
+
* being refused until somebody replaces it.
|
|
63
|
+
*
|
|
64
|
+
* `quota_exceeded` and `provider_billing_refused` divide along the same line:
|
|
65
|
+
* both are money, but one is the CUSTOMER's ceiling and the other is Oxy's
|
|
66
|
+
* account with an upstream. Reporting the second as the first is retryability-
|
|
67
|
+
* correct and diagnostically wrong, which is the worst combination — it reads
|
|
68
|
+
* as actionable and the action does nothing.
|
|
69
|
+
*/
|
|
70
|
+
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", "provider_credential_invalid", "provider_billing_refused"];
|
|
71
|
+
/**
|
|
72
|
+
* Free text that is safe to hand a customer: bounded, and refused if it still
|
|
73
|
+
* looks like it carries a credential. Applied to BOTH the Oxy message and the
|
|
74
|
+
* upstream one — a leak is no less a leak for having been written by a provider.
|
|
75
|
+
*
|
|
76
|
+
* ## This is a last-resort REFUSAL, not protection
|
|
77
|
+
*
|
|
78
|
+
* A pattern over the OUTPUT cannot be the control that keeps a credential out of
|
|
79
|
+
* an error, and a producer that treats it as one has the hole #1027 reported.
|
|
80
|
+
* The only reliable control is redacting the KNOWN SECRET VALUE at the point
|
|
81
|
+
* where the producer still holds the bytes it sent — which is an adapter's job
|
|
82
|
+
* and is available to nobody else. This refinement exists to catch what that
|
|
83
|
+
* control missed, and nothing here is a licence to skip it.
|
|
84
|
+
*
|
|
85
|
+
* Two rules follow, and they are the whole reason this text is longer than the
|
|
86
|
+
* pattern it describes:
|
|
87
|
+
*
|
|
88
|
+
* - **Never redact by replacing the span this pattern matched.** The span is
|
|
89
|
+
* the MARKER; the secret is what follows it. OxyHQ/Kaana#3 measured the
|
|
90
|
+
* result: `{x-api-key: <key>}` is refused, `{x-[redacted] <key>}` was
|
|
91
|
+
* accepted, and both carry the key. Redaction made the leak worse by
|
|
92
|
+
* converting "this string is dangerous" into "this string is fine".
|
|
93
|
+
* - **This package deliberately ships no redaction helper.** One keyed on these
|
|
94
|
+
* patterns would rebuild the same defect one layer up, and one that took the
|
|
95
|
+
* secret as an argument would only restate what the producer already has.
|
|
96
|
+
*
|
|
97
|
+
* What it still cannot see, stated so nobody relies on it: a credential with no
|
|
98
|
+
* marker, no issued-token prefix and no placeholder beside it is bytes that look
|
|
99
|
+
* like a request id, and refusing those means refusing request ids.
|
|
100
|
+
*/
|
|
101
|
+
export declare const safeErrorTextSchema: z.ZodEffects<z.ZodString, string, string>;
|
|
102
|
+
/**
|
|
103
|
+
* A coarse classification of an upstream failure (ADR 0010's `upstreamCategory`).
|
|
104
|
+
*
|
|
105
|
+
* Distinct from {@link providerErrorPassthroughSchema}, which carries the
|
|
106
|
+
* upstream's OWN code and text: this is Oxy's reading of what kind of failure it
|
|
107
|
+
* was, in a vocabulary that is the same across every provider, so a client can
|
|
108
|
+
* branch on it without knowing who served the request.
|
|
109
|
+
*/
|
|
110
|
+
export declare const upstreamErrorCategorySchema: z.ZodEnum<["rate_limit", "quota", "timeout", "overloaded", "server_error", "content_filter", "invalid_request", "authentication", "unknown"]>;
|
|
111
|
+
/**
|
|
112
|
+
* What the upstream provider said, reduced to the four fields a customer can
|
|
113
|
+
* act on.
|
|
114
|
+
*
|
|
115
|
+
* `.strict()` is the security control here, not a tidiness preference: it means
|
|
116
|
+
* a producer cannot widen this by attaching `requestHeaders`, `curl`, `body` or
|
|
117
|
+
* `raw` and have it silently pass. Adding a field is a contract change with a
|
|
118
|
+
* version bump and a review, which is the point.
|
|
119
|
+
*/
|
|
120
|
+
export declare const providerErrorPassthroughSchema: z.ZodObject<{
|
|
121
|
+
provider: z.ZodString;
|
|
122
|
+
/** The upstream HTTP status, when the upstream spoke HTTP. */
|
|
123
|
+
status: z.ZodOptional<z.ZodNumber>;
|
|
124
|
+
/** The upstream's own error code, verbatim and uninterpreted. */
|
|
125
|
+
code: z.ZodOptional<z.ZodString>;
|
|
126
|
+
/** The upstream's message, subject to the same credential refusal. */
|
|
127
|
+
message: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
128
|
+
}, "strict", z.ZodTypeAny, {
|
|
129
|
+
provider: string;
|
|
130
|
+
code?: string | undefined;
|
|
131
|
+
message?: string | undefined;
|
|
132
|
+
status?: number | undefined;
|
|
133
|
+
}, {
|
|
134
|
+
provider: string;
|
|
135
|
+
code?: string | undefined;
|
|
136
|
+
message?: string | undefined;
|
|
137
|
+
status?: number | undefined;
|
|
138
|
+
}>;
|
|
139
|
+
/**
|
|
140
|
+
* The error body every inference surface returns and every stream error event
|
|
141
|
+
* carries.
|
|
142
|
+
*
|
|
143
|
+
* `requestId` is always present — an error a customer cannot correlate with a
|
|
144
|
+
* log line is an error they have to reproduce to report.
|
|
145
|
+
*/
|
|
146
|
+
export declare const inferenceErrorSchema: z.ZodEffects<z.ZodObject<{
|
|
147
|
+
/** See `version.ts`: this shape appears alone on the wire, so it is versioned. */
|
|
148
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
149
|
+
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", "provider_credential_invalid", "provider_billing_refused", "service_unavailable", "internal_error"]>;
|
|
150
|
+
message: z.ZodEffects<z.ZodString, string, string>;
|
|
151
|
+
retryable: z.ZodBoolean;
|
|
152
|
+
requestId: z.ZodString;
|
|
153
|
+
/** How long to wait before retrying. Only meaningful when `retryable`. */
|
|
154
|
+
retryAfterMs: z.ZodOptional<z.ZodNumber>;
|
|
155
|
+
/** The request field at fault, for `invalid_request`. */
|
|
156
|
+
param: z.ZodOptional<z.ZodString>;
|
|
157
|
+
/** Present only when an upstream provider was reached and failed. */
|
|
158
|
+
upstreamCategory: z.ZodOptional<z.ZodEnum<["rate_limit", "quota", "timeout", "overloaded", "server_error", "content_filter", "invalid_request", "authentication", "unknown"]>>;
|
|
159
|
+
providerError: z.ZodOptional<z.ZodObject<{
|
|
160
|
+
provider: z.ZodString;
|
|
161
|
+
/** The upstream HTTP status, when the upstream spoke HTTP. */
|
|
162
|
+
status: z.ZodOptional<z.ZodNumber>;
|
|
163
|
+
/** The upstream's own error code, verbatim and uninterpreted. */
|
|
164
|
+
code: z.ZodOptional<z.ZodString>;
|
|
165
|
+
/** The upstream's message, subject to the same credential refusal. */
|
|
166
|
+
message: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
167
|
+
}, "strict", z.ZodTypeAny, {
|
|
168
|
+
provider: string;
|
|
169
|
+
code?: string | undefined;
|
|
170
|
+
message?: string | undefined;
|
|
171
|
+
status?: number | undefined;
|
|
172
|
+
}, {
|
|
173
|
+
provider: string;
|
|
174
|
+
code?: string | undefined;
|
|
175
|
+
message?: string | undefined;
|
|
176
|
+
status?: number | undefined;
|
|
177
|
+
}>>;
|
|
178
|
+
}, "strip", z.ZodTypeAny, {
|
|
179
|
+
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" | "provider_credential_invalid" | "provider_billing_refused" | "service_unavailable" | "internal_error";
|
|
180
|
+
message: string;
|
|
181
|
+
schemaVersion: 1;
|
|
182
|
+
requestId: string;
|
|
183
|
+
retryable: boolean;
|
|
184
|
+
retryAfterMs?: number | undefined;
|
|
185
|
+
param?: string | undefined;
|
|
186
|
+
upstreamCategory?: "unknown" | "authentication" | "invalid_request" | "rate_limit" | "quota" | "timeout" | "overloaded" | "server_error" | "content_filter" | undefined;
|
|
187
|
+
providerError?: {
|
|
188
|
+
provider: string;
|
|
189
|
+
code?: string | undefined;
|
|
190
|
+
message?: string | undefined;
|
|
191
|
+
status?: number | undefined;
|
|
192
|
+
} | undefined;
|
|
193
|
+
}, {
|
|
194
|
+
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" | "provider_credential_invalid" | "provider_billing_refused" | "service_unavailable" | "internal_error";
|
|
195
|
+
message: string;
|
|
196
|
+
schemaVersion: 1;
|
|
197
|
+
requestId: string;
|
|
198
|
+
retryable: boolean;
|
|
199
|
+
retryAfterMs?: number | undefined;
|
|
200
|
+
param?: string | undefined;
|
|
201
|
+
upstreamCategory?: "unknown" | "authentication" | "invalid_request" | "rate_limit" | "quota" | "timeout" | "overloaded" | "server_error" | "content_filter" | undefined;
|
|
202
|
+
providerError?: {
|
|
203
|
+
provider: string;
|
|
204
|
+
code?: string | undefined;
|
|
205
|
+
message?: string | undefined;
|
|
206
|
+
status?: number | undefined;
|
|
207
|
+
} | undefined;
|
|
208
|
+
}>, {
|
|
209
|
+
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" | "provider_credential_invalid" | "provider_billing_refused" | "service_unavailable" | "internal_error";
|
|
210
|
+
message: string;
|
|
211
|
+
schemaVersion: 1;
|
|
212
|
+
requestId: string;
|
|
213
|
+
retryable: boolean;
|
|
214
|
+
retryAfterMs?: number | undefined;
|
|
215
|
+
param?: string | undefined;
|
|
216
|
+
upstreamCategory?: "unknown" | "authentication" | "invalid_request" | "rate_limit" | "quota" | "timeout" | "overloaded" | "server_error" | "content_filter" | undefined;
|
|
217
|
+
providerError?: {
|
|
218
|
+
provider: string;
|
|
219
|
+
code?: string | undefined;
|
|
220
|
+
message?: string | undefined;
|
|
221
|
+
status?: number | undefined;
|
|
222
|
+
} | undefined;
|
|
223
|
+
}, {
|
|
224
|
+
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" | "provider_credential_invalid" | "provider_billing_refused" | "service_unavailable" | "internal_error";
|
|
225
|
+
message: string;
|
|
226
|
+
schemaVersion: 1;
|
|
227
|
+
requestId: string;
|
|
228
|
+
retryable: boolean;
|
|
229
|
+
retryAfterMs?: number | undefined;
|
|
230
|
+
param?: string | undefined;
|
|
231
|
+
upstreamCategory?: "unknown" | "authentication" | "invalid_request" | "rate_limit" | "quota" | "timeout" | "overloaded" | "server_error" | "content_filter" | undefined;
|
|
232
|
+
providerError?: {
|
|
233
|
+
provider: string;
|
|
234
|
+
code?: string | undefined;
|
|
235
|
+
message?: string | undefined;
|
|
236
|
+
status?: number | undefined;
|
|
237
|
+
} | undefined;
|
|
238
|
+
}>;
|
|
239
|
+
export type InferenceErrorCode = z.infer<typeof inferenceErrorCodeSchema>;
|
|
240
|
+
export type UpstreamErrorCategory = z.infer<typeof upstreamErrorCategorySchema>;
|
|
241
|
+
export type ProviderErrorPassthrough = z.infer<typeof providerErrorPassthroughSchema>;
|
|
242
|
+
export type InferenceError = z.infer<typeof inferenceErrorSchema>;
|
|
@@ -0,0 +1,182 @@
|
|
|
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 allocated by the Oxy EDGE, at admission and BEFORE
|
|
55
|
+
* authentication, so that a request rejected for a bad credential is as
|
|
56
|
+
* traceable as one that was served (ADR 0007, and step 1 of ADR 0010's edge
|
|
57
|
+
* order). It is required on the inbound envelope, which is what makes the data
|
|
58
|
+
* plane a consumer of this id rather than its source: the data plane echoes it
|
|
59
|
+
* on every stream event, on the usage report, in its response header and on
|
|
60
|
+
* anything it can be asked about later. It never mints one for a request it
|
|
61
|
+
* received.
|
|
62
|
+
*
|
|
63
|
+
* The one case that is NOT an exception to that: an envelope the data plane
|
|
64
|
+
* cannot read or authenticate carries no id to echo, so its rejection is
|
|
65
|
+
* labelled with an id of the data plane's own — visibly local, and never
|
|
66
|
+
* correlated with an Oxy request, because there is no Oxy request it belongs to.
|
|
67
|
+
* Saying so is what stops "consumer, not source" from being read as forbidding
|
|
68
|
+
* the only id such a rejection could have.
|
|
69
|
+
*
|
|
70
|
+
* Correlates the Oxy edge, the data plane, the financial ledger and the
|
|
71
|
+
* customer-visible receipt, so it appears on every stream event and every
|
|
72
|
+
* ledger record.
|
|
73
|
+
*/
|
|
74
|
+
export declare const requestIdSchema: z.ZodString;
|
|
75
|
+
/**
|
|
76
|
+
* A generation id generated by the data plane, present when a request produced
|
|
77
|
+
* a generation that can be looked up later (`GET /v1/generations/:id`).
|
|
78
|
+
*/
|
|
79
|
+
export declare const generationIdSchema: z.ZodString;
|
|
80
|
+
/**
|
|
81
|
+
* A caller-supplied idempotency key. Every reserve/settle/refund call is keyed
|
|
82
|
+
* on one so a retry, a redelivered event or a duplicated webhook can never
|
|
83
|
+
* charge twice.
|
|
84
|
+
*/
|
|
85
|
+
export declare const idempotencyKeySchema: z.ZodString;
|
|
86
|
+
/** Credential environments. A credential is issued into exactly one of them. */
|
|
87
|
+
export declare const inferenceEnvironmentSchema: z.ZodEnum<["development", "staging", "production"]>;
|
|
88
|
+
/**
|
|
89
|
+
* An instant, as an ISO 8601 string in UTC (`2026-08-15T09:41:00.000Z`).
|
|
90
|
+
*
|
|
91
|
+
* Validated rather than left free-form — unlike the session contracts, which
|
|
92
|
+
* carry legacy expiry strings no consumer interprets, every instant here is
|
|
93
|
+
* read: a reservation expires, a price version starts applying, a receipt is
|
|
94
|
+
* settled. One canonical spelling (UTC, `Z`) so two records that describe the
|
|
95
|
+
* same moment compare and sort as equal, which a mix of offsets would not.
|
|
96
|
+
*/
|
|
97
|
+
export declare const inferenceTimestampSchema: z.ZodString;
|
|
98
|
+
/**
|
|
99
|
+
* A calendar DATE with no instant attached (`2026-05-01`) — a knowledge cutoff
|
|
100
|
+
* or a release date, which are published as days and become wrong when a
|
|
101
|
+
* timezone is invented for them.
|
|
102
|
+
*/
|
|
103
|
+
export declare const inferenceDateSchema: z.ZodString;
|
|
104
|
+
/** An absolute https URL, for model cards, licenses and provider documentation. */
|
|
105
|
+
export declare const inferenceHttpsUrlSchema: z.ZodString;
|
|
106
|
+
/**
|
|
107
|
+
* A content digest, `sha256:<64 lowercase hex>`.
|
|
108
|
+
*
|
|
109
|
+
* ONE spelling, because a digest is compared for equality and nothing else: an
|
|
110
|
+
* uppercase or unprefixed variant of the same hash is a different string, so two
|
|
111
|
+
* records describing the same bytes would not match. Lowercase hex with the
|
|
112
|
+
* algorithm prefix is what the `inference_model_revisions` CHECK stores and what
|
|
113
|
+
* every artifact registry emits.
|
|
114
|
+
*/
|
|
115
|
+
export declare const sha256DigestSchema: z.ZodString;
|
|
116
|
+
/** A publisher slug, e.g. `openai`, `anthropic`, `meta`, `alia`. */
|
|
117
|
+
export declare const publisherSlugSchema: z.ZodString;
|
|
118
|
+
/** A model slug within its publisher's namespace, e.g. `gpt-5`, `llama-3.1-70b`. */
|
|
119
|
+
export declare const modelSlugSchema: z.ZodString;
|
|
120
|
+
/**
|
|
121
|
+
* A canonical model id, `<publisher>/<model>`. This names a MODEL — a
|
|
122
|
+
* long-lived product identity whose behaviour changes as revisions ship. It
|
|
123
|
+
* does not name a revision, a deployment or a provider.
|
|
124
|
+
*/
|
|
125
|
+
export declare const modelIdSchema: z.ZodString;
|
|
126
|
+
/** An immutable revision label, unique within its model, e.g. `2026-05-01`. */
|
|
127
|
+
export declare const modelRevisionLabelSchema: z.ZodString;
|
|
128
|
+
/**
|
|
129
|
+
* A model reference as a customer writes it: `<publisher>/<model>` (the model's
|
|
130
|
+
* current revision, chosen by Oxy) or `<publisher>/<model>@<revision>` (an
|
|
131
|
+
* immutable revision the customer pinned).
|
|
132
|
+
*
|
|
133
|
+
* Both forms name a CONCRETE MODEL. Neither can name a routing profile — see
|
|
134
|
+
* {@link routingProfileSlugSchema} — which is what makes "a request for a
|
|
135
|
+
* concrete model is never silently replaced with a different model" a
|
|
136
|
+
* distinction the type system can carry rather than a convention.
|
|
137
|
+
*/
|
|
138
|
+
export declare const modelReferenceSchema: z.ZodString;
|
|
139
|
+
/**
|
|
140
|
+
* A routing-profile slug, e.g. `auto`, `fast`, `quality`.
|
|
141
|
+
*
|
|
142
|
+
* Deliberately refuses a `/`, so a profile can never be written in the shape of
|
|
143
|
+
* a model id and no caller can be confused about whether they asked for a
|
|
144
|
+
* concrete model or for Oxy to choose one. Modes like `auto`/`fast`/`quality`
|
|
145
|
+
* are profiles or product presets; they are never model objects.
|
|
146
|
+
*/
|
|
147
|
+
export declare const routingProfileSlugSchema: z.ZodString;
|
|
148
|
+
/**
|
|
149
|
+
* The opaque PostgreSQL identity of one routing profile.
|
|
150
|
+
*
|
|
151
|
+
* No trim, case-folding or format heuristic: callers selecting by id must name
|
|
152
|
+
* the exact stored bytes. The database lookup is the authority for existence.
|
|
153
|
+
*/
|
|
154
|
+
export declare const routingProfileIdSchema: z.ZodString;
|
|
155
|
+
/** An inference provider slug, e.g. `openai`, `bedrock`, `oxy-hosted`. */
|
|
156
|
+
export declare const inferenceProviderSlugSchema: z.ZodString;
|
|
157
|
+
/**
|
|
158
|
+
* A deployment/endpoint id. Opaque to customers: which concrete endpoint served
|
|
159
|
+
* a request is the data plane's operational detail, and only the customer-safe
|
|
160
|
+
* subset of it is ever attributed back (see the catalogue's serving-boundary
|
|
161
|
+
* rules).
|
|
162
|
+
*/
|
|
163
|
+
export declare const deploymentIdSchema: z.ZodString;
|
|
164
|
+
/**
|
|
165
|
+
* A region identifier, e.g. `us-west-2`, `eu-central-1`. Free-form rather than
|
|
166
|
+
* a closed enum because the set is provider-defined and grows without any
|
|
167
|
+
* contract change; residency policies match on exact strings.
|
|
168
|
+
*/
|
|
169
|
+
export declare const inferenceRegionSchema: z.ZodString;
|
|
170
|
+
/**
|
|
171
|
+
* The publisher namespace reserved for models Alia actually owns or derives.
|
|
172
|
+
*
|
|
173
|
+
* `alia/*` is never a re-badged third-party route and never a prompt preset —
|
|
174
|
+
* enforcing that is the job of `modelSchema`'s provenance refinement, which
|
|
175
|
+
* this constant exists to be checked against.
|
|
176
|
+
*/
|
|
177
|
+
export declare const RESERVED_ALIA_PUBLISHER = "alia";
|
|
178
|
+
export type OxyAccountId = z.infer<typeof oxyAccountIdSchema>;
|
|
179
|
+
export type DelegatedUserId = z.infer<typeof delegatedUserIdSchema>;
|
|
180
|
+
export type InferenceEnvironment = z.infer<typeof inferenceEnvironmentSchema>;
|
|
181
|
+
export type ModelReference = z.infer<typeof modelReferenceSchema>;
|
|
182
|
+
export type ModelId = z.infer<typeof modelIdSchema>;
|