Skip to content

Gateway API

The OpenAI‑compatible endpoint and Anthropic’s Messages API: endpoints, attribution and response headers, the request pipeline, errors, providers and the simulator.

On this page

The gateway is an OpenAI‑compatible HTTP API that also serves Anthropic’s Messages API. Point any OpenAI SDK at https://gateway.worksi.ai/v1, or an Anthropic SDK at https://gateway.worksi.ai, with an aiw_sk_… key and every call is authenticated, checked against your plan and policies, forwarded to the provider you chose, priced and traced. Providers & routing explains how a call finds its provider.

Send the key as Authorization: Bearer, as x-api-key (what the Anthropic SDKs send) or as api-key (Azure‑style clients).

Endpoints#

Endpoints
Method and pathWhat it does
POST /v1/chat/completionsChat Completions, streaming and non-streaming, on every provider (translated to the Messages API for Claude). Usage is captured even for streams.
POST /v1/responsesResponses API, streaming and non-streaming, where the provider serves it
POST /v1/embeddingsEmbeddings, where the provider serves them (the model’s registry type must be embedding)
POST /v1/messagesAnthropic’s Messages API, natively, for models on Anthropic credentials. See Claude.
POST /v1/messages/count_tokensAnthropic token counting. Not metered.
GET /v1/models, GET /v1/models/{model}The models this key may use, in the OpenAI list format (Anthropic’s format when the request carries anthropic-version). ?include=catalog adds the unregistered catalog models of your preset credentials when your organization allows unregistered models (details).
GET /v1/control/statusPause and stop state, plus tool policy verdicts, for SDK pre-checks
POST /v1/control/approvals, GET /v1/control/approvals/{id}Request and poll a human approval
POST /v1/traces, POST /v1/outcomesSpans and business outcomes from the SDKs
POST /v1/otlp/v1/tracesOpenTelemetry traces over OTLP/HTTP
/mcp, /mcp/servers/{slug}The Worksi MCP server and the MCP gateway. See MCP.

Request headers#

All optional. The SDKs set them for you from the current run and step.

Request headers
HeaderMeaning
X-AIW-Agent, X-AIW-Workflow, X-AIW-TeamAttribution. Drives policies, dashboards, cost allocation and auto-discovery.
X-AIW-Run-IdWorkflow run id (defaults to the trace id)
X-AIW-Trace-Id, X-AIW-Parent-Span-IdAttach the call to your own trace. W3C traceparent is used when these are absent.
X-AIW-StepStep name
X-AIW-End-User, X-AIW-End-User-PlanYour end user (a pseudonymous id) and their plan in your app. See end‑user plans.
X-AIW-TagsComma-separated tags
X-AIW-Captureredacted or metadata_only. Can only make capture stricter.
X-AIW-Approval-IdAn approved model-access approval, for models that require one
X-AIW-Fallbackoff turns the model’s fallbacks off for this request
X-AIW-SimulateFault injection for the simulator (see below)
anthropic-version, anthropic-betaForwarded to Anthropic. anthropic-version also selects Anthropic’s format for /v1/models.

Response headers#

Response headers
HeaderMeaning
X-AIW-Request-IdGateway request id. Quote it when you contact support.
X-AIW-Trace-Id, X-AIW-Span-Id, X-AIW-Run-IdWhere to find the call in Operations → Traces
X-AIW-ProviderThe provider preset that served the call, for example deepseek, else the provider kind
X-AIW-Provider-Kindopenai, anthropic, openai_compatible or simulator
X-AIW-ModelThe model that served the call (the fallback model, when one did)
X-AIW-Fallback-FromThe model first resolved, when a fallback served the call
X-AIW-Cost-USDCost of the call in USD (non-streaming responses; streams carry the cost on the span)
X-AIW-Upstream-Request-IdThe provider’s own request id, when it sent one
X-AIW-Sampling-Dropped, X-AIW-Params-Clamped, X-AIW-Params-IgnoredParameters the gateway dropped, clamped into range or removed because the model or provider rejects them
X-AIW-Tool-Choice-DowngradedA forced tool choice set to auto, because the model cannot honor it
X-AIW-Max-Tokens-DefaultedThe max_tokens the gateway supplied for Claude
X-RateLimit-Limit, X-RateLimit-Remaining, Retry-AfterRate-limit state

