POST /v1/chat/completionsSend a chat request to any supported provider through the gateway. The response format is identical to OpenAI’s chat completions API regardless of which provider handles the request.
Remote URLs are fetched server-side with SSRF checks and a shared deadline. Text files are inlined as text on every model; images and documents require a model with the matching capability. Anthropic accepts images and PDF documents only. See prompt file variables for the dashboard upload flow.
Values must be string, number, or boolean — nested objects and arrays are rejected (400)
Keys are limited to 64 characters and values to 128 characters; at most 100 keys per request
The field is stripped before forwarding to the provider — it never reaches the upstream API
It appears on the log entry and can be filtered with key=value in the dashboard
The gateway also accepts user in the body — a standard OpenAI field. It is forwarded to OpenAI-compatible providers unchanged, and used as the logged end-user ID when no signed-token claim or x-gatelit-end-user-id header set one. (Non-OpenAI providers that lack the field — e.g. Anthropic, Google — ignore it; the gateway still logs it.)
cache opts into an exact-match response cache. Only deterministic requests are eligible — non-streaming, explicit temperature: 0, no tools — and only successful responses are stored, so a failure retry always hits the upstream provider fresh.
{ "ttl": 3600 } — custom TTL in seconds; must be positive and is clamped to 60–3600
false — bypass both reads and writes; pass this when you explicitly retry for a fresh answer
The cache key is scoped to org + model + the full request body (minus gateway-internal fields) + output schema, so changing response_format, seed, or any other parameter produces a distinct entry. A fallback-winning response is cached under the model that actually answered. The response header tells you what happened:
Header value
Meaning
HIT
Served from cache — no upstream call, no provider spend
MISS
Cached the fresh response on this request
BYPASS
Cache was requested but the request isn’t cacheable (streaming, temperature ≠ 0, tools), or cache: false
import { GatelitClient } from "@gatelit/sdk"const response = await client.chat({ model: "openai/gpt-4o", messages: [{ role: "user", content: "Classify this email: order placed" }], temperature: 0, cache: true,})if (response.meta.cacheHit) { console.log("served from cache — no cost")}
rate_limit, provider_error, timeout, refusal_detected, or cache (a cached response produced by a different model)
x-gatelit-fallback-model
The fallback model that responded
x-gatelit-clamped
Params the gateway clamped or stripped against the resolved model’s limits (e.g. max_tokens=10000->4096,temperature=removed). Only present when the gateway modified the request
x-gatelit-cache
HIT, MISS, or BYPASS when the request opted into caching
Params are forwarded to the provider as-is within the resolved model’s catalog limits. The gateway clamps out-of-range values (e.g. max_tokens above the model’s cap) rather than erroring — when that happens, x-gatelit-clamped tells you what changed. The provider enforces the budget itself: a response that ends with finish_reason: "length" hit the max_tokens cap. Streaming responses surface the same header; the final SSE chunk carries the model’s finish_reason.
Trigger conditions (triggers): rate_limit, provider_error, timeout, refusal_detected. Without triggers, the fallback fires on any failure. A fallback candidate never falls through when its provider is disabled for your org — it is skipped in order.
OIDC JWT issued by your auth provider (Alpha).
Full self-serve configuration is coming soon — contact us for early access.
Use this for browser/frontend clients where a user is signed in.
Maximum tokens to generate. The gateway maps this to the correct
upstream parameter — max_completion_tokens for OpenAI reasoning
models, max_tokens for everything else.
End-user identifier (standard OpenAI field). Forwarded to the provider
unchanged, and used as the logged end-user ID when no signed-token
claim or x-gatelit-end-user-id header is present.
Arbitrary tags attached to the request — environment, feature, session,
tenant, and so on. Values must be string, number, or boolean; keys are
limited to 64 characters and string values to 128 characters. Stripped
before forwarding to the provider, stored on the log entry, and
filterable in the dashboard.
Opt-in exact-match response cache. Only deterministic requests are
cached — non-streaming, explicit temperature: 0, no tools — and
only successful upstream responses are stored. Cache reads happen
before any upstream call; a fallback-winning response is cached
under the model that actually answered. The response header
x-gatelit-cache reports HIT, MISS, or BYPASS.
Response
Successful response.
Non-streaming:Content-Type: application/json
Streaming:Content-Type: text/event-stream
Response headers always include:
x-gatelit-request-id — use for log lookup in the dashboard
x-gatelit-model — the provider/model that responded
x-gatelit-auth-mode — Bearer, GatelitSigned, or GatelitKey
OpenAI-compatible chat completion response.
Returned when stream is false (default).
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Gatelit","colors":{"primary":"#6366f1","light":"#818cf8","dark":"#4f46e5"},"logo":{"light":"https://mintcdn.com/gatelit/nfB0Pw2EV0_b488r/logo/gatelit-light.svg?fit=max\u0026auto=format\u0026n=nfB0Pw2EV0_b488r\u0026q=85\u0026s=ca585002ed63491bf132b671e8032c55","dark":"https://mintcdn.com/gatelit/nfB0Pw2EV0_b488r/logo/gatelit-dark.svg?fit=max\u0026auto=format\u0026n=nfB0Pw2EV0_b488r\u0026q=85\u0026s=4387a8dc17f3aea2ae3468fa06db837d"},"favicon":"https://mintcdn.com/gatelit/FhMvfa6HGf_S7MCU/favicon.svg?fit=max\u0026auto=format\u0026n=FhMvfa6HGf_S7MCU\u0026q=85\u0026s=30529ffcee19371c3a9d57188b04b44e","api":{"openapi":"gateway/openapi.yaml"},"navbar":{"links":[{"href":"mailto:hello@gatelit.dev","label":"Contact","type":"link"}],"primary":{"type":"button","label":"Dashboard","href":"https://app.gatelit.dev"}},"footer":{"socials":{}},"styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"gatelit","hasAudioNarration":false,"actualSubdomain":"gatelit","customDomains":["docs.gatelit.dev"],"gitSource":{"type":"github","owner":"dbssman","repo":"gatelit","deployBranch":"main","contentDirectory":"apps/docs","isPrivate":true,"mountPath":"","label":""},"chroma":{"liveDeploymentHistoryId":"6ad92ef500ae219b501cee91","collectionId":"a94f9ab6-8c04-41f1-8492-4fd706459a6b","schemaVersion":"v3","latestBuiltDeploymentHistoryId":"6ad92ef500ae219b501cee91"},"entitlements":{},"buildId":"6ad92ef500ae219b501cee91","clientVersion":"0.0.4074","searchFilterCounts":[{"language":"default","tag":"SDK","count":12},{"language":"default","tag":"Gateway","count":10},{"language":"default","tag":"How it works","count":6},{"language":"default","tag":"TypeScript","count":6},{"language":"default","tag":"Dashboard","count":5},{"language":"default","tag":"Managing Gatelit","count":5},{"language":"default","tag":"API Reference","count":4},{"language":"default","tag":"TypeScript Reference","count":3},{"language":"default","tag":"Vue","count":3},{"language":"default","tag":"Get Started","count":2}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"comment-mode","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[],"page":{"pagePath":"gateway/api-reference/chat-completions","slug":"/gateway/api-reference/chat-completions","pageMetadata":{"title":"Chat Completions","description":"OpenAI-compatible chat endpoint. Any provider, any model.","openapi":"post /v1/chat/completions","href":"/gateway/api-reference/chat-completions"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"OpenAI-compatible chat endpoint. Any provider, any model.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,li:`li`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Info,Table}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Info)_missingMdxReference(`Info`,true);if(!Table)_missingMdxReference(`Table`,true);return _jsxs(_Fragment,{children:[_jsx(_components.p,{children:_jsx(_components.code,{children:`POST /v1/chat/completions`})}),`\n`,_jsx(_components.p,{children:`Send a chat request to any supported provider through the gateway. The response format is identical to OpenAI’s chat completions API regardless of which provider handles the request.`}),`\n`,_jsx(Heading,{level:`2`,id:`auth`,children:`Auth`}),`\n`,_jsx(_components.p,{children:`All three schemes are accepted:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`2`,language:`http`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`http`,children:_jsxs(_components.code,{language:`http`,numberOfLines:`2`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:`Authorization`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` GatelitKey glk_...`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:`Authorization`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` GatelitSigned \u003csigned-token>`})]}),`\n`]})})}),`\n`,_jsx(Info,{children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`Bearer`}),` (OIDC) is supported but in `,_jsx(_components.strong,{children:`Alpha`}),`. `,_jsx(_components.a,{href:`mailto:hello@gatelit.dev`,children:`Contact us`}),` if you need OIDC auth.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`request`,children:`Request`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Field`}),_jsx(_components.th,{children:`Type`}),_jsx(_components.th,{children:`Required`}),_jsx(_components.th,{children:`Description`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`model`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`string`})}),_jsx(_components.td,{children:`Yes`}),_jsxs(_components.td,{children:[`Provider/model in `,_jsx(_components.code,{children:`provider/model-id`}),` format`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`messages`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`array`})}),_jsx(_components.td,{children:`Yes`}),_jsxs(_components.td,{children:[`Array of `,_jsx(_components.code,{children:`{role, content}`}),` objects`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`max_tokens`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`integer`})}),_jsx(_components.td,{children:`No`}),_jsx(_components.td,{children:`Max output tokens`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`temperature`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`number`})}),_jsx(_components.td,{children:`No`}),_jsx(_components.td,{children:`0–2, stripped for reasoning models`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`stream`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`boolean`})}),_jsx(_components.td,{children:`No`}),_jsx(_components.td,{children:`Enable SSE streaming`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`user`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`string`})}),_jsx(_components.td,{children:`No`}),_jsxs(_components.td,{children:[`End-user ID — forwarded to the provider and used as the logged end-user ID when no token claim or `,_jsx(_components.code,{children:`x-gatelit-end-user-id`}),` header is present`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`metadata`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`object`})}),_jsx(_components.td,{children:`No`}),_jsx(_components.td,{children:`Arbitrary string/number/boolean tags — stripped before forwarding, stored on the log entry, filterable in the dashboard`})]})]})]}),`\n`,_jsx(Heading,{level:`3`,id:`content-blocks`,children:`Content blocks`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`messages[].content`}),` may be a string or an array of content blocks:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`10`,language:`json`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`json`,children:_jsxs(_components.code,{language:`json`,numberOfLines:`10`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:`\"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"text\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:`\"text\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Summarise this document\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"file\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"file\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: { `}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:`\"mime_type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"application/pdf\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:`\"file_data\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"data:application/pdf;base64,...\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ]`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Block`}),_jsx(_components.th,{children:`Shape`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`text`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`{ \"type\": \"text\", \"text\": \"...\" }`})})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`image_url`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`{ \"type\": \"image_url\", \"image_url\": { \"url\": \"https://… or data:image/…\" } }`})})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`file`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`{ \"type\": \"file\", \"file\": { \"mime_type\": \"...\", \"file_data\" | \"url\" | \"file_id\": \"...\" } }`})})]})]})]}),`\n`,_jsxs(_components.p,{children:[`Remote URLs are fetched server-side with SSRF checks and a shared deadline. Text files are inlined as text on every model; images and documents require a model with the matching capability. Anthropic accepts images and PDF documents only. See `,_jsx(_components.a,{href:`/gateway/api-reference/prompt-run`,children:`prompt file variables`}),` for the dashboard upload flow.`]}),`\n`,_jsx(Heading,{level:`3`,id:`gateway-specific-fields`,children:`Gateway-specific fields`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Field`}),_jsx(_components.th,{children:`Description`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`output_schema`})}),_jsxs(_components.td,{children:[`Structured output config (`,_jsx(_components.code,{children:`json_object`}),` or `,_jsx(_components.code,{children:`json_schema`}),` mode)`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`prompt_id`})}),_jsx(_components.td,{children:`Tag request with a saved prompt’s slug for log correlation`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`fallback_chain`})}),_jsx(_components.td,{children:`Ordered fallback models with trigger conditions`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`cache`})}),_jsxs(_components.td,{children:[`Opt-in response cache — `,_jsx(_components.code,{children:`true`}),`, `,_jsx(_components.code,{children:`{ ttl: seconds }`}),`, or `,_jsx(_components.code,{children:`false`}),` to bypass`]})]})]})]}),`\n`,_jsx(Heading,{level:`3`,id:`metadata`,children:`Metadata`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`metadata`}),` lets you attach business context to a request — environment, feature, session, tenant, experiment — without polluting the provider call:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`9`,language:`json`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`json`,children:_jsxs(_components.code,{language:`json`,numberOfLines:`9`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"model\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"openai/gpt-4o\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"messages\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [{`}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:`\"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:`\"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Hello!\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"metadata\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"environment\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"production\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"feature\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"doc-summariser\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"session_id\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"sess_123\"`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`Rules:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`Values must be `,_jsx(_components.code,{children:`string`}),`, `,_jsx(_components.code,{children:`number`}),`, or `,_jsx(_components.code,{children:`boolean`}),` — nested objects and arrays are rejected (400)`]}),`\n`,_jsx(_components.li,{children:`Keys are limited to 64 characters and values to 128 characters; at most 100 keys per request`}),`\n`,_jsxs(_components.li,{children:[`The field is `,_jsx(_components.strong,{children:`stripped before forwarding`}),` to the provider — it never reaches the upstream API`]}),`\n`,_jsxs(_components.li,{children:[`It appears on the `,_jsx(_components.a,{href:`/dashboard/logs`,children:`log entry`}),` and can be filtered with `,_jsx(_components.code,{children:`key=value`}),` in the dashboard`]}),`\n`]}),`\n`,_jsxs(_components.p,{children:[`The gateway also accepts `,_jsx(_components.code,{children:`user`}),` in the body — a standard OpenAI field. It is forwarded to OpenAI-compatible providers unchanged, and used as the logged end-user ID when no signed-token claim or `,_jsx(_components.code,{children:`x-gatelit-end-user-id`}),` header set one. (Non-OpenAI providers that lack the field — e.g. Anthropic, Google — ignore it; the gateway still logs it.)`]}),`\n`,_jsx(Heading,{level:`3`,id:`response-caching`,children:`Response caching`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`cache`}),` opts into an exact-match response cache. Only deterministic requests are eligible — non-streaming, explicit `,_jsx(_components.code,{children:`temperature: 0`}),`, no tools — and only successful responses are stored, so a failure retry always hits the upstream provider fresh.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`9`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`9`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`curl`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` https://gateway.gatelit.dev/v1/chat/completions`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Content-Type: application/json\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Authorization: GatelitKey glk_...\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -d`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"model\": \"openai/gpt-4o\",`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"messages\": [{\"role\": \"user\", \"content\": \"Classify this email: order placed\"}],`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"temperature\": 0,`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"cache\": true`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` }'`})}),`\n`]})})}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`true`}),` — cache with the default TTL (5 minutes)`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`{ \"ttl\": 3600 }`}),` — custom TTL in seconds; must be positive and is clamped to 60–3600`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`false`}),` — bypass both reads and writes; pass this when you explicitly retry for a fresh answer`]}),`\n`]}),`\n`,_jsxs(_components.p,{children:[`The cache key is scoped to org + model + the full request body (minus gateway-internal fields) + output schema, so changing `,_jsx(_components.code,{children:`response_format`}),`, `,_jsx(_components.code,{children:`seed`}),`, or any other parameter produces a distinct entry. A fallback-winning response is cached under the model that actually answered. The response header tells you what happened:`]}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Header value`}),_jsx(_components.th,{children:`Meaning`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`HIT`})}),_jsx(_components.td,{children:`Served from cache — no upstream call, no provider spend`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`MISS`})}),_jsx(_components.td,{children:`Cached the fresh response on this request`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`BYPASS`})}),_jsxs(_components.td,{children:[`Cache was requested but the request isn’t cacheable (streaming, temperature ≠ 0, tools), or `,_jsx(_components.code,{children:`cache: false`})]})]})]})]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`12`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`12`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`GatelitClient`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"@gatelit/sdk\"`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` response`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` client`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`chat`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` model:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"openai/gpt-4o\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` messages:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [{ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`role:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Classify this email: order placed\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` temperature:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` cache:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`})`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`response`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`meta`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`cacheHit`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"served from cache — no cost\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`response`,children:`Response`}),`\n`,_jsx(Heading,{level:`3`,id:`non-streaming`,children:`Non-streaming`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`15`,language:`json`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`json`,children:_jsxs(_components.code,{language:`json`,numberOfLines:`15`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"id\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"chatcmpl-abc123\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"object\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"chat.completion\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"model\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"openai/gpt-4o\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"choices\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [{`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"index\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"message\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: { `}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:`\"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"assistant\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:`\"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"...\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"finish_reason\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"stop\"`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }],`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"usage\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"prompt_tokens\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`15`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"completion_tokens\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`8`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"total_tokens\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`23`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`response-headers`,children:`Response headers`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Header`}),_jsx(_components.th,{children:`Description`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`x-gatelit-request-id`})}),_jsx(_components.td,{children:`Unique request ID for log lookup`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`x-gatelit-model`})}),_jsxs(_components.td,{children:[`Resolved model in `,_jsx(_components.code,{children:`provider/model`}),` format`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`x-gatelit-auth-mode`})}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`Bearer`}),`, `,_jsx(_components.code,{children:`GatelitSigned`}),`, or `,_jsx(_components.code,{children:`GatelitKey`})]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`x-gatelit-fallback`})}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`\"true\"`}),` when a fallback model was used`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`x-gatelit-fallback-reason`})}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`rate_limit`}),`, `,_jsx(_components.code,{children:`provider_error`}),`, `,_jsx(_components.code,{children:`timeout`}),`, `,_jsx(_components.code,{children:`refusal_detected`}),`, or `,_jsx(_components.code,{children:`cache`}),` (a cached response produced by a different model)`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`x-gatelit-fallback-model`})}),_jsx(_components.td,{children:`The fallback model that responded`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`x-gatelit-clamped`})}),_jsxs(_components.td,{children:[`Params the gateway clamped or stripped against the resolved model’s limits (e.g. `,_jsx(_components.code,{children:`max_tokens=10000->4096,temperature=removed`}),`). Only present when the gateway modified the request`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`x-gatelit-cache`})}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`HIT`}),`, `,_jsx(_components.code,{children:`MISS`}),`, or `,_jsx(_components.code,{children:`BYPASS`}),` when the request opted into caching`]})]})]})]}),`\n`,_jsxs(_components.p,{children:[`Params are forwarded to the provider as-is within the resolved model’s catalog limits. The gateway clamps out-of-range values (e.g. `,_jsx(_components.code,{children:`max_tokens`}),` above the model’s cap) rather than erroring — when that happens, `,_jsx(_components.code,{children:`x-gatelit-clamped`}),` tells you what changed. The provider enforces the budget itself: a response that ends with `,_jsx(_components.code,{children:`finish_reason: \"length\"`}),` hit the `,_jsx(_components.code,{children:`max_tokens`}),` cap. Streaming responses surface the same header; the final SSE chunk carries the model’s `,_jsx(_components.code,{children:`finish_reason`}),`.`]}),`\n`,_jsx(Heading,{level:`3`,id:`streaming`,children:`Streaming`}),`\n`,_jsxs(_components.p,{children:[`When `,_jsx(_components.code,{children:`stream: true`}),`, the response is an OpenAI-compatible SSE stream. Each `,_jsx(_components.code,{children:`data:`}),` line is a JSON chunk. Final line is `,_jsx(_components.code,{children:`data: [DONE]`}),`.`]}),`\n`,_jsx(Heading,{level:`2`,id:`examples`,children:`Examples`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`7`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`7`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`curl`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` https://gateway.gatelit.dev/v1/chat/completions`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Content-Type: application/json\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Authorization: GatelitKey glk_...\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -d`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"model\": \"openai/gpt-4o\",`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"messages\": [{\"role\": \"user\", \"content\": \"Hello!\"}]`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` }'`})}),`\n`]})})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`11`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`11`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`GatelitClient`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"@gatelit/sdk\"`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` client`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` GatelitClient`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` gatewayUrl:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"https://gateway.gatelit.dev\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` getToken`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` async`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` () `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`=>`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ({ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`token:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"glk_...\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`scheme:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"GatelitKey\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }),`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`})`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` response`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` client`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`chat`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` model:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"openai/gpt-4o\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` messages:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [{ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`role:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Hello!\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }],`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`})`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`structured-output`,children:`Structured output`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`16`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`16`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`curl`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` https://gateway.gatelit.dev/v1/chat/completions`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Content-Type: application/json\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Authorization: GatelitKey glk_...\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -d`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"model\": \"openai/gpt-4o\",`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"messages\": [{\"role\": \"user\", \"content\": \"Alice is 30.\"}],`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"output_schema\": {`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"mode\": \"json_schema\",`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"type\": \"object\",`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"properties\": {`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"name\": {\"type\": \"string\"},`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"age\": {\"type\": \"integer\"}`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"required\": [\"name\", \"age\"]`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` }'`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`with-fallback-chain`,children:`With fallback chain`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`11`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`11`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`curl`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` https://gateway.gatelit.dev/v1/chat/completions`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Content-Type: application/json\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Authorization: GatelitKey glk_...\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -d`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"model\": \"openai/gpt-4o\",`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"messages\": [{\"role\": \"user\", \"content\": \"Explain TCP\"}],`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"fallback_chain\": [`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` {\"model\": \"anthropic/claude-3-5-haiku-20241022\", \"triggers\": [\"rate_limit\"]},`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` {\"model\": \"google/gemini-2.5-flash\"}`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` ]`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` }'`})}),`\n`]})})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`20`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`20`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`GatelitClient`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"@gatelit/sdk\"`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` client`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` GatelitClient`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` gatewayUrl:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"https://gateway.gatelit.dev\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` getToken`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` async`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` () `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`=>`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ({ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`token:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"glk_...\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`scheme:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"GatelitKey\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }),`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`})`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` response`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` client`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`chat`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` model:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"openai/gpt-4o\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` messages:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [{ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`role:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Explain TCP\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` fallbackChain:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`model:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"anthropic/claude-3-5-haiku-20241022\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`triggers:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"rate_limit\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`] },`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`model:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"google/gemini-2.5-flash\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ],`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`})`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// When a fallback fired, the response exposes it:`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`response`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`meta`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`usedFallback`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`Handled by \"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`response`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`meta`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`fallbackModel`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` (`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`response`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`meta`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`fallbackReason`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\")`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`Trigger conditions (`,_jsx(_components.code,{children:`triggers`}),`): `,_jsx(_components.code,{children:`rate_limit`}),`, `,_jsx(_components.code,{children:`provider_error`}),`, `,_jsx(_components.code,{children:`timeout`}),`, `,_jsx(_components.code,{children:`refusal_detected`}),`. Without `,_jsx(_components.code,{children:`triggers`}),`, the fallback fires on any failure. A fallback candidate never falls through when its provider is disabled for your org — it is skipped in order.`]}),`\n`,_jsx(Heading,{level:`2`,id:`errors`,children:`Errors`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Status`}),_jsx(_components.th,{children:`Code`}),_jsx(_components.th,{children:`Meaning`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{\"data-numeric\":`true`,children:`400`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`gateway_error`})}),_jsx(_components.td,{children:`Invalid model format or missing fields`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{\"data-numeric\":`true`,children:`401`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`unauthorized`})}),_jsx(_components.td,{children:`Missing, invalid, or expired token`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{\"data-numeric\":`true`,children:`502`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`provider_error`})}),_jsx(_components.td,{children:`Upstream provider returned an error`})]})]})]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Chat Completions","description":"OpenAI-compatible chat endpoint. Any provider, any model.","openapi":"post /v1/chat/completions","href":"/gateway/api-reference/chat-completions"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Auth","slug":"auth","depth":2,"children":[]},{"title":"Request","slug":"request","depth":2,"children":[{"title":"Content blocks","slug":"content-blocks","depth":3,"children":[]},{"title":"Gateway-specific fields","slug":"gateway-specific-fields","depth":3,"children":[]},{"title":"Metadata","slug":"metadata","depth":3,"children":[]},{"title":"Response caching","slug":"response-caching","depth":3,"children":[]}]},{"title":"Response","slug":"response","depth":2,"children":[{"title":"Non-streaming","slug":"non-streaming","depth":3,"children":[]},{"title":"Response headers","slug":"response-headers","depth":3,"children":[]},{"title":"Streaming","slug":"streaming","depth":3,"children":[]}]},{"title":"Examples","slug":"examples","depth":2,"children":[{"title":"Structured output","slug":"structured-output","depth":3,"children":[]},{"title":"With fallback chain","slug":"with-fallback-chain","depth":3,"children":[]}]},{"title":"Errors","slug":"errors","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"openApiReferenceData":{"operation":{"operationId":"chatCompletions","summary":"Chat completions","description":"OpenAI-compatible chat endpoint. Any provider, any model.","security":["254f6e19-c14c-43a3-8737-76daad30fe89","d1fe51f8-da1d-47c0-b8d5-d005b2875839","d1d0a665-f6c9-4410-af41-81b2bf985fd0"],"x-codeSamples":[{"lang":"curl","label":"curl — service key","source":"curl https://gateway.gatelit.dev/v1/chat/completions \\\n -H \"Content-Type: application/json\" \\\n -H \"Authorization: GatelitKey glk_your_service_key\" \\\n -d '{\n \"model\": \"openai/gpt-4o\",\n \"messages\": [{\"role\": \"user\", \"content\": \"What is the capital of France?\"}]\n }'\n"},{"lang":"curl","label":"curl — signed token","source":"# First, have your backend issue a token (shown here for illustration).\n# In practice, this happens on a server endpoint.\n\nTOKEN=$(node -e \"\n const { exchangeToken } = require('@gatelit/sdk/sign');\n exchangeToken({\n gatewayUrl: 'https://gateway.gatelit.dev',\n serviceKey: process.env.GATELIT_SERVICE_KEY,\n sub: 'user_123',\n ttl: 60\n }).then(r => console.log(r.token))\n\")\n\ncurl https://gateway.gatelit.dev/v1/chat/completions \\\n -H \"Content-Type: application/json\" \\\n -H \"Authorization: GatelitSigned $TOKEN\" \\\n -d '{\n \"model\": \"openai/gpt-4o\",\n \"messages\": [{\"role\": \"user\", \"content\": \"Hello!\"}]\n }'\n"},{"lang":"ts","label":"SDK — non-streaming","source":"import { GatelitClient } from \"@gatelit/sdk\"\n\nconst client = new GatelitClient({\n gatewayUrl: \"https://gateway.gatelit.dev\",\n getToken: async () => ({\n token: \"glk_...\",\n scheme: \"GatelitKey\",\n }),\n})\n\nconst response = await client.chat({\n model: \"openai/gpt-4o\",\n messages: [{ role: \"user\", content: \"What is the capital of France?\" }],\n})\n\nconsole.log(response.content) // \"The capital of France is Paris.\"\nconsole.log(response.usage) // { inputTokens: 15, outputTokens: 8, totalTokens: 23 }\n"},{"lang":"ts","label":"SDK — streaming","source":"import { GatelitClient } from \"@gatelit/sdk\"\n\nconst client = new GatelitClient({\n gatewayUrl: \"https://gateway.gatelit.dev\",\n getToken: async () => {\n const res = await fetch(\"/api/ai-token\")\n const { token } = await res.json()\n return { token, scheme: \"GatelitSigned\" }\n },\n})\n\nfor await (const chunk of client.stream({\n model: \"anthropic/claude-3-5-haiku-20241022\",\n messages: [{ role: \"user\", content: \"Write a haiku about clouds.\" }],\n})) {\n process.stdout.write(chunk.delta)\n}\n"},{"lang":"ts","label":"SDK — typed JSON","source":"import { GatelitClient } from \"@gatelit/sdk\"\n\nconst client = new GatelitClient({\n gatewayUrl: \"https://gateway.gatelit.dev\",\n getToken: async () => ({\n token: \"glk_...\",\n scheme: \"GatelitKey\",\n }),\n})\n\nconst result = await client.chatJson\u003c{ name: string; age: number }>({\n model: \"openai/gpt-4o\",\n messages: [{ role: \"user\", content: \"Alice is 30 years old.\" }],\n outputSchema: {\n mode: \"json_schema\",\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n age: { type: \"integer\" },\n },\n required: [\"name\", \"age\"],\n },\n})\n\nconsole.log(result.name, result.age) // Alice 30\n"}],"requestBody":"bab2fc02-833d-4ab6-87f7-3f890041020a","responses":{"200":"10584641-3d91-4265-887d-580242b17b33","400":"71ae7ecd-d668-4df6-8708-52ba0bd7d3fe","401":"57698624-0404-4770-93fb-47b3c1830f76","502":"c512c2a1-560b-4c07-9e0c-b96ff1127e62"},"method":"post","type":"path","servers":["27652b57-ae9a-4757-97cd-462fe4275096"],"path":"/v1/chat/completions","baseUrlOptions":["https://gateway.gatelit.dev"],"title":"Chat completions","codeSamples":[{"label":"curl — service key","lang":"curl","source":"curl https://gateway.gatelit.dev/v1/chat/completions \\\n -H \"Content-Type: application/json\" \\\n -H \"Authorization: GatelitKey glk_your_service_key\" \\\n -d '{\n \"model\": \"openai/gpt-4o\",\n \"messages\": [{\"role\": \"user\", \"content\": \"What is the capital of France?\"}]\n }'\n"},{"label":"curl — signed token","lang":"curl","source":"# First, have your backend issue a token (shown here for illustration).\n# In practice, this happens on a server endpoint.\n\nTOKEN=$(node -e \"\n const { exchangeToken } = require('@gatelit/sdk/sign');\n exchangeToken({\n gatewayUrl: 'https://gateway.gatelit.dev',\n serviceKey: process.env.GATELIT_SERVICE_KEY,\n sub: 'user_123',\n ttl: 60\n }).then(r => console.log(r.token))\n\")\n\ncurl https://gateway.gatelit.dev/v1/chat/completions \\\n -H \"Content-Type: application/json\" \\\n -H \"Authorization: GatelitSigned $TOKEN\" \\\n -d '{\n \"model\": \"openai/gpt-4o\",\n \"messages\": [{\"role\": \"user\", \"content\": \"Hello!\"}]\n }'\n"},{"label":"SDK — non-streaming","lang":"ts","source":"import { GatelitClient } from \"@gatelit/sdk\"\n\nconst client = new GatelitClient({\n gatewayUrl: \"https://gateway.gatelit.dev\",\n getToken: async () => ({\n token: \"glk_...\",\n scheme: \"GatelitKey\",\n }),\n})\n\nconst response = await client.chat({\n model: \"openai/gpt-4o\",\n messages: [{ role: \"user\", content: \"What is the capital of France?\" }],\n})\n\nconsole.log(response.content) // \"The capital of France is Paris.\"\nconsole.log(response.usage) // { inputTokens: 15, outputTokens: 8, totalTokens: 23 }\n"},{"label":"SDK — streaming","lang":"ts","source":"import { GatelitClient } from \"@gatelit/sdk\"\n\nconst client = new GatelitClient({\n gatewayUrl: \"https://gateway.gatelit.dev\",\n getToken: async () => {\n const res = await fetch(\"/api/ai-token\")\n const { token } = await res.json()\n return { token, scheme: \"GatelitSigned\" }\n },\n})\n\nfor await (const chunk of client.stream({\n model: \"anthropic/claude-3-5-haiku-20241022\",\n messages: [{ role: \"user\", content: \"Write a haiku about clouds.\" }],\n})) {\n process.stdout.write(chunk.delta)\n}\n"},{"label":"SDK — typed JSON","lang":"ts","source":"import { GatelitClient } from \"@gatelit/sdk\"\n\nconst client = new GatelitClient({\n gatewayUrl: \"https://gateway.gatelit.dev\",\n getToken: async () => ({\n token: \"glk_...\",\n scheme: \"GatelitKey\",\n }),\n})\n\nconst result = await client.chatJson\u003c{ name: string; age: number }>({\n model: \"openai/gpt-4o\",\n messages: [{ role: \"user\", content: \"Alice is 30 years old.\" }],\n outputSchema: {\n mode: \"json_schema\",\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n age: { type: \"integer\" },\n },\n required: [\"name\", \"age\"],\n },\n})\n\nconsole.log(result.name, result.age) // Alice 30\n"}],"requiredOnlyExamples":false,"requestExampleType":"codeSamples","responseExampleType":"generated"},"dependencies":{"parameters":{},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["model","messages"],"properties":{"model":{"type":"string","description":"Model in `provider/model-id` format.\nSupported providers: `openai`, `anthropic`, `google`, `mistral`.\n","examples":["openai/gpt-4o","anthropic/claude-3-5-sonnet-20241022","google/gemini-2.5-flash","mistral/mistral-large-latest"],"isRequired":true,"uniqueKey":"model","typeLabel":"string"},"messages":{"type":"array","items":{"type":"object","required":["role","content"],"properties":{"role":{"type":"string","enum":["system","user","assistant"],"isRequired":true,"uniqueKey":"messages.items.[INDEX].role","typeLabel":"enum\u003cstring>"},"content":{"oneOf":[{"type":"string","description":"Plain text — may be a JSON string of content blocks","isRequired":true,"uniqueKey":"messages.items.[INDEX].content.oneOf.0","typeLabel":"string"},{"type":"array","items":{"type":"object","required":["type"],"properties":{"type":{"type":"string","enum":["text","image_url","file"],"isRequired":true,"uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].type","typeLabel":"enum\u003cstring>"},"text":{"type":"string","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].text","typeLabel":"string"},"image_url":{"type":"object","properties":{"url":{"type":"string","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].image_url.url","typeLabel":"string"}},"uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].image_url","typeLabel":"object"},"file":{"type":"object","properties":{"mime_type":{"type":"string","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].file.mime_type","typeLabel":"string"},"file_data":{"type":"string","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].file.file_data","typeLabel":"string"},"file_id":{"type":"string","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].file.file_id","typeLabel":"string"},"url":{"type":"string","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].file.url","typeLabel":"string"}},"uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX].file","typeLabel":"object"}},"uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX]","typeLabel":"object"},"description":"Multimodal content blocks. Supported types: `text`,\n`image_url` (URL or base64 data URL), `file` (base64 data\nURL, remote URL, or provider file_id). Converted to each\nprovider's native format by the gateway.\n","isRequired":true,"uniqueKey":"messages.items.[INDEX].content.oneOf.1","typeLabel":"object[]"}],"isRequired":true,"uniqueKey":"messages.items.[INDEX].content","typeLabel":"string | object[]"}},"example":{"role":"user","content":"Explain quantum entanglement in one sentence."},"x-codeSample":"// SDK\nconst msg: ChatMessage = {\n role: \"user\",\n content: \"Explain quantum entanglement in one sentence.\"\n}\n","uniqueKey":"messages.items.[INDEX]","typeLabel":"object"},"minItems":1,"isRequired":true,"uniqueKey":"messages","typeLabel":"object[]"},"max_tokens":{"type":"integer","description":"Maximum tokens to generate. The gateway maps this to the correct\nupstream parameter — `max_completion_tokens` for OpenAI reasoning\nmodels, `max_tokens` for everything else.\n","example":1024,"uniqueKey":"max_tokens","typeLabel":"integer"},"temperature":{"type":"number","minimum":0,"maximum":2,"description":"Sampling temperature. Omit for reasoning models (o3, o3-mini, o4-mini)\n— the gateway strips it automatically based on the model catalog.\n","example":0.7,"uniqueKey":"temperature","typeLabel":"number"},"top_p":{"type":"number","minimum":0,"maximum":1,"description":"Nucleus sampling. Supported by all providers.","uniqueKey":"top_p","typeLabel":"number"},"stream":{"type":"boolean","default":false,"description":"When true, the response is an OpenAI-compatible SSE stream.\nEach `data:` line is a JSON object regardless of the upstream provider.\n","uniqueKey":"stream","typeLabel":"boolean"},"user":{"type":"string","description":"End-user identifier (standard OpenAI field). Forwarded to the provider\nunchanged, and used as the logged end-user ID when no signed-token\nclaim or `x-gatelit-end-user-id` header is present.\n","example":"customer_42","uniqueKey":"user","typeLabel":"string"},"metadata":{"type":"object","additionalProperties":{"oneOf":[{"type":"string","uniqueKey":"metadata.additionalProperties.oneOf.0","typeLabel":"string"},{"type":"number","uniqueKey":"metadata.additionalProperties.oneOf.1","typeLabel":"number"},{"type":"boolean","uniqueKey":"metadata.additionalProperties.oneOf.2","typeLabel":"boolean"}],"uniqueKey":"metadata.additionalProperties","typeLabel":"string | number | boolean"},"maxProperties":100,"description":"Arbitrary tags attached to the request — environment, feature, session,\ntenant, and so on. Values must be string, number, or boolean; keys are\nlimited to 64 characters and string values to 128 characters. Stripped\nbefore forwarding to the provider, stored on the log entry, and\nfilterable in the dashboard.\n","example":{"environment":"production","feature":"doc-summariser","session_id":"sess_123"},"uniqueKey":"metadata","typeLabel":"object"},"output_schema":{"type":"object","description":"Structured output configuration. The gateway translates to the\ncorrect provider-specific format automatically.\n","properties":{"mode":{"type":"string","enum":["json_object","json_schema"],"description":"`json_object` — model must return valid JSON (any shape).\n`json_schema` — model must return JSON matching the provided schema.\n","isRequired":true,"uniqueKey":"output_schema.mode","typeLabel":"enum\u003cstring>"},"type":{"type":"string","description":"JSON Schema `type` for `json_schema` mode.","uniqueKey":"output_schema.type","typeLabel":"string"},"properties":{"type":"object","additionalProperties":true,"description":"JSON Schema `properties` for `json_schema` mode.","uniqueKey":"output_schema.properties","typeLabel":"object"},"required":{"type":"array","items":{"type":"string","uniqueKey":"output_schema.required.items.[INDEX]","typeLabel":"string"},"uniqueKey":"output_schema.required","typeLabel":"string[]"}},"required":["mode"],"uniqueKey":"output_schema","typeLabel":"object"},"prompt_id":{"type":"string","description":"Associates this request with a saved prompt in the dashboard.\nThe prompt's content is not used — only the ID is logged for correlation.\n","uniqueKey":"prompt_id","typeLabel":"string"},"fallback_chain":{"type":"array","description":"Ordered list of fallback models to try if the primary model fails.\nEach entry specifies a model and the error types that trigger it.\n","items":{"type":"object","required":["model"],"properties":{"model":{"type":"string","description":"Fallback model in `provider/model-id` format.","isRequired":true,"uniqueKey":"fallback_chain.items.[INDEX].model","typeLabel":"string"},"triggers":{"type":"array","items":{"type":"string","enum":["rate_limit","provider_error","timeout","refusal_detected"],"uniqueKey":"fallback_chain.items.[INDEX].triggers.items.[INDEX]","typeLabel":"enum\u003cstring>"},"description":"Error types that trigger this fallback.\nOmit to trigger on any error from the previous model.\n","uniqueKey":"fallback_chain.items.[INDEX].triggers","typeLabel":"enum\u003cstring>[]"}},"uniqueKey":"fallback_chain.items.[INDEX]","typeLabel":"object"},"uniqueKey":"fallback_chain","typeLabel":"object[]"},"cache":{"oneOf":[{"type":"boolean","description":"Opt-in exact-match response cache. Only deterministic requests are\ncached — non-streaming, explicit `temperature: 0`, no tools — and\nonly successful upstream responses are stored. Cache reads happen\nbefore any upstream call; a fallback-winning response is cached\nunder the model that actually answered. The response header\n`x-gatelit-cache` reports HIT, MISS, or BYPASS.\n","uniqueKey":"cache.oneOf.0","typeLabel":"boolean"},{"type":"object","description":"Opt-in exact-match response cache. Only deterministic requests are\ncached — non-streaming, explicit `temperature: 0`, no tools — and\nonly successful upstream responses are stored. Cache reads happen\nbefore any upstream call; a fallback-winning response is cached\nunder the model that actually answered. The response header\n`x-gatelit-cache` reports HIT, MISS, or BYPASS.\n","required":["ttl"],"properties":{"ttl":{"type":"integer","minimum":60,"maximum":3600,"description":"Cache TTL in seconds, clamped to 60–3600.\n","isRequired":true,"uniqueKey":"cache.oneOf.1.ttl","typeLabel":"integer"}},"uniqueKey":"cache.oneOf.1","typeLabel":"object"}],"uniqueKey":"cache","typeLabel":"boolean | object"}},"uniqueKey":"","typeLabel":"object"},"examples":{"simple":{"title":"simple","value":{"model":"openai/gpt-4o","messages":[{"role":"user","content":"What is the capital of France?"}]}},"streaming":{"title":"streaming","value":{"model":"anthropic/claude-3-5-haiku-20241022","messages":[{"role":"user","content":"Write a haiku about cloud infrastructure."}],"stream":true,"max_tokens":100}},"json_schema":{"title":"json_schema","value":{"model":"openai/gpt-4o","messages":[{"role":"user","content":"Extract the name and age: \"Alice is 30 years old.\""}],"output_schema":{"mode":"json_schema","type":"object","properties":{"name":{"type":"string"},"age":{"type":"integer"}},"required":["name","age"]}}},"fallback":{"title":"fallback","value":{"model":"openai/gpt-4o","messages":[{"role":"user","content":"Hello"}],"fallback_chain":[{"model":"anthropic/claude-3-5-haiku-20241022","triggers":["rate_limit","provider_error"]},{"model":"google/gemini-2.5-flash"}]}},"with_prompt_id":{"title":"with_prompt_id","value":{"model":"openai/gpt-4o","messages":[{"role":"user","content":"Summarize this document"}],"prompt_id":"my-summarizer"}}},"exampleType":"examples"}},"exampleType":"examples"},"responses":{"10584641-3d91-4265-887d-580242b17b33":{"description":"Successful response.\n\n- **Non-streaming:** `Content-Type: application/json`\n- **Streaming:** `Content-Type: text/event-stream`\n\nResponse headers always include:\n- `x-gatelit-request-id` — use for log lookup in the dashboard\n- `x-gatelit-model` — the provider/model that responded\n- `x-gatelit-auth-mode` — `Bearer`, `GatelitSigned`, or `GatelitKey`\n","headers":{"x-gatelit-request-id":{"schema":{"type":"string"},"description":"Unique request ID — look up in dashboard logs"},"x-gatelit-model":{"schema":{"type":"string"},"description":"Resolved model in `provider/model` format"},"x-gatelit-auth-mode":{"schema":{"type":"string"},"description":"Auth scheme used"},"x-gatelit-fallback":{"schema":{"type":"string"},"description":"Present only when a fallback model was used"},"x-gatelit-fallback-reason":{"schema":{"type":"string"},"description":"Why the fallback triggered (`rate_limit`, `provider_error`, `timeout`,\n`refusal_detected`, or `cache` — a cached response produced by a different model)\n"},"x-gatelit-fallback-model":{"schema":{"type":"string"},"description":"The fallback model that responded"},"x-gatelit-clamped":{"schema":{"type":"string"},"description":"Params the gateway clamped or stripped against the resolved model's catalog limits, e.g. `max_tokens=10000->4096, temperature=removed`. Present only when the gateway modified the request."},"x-gatelit-cache":{"schema":{"type":"string","enum":["HIT","MISS","BYPASS"]},"description":"Present when the request opted into caching. `HIT` — served from\ncache (no upstream call). `MISS` — fresh response cached. `BYPASS` —\nrequest not cacheable (streaming, temperature ≠ 0, tools) or cache: false.\n"}},"content":{"application/json":{"schema":{"type":"object","description":"OpenAI-compatible chat completion response.\nReturned when `stream` is false (default).\n","properties":{"id":{"type":"string","uniqueKey":"id","typeLabel":"string"},"object":{"type":"string","example":"chat.completion","uniqueKey":"object","typeLabel":"string"},"created":{"type":"integer","uniqueKey":"created","typeLabel":"integer"},"model":{"type":"string","description":"The upstream model that handled the request.","uniqueKey":"model","typeLabel":"string"},"choices":{"type":"array","items":{"type":"object","properties":{"index":{"type":"integer","uniqueKey":"choices.items.[INDEX].index","typeLabel":"integer"},"message":{"type":"object","required":["role","content"],"properties":{"role":{"type":"string","enum":["system","user","assistant"],"isRequired":true,"uniqueKey":"choices.items.[INDEX].message.role","typeLabel":"enum\u003cstring>"},"content":{"oneOf":[{"type":"string","description":"Plain text — may be a JSON string of content blocks","isRequired":true,"uniqueKey":"choices.items.[INDEX].message.content.oneOf.0","typeLabel":"string"},{"type":"array","items":{"type":"object","required":["type"],"properties":{"type":{"type":"string","enum":["text","image_url","file"],"isRequired":true,"uniqueKey":"choices.items.[INDEX].message.content.oneOf.1.items.[INDEX].type","typeLabel":"enum\u003cstring>"},"text":{"type":"string","uniqueKey":"choices.items.[INDEX].message.content.oneOf.1.items.[INDEX].text","typeLabel":"string"},"image_url":{"type":"object","properties":{"url":{"type":"string","uniqueKey":"choices.items.[INDEX].message.content.oneOf.1.items.[INDEX].image_url.url","typeLabel":"string"}},"uniqueKey":"choices.items.[INDEX].message.content.oneOf.1.items.[INDEX].image_url","typeLabel":"object"},"file":{"type":"object","properties":{"mime_type":{"type":"string","uniqueKey":"choices.items.[INDEX].message.content.oneOf.1.items.[INDEX].file.mime_type","typeLabel":"string"},"file_data":{"type":"string","uniqueKey":"choices.items.[INDEX].message.content.oneOf.1.items.[INDEX].file.file_data","typeLabel":"string"},"file_id":{"type":"string","uniqueKey":"choices.items.[INDEX].message.content.oneOf.1.items.[INDEX].file.file_id","typeLabel":"string"},"url":{"type":"string","uniqueKey":"choices.items.[INDEX].message.content.oneOf.1.items.[INDEX].file.url","typeLabel":"string"}},"uniqueKey":"choices.items.[INDEX].message.content.oneOf.1.items.[INDEX].file","typeLabel":"object"}},"uniqueKey":"choices.items.[INDEX].message.content.oneOf.1.items.[INDEX]","typeLabel":"object"},"description":"Multimodal content blocks. Supported types: `text`,\n`image_url` (URL or base64 data URL), `file` (base64 data\nURL, remote URL, or provider file_id). Converted to each\nprovider's native format by the gateway.\n","isRequired":true,"uniqueKey":"choices.items.[INDEX].message.content.oneOf.1","typeLabel":"object[]"}],"isRequired":true,"uniqueKey":"choices.items.[INDEX].message.content","typeLabel":"string | object[]"}},"example":{"role":"user","content":"Explain quantum entanglement in one sentence."},"x-codeSample":"// SDK\nconst msg: ChatMessage = {\n role: \"user\",\n content: \"Explain quantum entanglement in one sentence.\"\n}\n","uniqueKey":"choices.items.[INDEX].message","typeLabel":"object"},"finish_reason":{"type":"string","enum":["stop","length","tool_calls","content_filter"],"uniqueKey":"choices.items.[INDEX].finish_reason","typeLabel":"enum\u003cstring>"}},"uniqueKey":"choices.items.[INDEX]","typeLabel":"object"},"uniqueKey":"choices","typeLabel":"object[]"},"usage":{"type":"object","properties":{"prompt_tokens":{"type":"integer","description":"Tokens consumed by the input (system prompt + messages).","uniqueKey":"usage.prompt_tokens","typeLabel":"integer"},"completion_tokens":{"type":"integer","description":"Tokens generated in the response.","uniqueKey":"usage.completion_tokens","typeLabel":"integer"},"total_tokens":{"type":"integer","uniqueKey":"usage.total_tokens","typeLabel":"integer"}},"uniqueKey":"usage","typeLabel":"object"}},"uniqueKey":"","typeLabel":"object"},"example":{"id":"chatcmpl-abc123","object":"chat.completion","created":1717776000,"model":"openai/gpt-4o","choices":[{"index":0,"message":{"role":"assistant","content":"The capital of France is Paris."},"finish_reason":"stop"}],"usage":{"prompt_tokens":15,"completion_tokens":8,"total_tokens":23}},"examples":{"Example":{"title":"Example","value":{"id":"chatcmpl-abc123","object":"chat.completion","created":1717776000,"model":"openai/gpt-4o","choices":[{"index":0,"message":{"role":"assistant","content":"The capital of France is Paris."},"finish_reason":"stop"}],"usage":{"prompt_tokens":15,"completion_tokens":8,"total_tokens":23}}}},"exampleType":"examples"},"text/event-stream":{"schema":{"type":"string","description":"OpenAI-compatible SSE stream. Each `data:` line is a JSON object.\nThe final line is `data: [DONE]`.\n\n```sse\ndata: {\"id\":\"chatcmpl-abc\",\"choices\":[{\"delta\":{\"content\":\"The\"},\"index\":0}]}\ndata: {\"id\":\"chatcmpl-abc\",\"choices\":[{\"delta\":{\"content\":\" capital\"},\"index\":0}]}\ndata: {\"id\":\"chatcmpl-abc\",\"choices\":[{\"delta\":{\"content\":\" of\"},\"index\":0}]}\n...\ndata: {\"id\":\"chatcmpl-abc\",\"choices\":[{\"delta\":{},\"finish_reason\":\"stop\"}]}\ndata: {\"id\":\"chatcmpl-abc\",\"choices\":[],\"usage\":{\"prompt_tokens\":15,\"completion_tokens\":8,\"total_tokens\":23}}\ndata: [DONE]\n```\n","uniqueKey":"","typeLabel":"string"},"examples":{"Example":{"title":"Example","value":"\u003cstring>"}},"exampleType":"generated"}},"exampleType":"examples"},"71ae7ecd-d668-4df6-8708-52ba0bd7d3fe":{"description":"Bad request — invalid model format, missing fields, or malformed JSON.","content":{"application/json":{"schema":{"type":"object","required":["error","code","message"],"properties":{"error":{"type":"boolean","enum":[true],"isRequired":true,"uniqueKey":"error","typeLabel":"enum\u003cboolean>"},"code":{"type":"string","enum":["unauthorized","gateway_error","provider_error","forbidden","policy_violation","rate_limit_exceeded","model_not_allowed","token_limit_exceeded"],"isRequired":true,"uniqueKey":"code","typeLabel":"enum\u003cstring>"},"message":{"type":"string","isRequired":true,"uniqueKey":"message","typeLabel":"string"}},"uniqueKey":"","typeLabel":"object"},"example":{"error":true,"code":"gateway_error","message":"Missing or invalid 'model' field. Expected format: 'provider/model-name'"},"examples":{"Example":{"title":"Example","value":{"error":true,"code":"gateway_error","message":"Missing or invalid 'model' field. Expected format: 'provider/model-name'"}}},"exampleType":"examples"}},"exampleType":"examples"},"57698624-0404-4770-93fb-47b3c1830f76":{"description":"Authentication failed — missing, invalid, or expired token.","content":{"application/json":{"schema":{"type":"object","required":["error","code","message"],"properties":{"error":{"type":"boolean","enum":[true],"isRequired":true,"uniqueKey":"error","typeLabel":"enum\u003cboolean>"},"code":{"type":"string","enum":["unauthorized","gateway_error","provider_error","forbidden","policy_violation","rate_limit_exceeded","model_not_allowed","token_limit_exceeded"],"isRequired":true,"uniqueKey":"code","typeLabel":"enum\u003cstring>"},"message":{"type":"string","isRequired":true,"uniqueKey":"message","typeLabel":"string"}},"uniqueKey":"","typeLabel":"object"},"example":{"error":true,"code":"unauthorized","message":"Invalid or expired token"},"examples":{"Example":{"title":"Example","value":{"error":true,"code":"unauthorized","message":"Invalid or expired token"}}},"exampleType":"examples"}},"exampleType":"examples"},"c512c2a1-560b-4c07-9e0c-b96ff1127e62":{"description":"Upstream provider returned an error or was unreachable. Check fallback chains.","content":{"application/json":{"schema":{"type":"object","required":["error","code","message"],"properties":{"error":{"type":"boolean","enum":[true],"isRequired":true,"uniqueKey":"error","typeLabel":"enum\u003cboolean>"},"code":{"type":"string","enum":["unauthorized","gateway_error","provider_error","forbidden","policy_violation","rate_limit_exceeded","model_not_allowed","token_limit_exceeded"],"isRequired":true,"uniqueKey":"code","typeLabel":"enum\u003cstring>"},"message":{"type":"string","isRequired":true,"uniqueKey":"message","typeLabel":"string"}},"uniqueKey":"","typeLabel":"object"},"example":{"error":true,"code":"provider_error","message":"Upstream error 503 — Service Unavailable"},"examples":{"Example":{"title":"Example","value":{"error":true,"code":"provider_error","message":"Upstream error 503 — Service Unavailable"}}},"exampleType":"examples"}},"exampleType":"examples"}},"security":{"254f6e19-c14c-43a3-8737-76daad30fe89":{"BearerToken":{"type":"http","scheme":"bearer","description":"OIDC JWT issued by your auth provider (Alpha).\nFull self-serve configuration is coming soon — [contact us](mailto:hello@gatelit.dev) for early access.\nUse this for browser/frontend clients where a user is signed in.\n","scopes":[],"schemeName":"BearerToken"}},"d1fe51f8-da1d-47c0-b8d5-d005b2875839":{"GatelitSigned":{"type":"apiKey","in":"header","name":"Authorization","description":"Short-lived HMAC-signed token obtained via token exchange.\nFormat: `GatelitSigned \u003ctoken>`\n\nExchange a service key for a signed token via `POST /v1/auth/token`:\n```ts\nimport { exchangeToken } from \"@gatelit/sdk\"\nconst { token } = await exchangeToken({\n gatewayUrl: \"https://gateway.gatelit.dev\",\n serviceKey: process.env.GATELIT_SERVICE_KEY!,\n sub: \"user-123\",\n ttl: 60,\n})\n```\n","scopes":[],"schemeName":"GatelitSigned"}},"d1d0a665-f6c9-4410-af41-81b2bf985fd0":{"GatelitKey":{"type":"apiKey","in":"header","name":"Authorization","description":"Long-lived service key for backend-to-backend use.\nFormat: `GatelitKey glk_...`\n\nCreate service keys in the dashboard under Settings → Service Keys.\n","scopes":[],"schemeName":"GatelitKey"}}},"servers":{"27652b57-ae9a-4757-97cd-462fe4275096":{"url":"https://gateway.gatelit.dev","description":"Your gateway URL"}},"processedSecurityOptions":[{"schemes":[{"scheme":{"type":"http","scheme":"bearer","description":"OIDC JWT issued by your auth provider (Alpha).\nFull self-serve configuration is coming soon — [contact us](mailto:hello@gatelit.dev) for early access.\nUse this for browser/frontend clients where a user is signed in.\n","scopes":[],"schemeName":"BearerToken"},"schema":{"title":"Bearer Auth","type":"string","isRequired":true,"description":"OIDC JWT issued by your auth provider (Alpha).\nFull self-serve configuration is coming soon — [contact us](mailto:hello@gatelit.dev) for early access.\nUse this for browser/frontend clients where a user is signed in.\n","format":"bearer","typeLabel":"string\u003cbearer>","deprecated":false},"schemeName":"BearerToken","name":"Authorization"}],"title":"BearerToken"},{"schemes":[{"scheme":{"type":"apiKey","in":"header","name":"Authorization","description":"Short-lived HMAC-signed token obtained via token exchange.\nFormat: `GatelitSigned \u003ctoken>`\n\nExchange a service key for a signed token via `POST /v1/auth/token`:\n```ts\nimport { exchangeToken } from \"@gatelit/sdk\"\nconst { token } = await exchangeToken({\n gatewayUrl: \"https://gateway.gatelit.dev\",\n serviceKey: process.env.GATELIT_SERVICE_KEY!,\n sub: \"user-123\",\n ttl: 60,\n})\n```\n","scopes":[],"schemeName":"GatelitSigned"},"schema":{"title":"Authorization","type":"string","description":"Short-lived HMAC-signed token obtained via token exchange.\nFormat: `GatelitSigned \u003ctoken>`\n\nExchange a service key for a signed token via `POST /v1/auth/token`:\n```ts\nimport { exchangeToken } from \"@gatelit/sdk\"\nconst { token } = await exchangeToken({\n gatewayUrl: \"https://gateway.gatelit.dev\",\n serviceKey: process.env.GATELIT_SERVICE_KEY!,\n sub: \"user-123\",\n ttl: 60,\n})\n```\n","isRequired":true,"typeLabel":"string","deprecated":false},"schemeName":"GatelitSigned","name":"Authorization"}],"title":"GatelitSigned"},{"schemes":[{"scheme":{"type":"apiKey","in":"header","name":"Authorization","description":"Long-lived service key for backend-to-backend use.\nFormat: `GatelitKey glk_...`\n\nCreate service keys in the dashboard under Settings → Service Keys.\n","scopes":[],"schemeName":"GatelitKey"},"schema":{"title":"Authorization","type":"string","description":"Long-lived service key for backend-to-backend use.\nFormat: `GatelitKey glk_...`\n\nCreate service keys in the dashboard under Settings → Service Keys.\n","isRequired":true,"typeLabel":"string","deprecated":false},"schemeName":"GatelitKey","name":"Authorization"}],"title":"GatelitKey"}]},"originalFileLocation":"gateway/openapi.yaml"},"subdomain":"gatelit","siteName":"Gatelit","title":"Chat Completions - Gatelit","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-10-21T21:30:34.203Z","originalFileLocation":"gateway/api-reference/chat-completions.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"OpenAI-compatible chat endpoint. Any provider, any model.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Gatelit\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/gatelit/O8gMkp8jxt9Ymk-U/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/gatelit/O8gMkp8jxt9Ymk-U/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/gatelit/O8gMkp8jxt9Ymk-U/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/gatelit/O8gMkp8jxt9Ymk-U/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/gatelit/O8gMkp8jxt9Ymk-U/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/gatelit/O8gMkp8jxt9Ymk-U/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/gatelit/O8gMkp8jxt9Ymk-U/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/gatelit/O8gMkp8jxt9Ymk-U/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/gatelit/O8gMkp8jxt9Ymk-U/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Chat Completions - Gatelit\">\u003cmeta data-mint-head property=\"og:description\" content=\"OpenAI-compatible chat endpoint. Any provider, any model.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Gatelit\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.gatelit.dev/gateway/api-reference/chat-completions\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://gatelit.mintlify.site/_mintlify/api/og/v2?division=API+Reference\u0026amp;title=Chat+Completions\u0026amp;description=OpenAI-compatible+chat+endpoint.+Any+provider%2C+any+model.\u0026amp;theme=bb48ac3e5427060fc772bf6f\u0026amp;signature=e8bb13e3c3bf114da9acbeec65b18e7979a6cf41d698cc2dc83e9dd55444ef60\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Chat Completions - Gatelit\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"OpenAI-compatible chat endpoint. Any provider, any model.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://gatelit.mintlify.site/_mintlify/api/og/v2?division=API+Reference\u0026amp;title=Chat+Completions\u0026amp;description=OpenAI-compatible+chat+endpoint.+Any+provider%2C+any+model.\u0026amp;theme=bb48ac3e5427060fc772bf6f\u0026amp;signature=e8bb13e3c3bf114da9acbeec65b18e7979a6cf41d698cc2dc83e9dd55444ef60\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/gatelit/O8gMkp8jxt9Ymk-U/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Gatelit\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#6366f1\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.gatelit.dev/gateway/api-reference/chat-completions\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/gateway/api-reference/chat-completions.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.gatelit.dev/#organization\",\"name\":\"Gatelit\",\"url\":\"https://docs.gatelit.dev\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/gatelit/nfB0Pw2EV0_b488r/logo/gatelit-light.svg?fit=max\u0026auto=format\u0026n=nfB0Pw2EV0_b488r\u0026q=85\u0026s=ca585002ed63491bf132b671e8032c55\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.gatelit.dev#website\",\"name\":\"Gatelit\",\"url\":\"https://docs.gatelit.dev\",\"publisher\":{\"@id\":\"https://docs.gatelit.dev/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.gatelit.dev/gateway/api-reference/chat-completions#webpage\",\"url\":\"https://docs.gatelit.dev/gateway/api-reference/chat-completions\",\"name\":\"Chat Completions\",\"description\":\"OpenAI-compatible chat endpoint. Any provider, any model.\",\"dateModified\":\"2026-10-21T21:30:34.203Z\",\"isPartOf\":{\"@id\":\"https://docs.gatelit.dev#website\"},\"breadcrumb\":{\"@id\":\"https://docs.gatelit.dev/gateway/api-reference/chat-completions#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.gatelit.dev/gateway/api-reference/chat-completions#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Gatelit\",\"item\":\"https://docs.gatelit.dev\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Chat Completions\",\"item\":\"https://docs.gatelit.dev/gateway/api-reference/chat-completions\"}]},{\"@type\":[\"TechArticle\",\"APIReference\"],\"@id\":\"https://docs.gatelit.dev/gateway/api-reference/chat-completions#apireference\",\"headline\":\"Chat Completions\",\"name\":\"Chat Completions\",\"description\":\"OpenAI-compatible chat endpoint. Any provider, any model.\",\"url\":\"https://docs.gatelit.dev/gateway/api-reference/chat-completions\",\"mainEntityOfPage\":{\"@id\":\"https://docs.gatelit.dev/gateway/api-reference/chat-completions#webpage\"},\"dateModified\":\"2026-10-21T21:30:34.203Z\",\"publisher\":{\"@id\":\"https://docs.gatelit.dev/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.gatelit.dev#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Gatelit\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"Gatelit","nav":{"global":null,"tabs":[{"tab":"Get Started","pages":[{"title":"Get Started","href":"/quickstart"}]},{"tab":"Gateway","groups":[{"group":"How it works","pages":[{"title":"Gateway overview","href":"/gateway/overview"},{"title":"Authentication","href":"/gateway/authentication"},{"title":"Models","href":"/gateway/models"},{"title":"Metadata","href":"/gateway/metadata"},{"title":"Conventions","href":"/gateway/conventions"},{"title":"Errors","description":"Error types returned by the gateway.","href":"/gateway/errors"}]},{"group":"API Reference","pages":[{"title":"Chat Completions","openapi":"post /v1/chat/completions","href":"/gateway/api-reference/chat-completions"},{"title":"Token Exchange","description":"Exchange a long-lived service key for a short-lived signed token.","openapi":"post /v1/auth/token","href":"/gateway/api-reference/token-exchange"},{"title":"Run Prompt","openapi":"post /v1/prompts/{slug}/run","href":"/gateway/api-reference/prompt-run"},{"title":"Health Check","openapi":"get /health","href":"/gateway/api-reference/health"}]}]},{"tab":"SDK","pages":[{"title":"SDK","href":"/sdk/typescript/overview"}]},{"tab":"Dashboard","pages":[{"title":"Dashboard","href":"/dashboard/providers"}]}]},"basePath":"","title":"Chat Completions - Gatelit","buildId":"dpl_BLQvU86QFwq3AhPofSTw6q8dGWKm","deploymentId":"dpl_BLQvU86QFwq3AhPofSTw6q8dGWKm","dynamics":["c2aa737661","2b790eda92","b0f84f53ff","a9bb46feb3"],"chunks":["OpenApiReferenceProvider-Myd8dsju.js","utils-C2HkQgW0.js","cloneDeep-izs3Hzxb.js","_Uint8Array-BVIqJ90l.js","isObjectLike-C8vmzPEN.js","isArray-Dcu1dQ5t.js","utils-8rSppmTv.js","toString-BX-iyh8G.js","isSymbol-CSH9U2Gm.js","addUniqueKeysToSchema-B6MjiCFm.js","snippetPresets-DwrSAONL.js","style-to-object-BY3JEAdk.js","v4-DIgz8zy6.js","ApiExamples-1-a5UQKQ.js","isEqual-BfaiBbcl.js","usePlaygroundInputsStore-C541m7wZ.js","shallow-CWELCZ77.js","getApiPlaygroundDisplay-CTo5Zn03.js","CodeSnippet-D--dzvnl.js","CodeSnippets-DM3cXEDh.js","Page-CxAy5y67.js","getPastedJson-C-VECgcL.js","icon-BPq2-Mg3.js","MethodPill-D9J5cUHd.js","DuplicateIcon-BqHaxUnD.js","createIcon-CIbcZHp9.js","DynamicMarkdown-BKiHAm_d.js","SectionHeading-DstQXt3H.js","axios-vUo_bRtp.js","Markdown-CpxgzsKA.js","clsx-C5EfhVm0.js","lib-DuNMoZ05.js","lib-B8HbPgcC.js","html-void-elements-mCSPHezU.js","dist-CJ9Oly2E.js","katex-YMM-FMeD.js","marked.esm-CZWythHk.js","AssistantPageLink-Mk6P3qvh.js"]}