What happens on every request#

  1. The body size is checked (10 MiB).
  2. The key is resolved to its organization, workspace and environment.
  3. The model is resolved through your model registry, by id or alias, or by its route prefix, and its provider must serve the endpoint.
  4. Operator controls apply: a paused agent or workflow gets 423, a stopped run gets 409.
  5. Plan and policy checks: your subscription status and monthly quota, then your policies (model allow and deny lists, spend, token and rate limits, model-access approvals, declared tools and end‑user quotas).
  6. The key’s own rate limit applies.
  7. The call goes to your provider, with timeouts and up to two retries with backoff on connection errors, 429 and 5xx, then the model’s fallbacks. There is never a retry or a fallback after the first streamed byte.
  8. Tokens and cost are computed in USD from your registry prices (or the catalog’s, for an unregistered model of a preset credential) and the call is recorded as a span. Telemetry is asynchronous: it never fails or delays the request.

Errors#

Errors use the OpenAI error shape plus the gateway request id. On /v1/messages they use Anthropic’s error shape instead, with the gateway code in error.aiw_code, so the Anthropic SDKs raise their own typed errors.

JSON
{"error": {"message": "agent \"triage-agent\" is paused: investigating INC-12", "type": "…",           "code": "agent_paused", "param": null, "aiw_request_id": "req_…"}}
Errors
HTTPcodeMeaning
400invalid_requestMalformed request, the wrong model type for the endpoint, or a request Claude cannot take (n above 1, a JSON response_format)
400unsupported_endpointThe model’s provider does not serve this endpoint, for example embeddings on Anthropic
401invalid_api_keyUnknown, revoked or expired key
402budget_exceededA spend-limit policy’s budget for the period is used up
402subscription_inactiveThe trial has ended or the subscription is inactive
403insufficient_scopeThe key lacks the endpoint’s scope
403model_not_allowedBlocked model, an allow or deny list, or a model outside the end user’s plan
403approval_requiredThe model needs an approved X-AIW-Approval-Id
403tool_not_allowedThe request declares a tool the agent may not use
403token_limit_exceededPer-request or daily token limit
409run_stoppedAn operator stopped this run. Don’t retry.
413payload_too_largeBody over 10 MiB
423agent_paused, workflow_pausedAn operator paused the agent or workflow
429rate_limitedKey or policy rate limit. Honor Retry-After.
429plan_quota_exceededYour plan’s monthly gateway requests are used up. Retry-After counts down to the next month.
429end_user_quota_exceededYour end user reached a limit of their plan
502provider_errorUpstream 5xx or connection failure after retries and fallbacks, or a disabled provider named by a route prefix
504provider_timeoutUpstream timeout

Provider 4xx responses, such as a content-policy refusal, are passed through unchanged. Every refusal by the gateway itself is still recorded as a span with status=blocked, so blocked traffic stays visible and can raise a policy-violation incident.

Providers#

Providers
KindNotes
openaihttps://api.openai.com/v1 or your own base URL
anthropicClaude, through the native Messages API adapter
openai_compatibleThe catalog presets, from DeepSeek and Qwen to Ollama and vLLM, and any other server that speaks the OpenAI API at a base URL you register
simulatorDeterministic, offline and free. Replies are derived from a hash of the prompt, latency is 150–600 ms, and streaming, embeddings and the Messages API are supported.

The presets, their route prefixes and what each one serves are listed in Providers & routing.

The gateway refuses private network addresses unless they are explicitly allowed for your deployment, and it never follows redirects.

Simulator and fault injection#

When the resolved provider is the simulator, the X-AIW-Simulate header injects faults, so you can test your error handling and your alerting without breaking anything. Faults apply to the first call only, never to fallback models. Separate directives with ;.

Simulator and fault injection
DirectiveEffect
latency=<ms>Simulated latency
error=<status>The upstream answers with that HTTP status, for example error=503
timeoutThe upstream hangs and the gateway returns 504 provider_timeout
tokens=<n>, output_tokens=<n>Report n input or output tokens
tool_call=<name>The model answers with a call of tool <name>
stream_errorAbort the stream midway
content=<url-encoded text>Fixed reply text

More examples#

curl -sN https://gateway.worksi.ai/v1/chat/completions \  -H "Authorization: Bearer $AIW_API_KEY" \  -H "Content-Type: application/json" \  -d '{"model": "gpt-5-mini", "stream": true, "messages":       [{"role": "user", "content": "Count to five"}]}'

Questions? Email info@xeoo.io.