Skip to main content

Responses API

/v1/responses serves the OpenAI Responses API for every provider on the gateway. It is the stateful successor to chat completions. A response can be continued with previous_response_id, it supports built-in tools such as web search, file search, code interpreter and MCP servers, it can run in the background, and reasoning models can carry encrypted reasoning between turns. The gateway translates the format for providers without native Responses support and keeps follow-up calls on the right deployment, so coding agents and assistants built on this API work with the whole model catalogue.

Scenario​

A team runs a coding agent that keeps a long conversation with a reasoning model and spreads its traffic across two provider accounts for capacity. Each turn references the previous response id, and the reasoning items are encrypted for the account that produced them. The gateway pins every follow-up turn to the deployment that holds the state, so the agent never sees an invalid encrypted content error, and every turn is logged and costed under the team's key.

Steps​

  1. Register the model. In the Admin UI open Models + Endpoints (/ui/models-and-endpoints), click Add Model, pick the Provider, choose the model under Spanway Model Name(s), set the Public Model Name and click Add Model. Chat models serve the Responses API without any extra setting.

  2. Send a first response.

    curl -X POST http://localhost:4000/v1/responses \
    -H "Authorization: Bearer $SPANWAY_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
    "model": "gpt-6.1-sol",
    "input": "Summarize what an AI gateway does in two sentences.",
    "reasoning": {"effort": "medium"},
    "store": true
    }'
  3. Continue the conversation. Take id from the answer and send it as previous_response_id with the next input. When a model group has deployments on several provider accounts, turn on the responses_api_deployment_check pre-call check so the follow-up goes back to the deployment that stored the first response:

    router_settings:
    optional_pre_call_checks: ["responses_api_deployment_check"]

    Without it, the follow-up is load balanced like any call and can land on an account that does not hold the earlier response.

  4. Try it in the browser. Open Playground (/ui/playground), set Endpoint Type to /v1/responses, pick the model, turn on Session Management so each message continues the previous response, and send a message.

  5. Check the log. Open Logs (/ui/logs). Each turn is one row with its tokens and cost, and the rows of one session share a trace id so the trace sidebar groups them.

Expected result​

{
"id": "resp_7c2d4e1f",
"object": "response",
"created_at": 1760441234,
"status": "completed",
"model": "gpt-6.1-sol",
"output": [
{"type": "message", "id": "msg_3c4d5e6f", "role": "assistant", "status": "completed",
"content": [{"type": "output_text", "text": "An AI gateway routes requests to models.", "annotations": []}]}
],
"usage": {"input_tokens": 12, "output_tokens": 9, "total_tokens": 21}
}

The second call answers with a new response whose previous_response_id is the first id, and both appear in the Logs page.

Request fields​

input is a string or a list of input items. instructions, tools, tool_choice, previous_response_id, reasoning, text.format for structured output, temperature, max_output_tokens, stream, background, store, include and metadata are supported.

Endpoints​

MethodPathSummary
POST/v1/responsesCreate a model response
GET/v1/responses/{response_id}Read a stored response
DELETE/v1/responses/{response_id}Delete a stored response
GET/v1/responses/{response_id}/input_itemsList the input items of a response
POST/v1/responses/compactCompact a long conversation
POST/v1/responses/input_tokensCount the input tokens of a Responses API request
POST/v1/responses/{response_id}/cancelCancel a background response
GET/v1/responsesOpen a Responses API WebSocket session

Continuing a conversation​

Response ids returned by the gateway encode the deployment that produced them. With the responses_api_deployment_check pre-call check in router_settings.optional_pre_call_checks, sending previous_response_id routes the next turn to that deployment, so stored state is found. Without the check, the next turn is routed like any other call. GET /v1/responses/{response_id} fetches a stored response, GET /v1/responses/{response_id}/input_items lists its inputs, and DELETE removes it. general_settings.disable_responses_id_security and allow_unmanaged_response_ids control how strictly ids are validated.

Background mode​

With "background": true the call returns immediately with a response id in status queued, and you poll GET /v1/responses/{response_id} or cancel it with POST /v1/responses/{response_id}/cancel. With spanway_settings.responses.background_mode.polling_via_cache on, the gateway runs the call itself and streams the background response into Redis as it is produced, so polling returns partial output on any replica. native_background_mode lists models that keep the provider's own background mode, and ttl (3600 seconds by default) is how long a polled response stays in Redis. Polling through the cache needs a Redis cache, see the settings reference.

Compaction and token counting​

POST /v1/responses/compact runs a compaction pass over a long conversation and returns compact, opaque items that replace earlier turns to reduce context size. POST /v1/responses/input_tokens counts the input tokens of a request without running it and answers {"object": "response.input_tokens", "input_tokens": 6}.

Encrypted content affinity (multi-region load balancing)​

Reasoning models can return reasoning.encrypted_content items when a request uses store: false with include: ["reasoning.encrypted_content"]. Those items are encrypted for the provider account that produced them. If the next turn is load balanced to a deployment on another account or region, the provider rejects it with an invalid_encrypted_content error. The gateway solves this by encoding the originating deployment id into the response items that carry encrypted content and decoding it on the next request to pin the call to the same deployment. Enable the check in the router.

router_settings:
optional_pre_call_checks: ["encrypted_content_affinity"]

The responses_api_deployment_check pre-call check does the same for previous_response_id.

WebSocket sessions​

Responses API WebSocket sessions are supported at wss://<gateway>/v1/responses. The gateway closes a session once general_settings.responses_websocket_session_limit_seconds has passed since the connection was accepted. The default is 3600 seconds and the allowed range is 60 to 7200.

Close codeReasonMeaning
1000Session duration limit reachedThe session lifetime ended. Reconnect.
1008Invalid JSON in first message or Invalid first messageThe first frame is not a valid response.create event.
1008No model providedNeither ?model= nor the first frame named a model.
1008Pre-call errorA gateway check, such as a budget, rate limit or guardrail, refused the session.
1011Internal server errorAn unexpected failure. Retry, and quote the time if it keeps happening.
general_settings:
responses_websocket_session_limit_seconds: 1800

Each turn of a session, from a response.create frame to its response.completed, response.incomplete, response.failed or error event, is written as its own spend log row with its own request id and cost, and the rows of one session share a trace id.

Gateway features​

Keys, budgets, routing, guardrails, caching for responses call types and cost tracking all apply. MCP tools in tools run against servers registered on the gateway, see MCP.

Errors​

StatusWhat it meansFix
400 invalid_request_error with param model or input/responses: Missing required parameter: 'input'., the body lacks model or input, or input is null. An empty string is passed on to the provider.Send both fields.
400 invalid_encrypted_content from the providerA turn with encrypted reasoning landed on another deployment.Turn on the encrypted_content_affinity pre-call check.
404 NotFoundError on previous_response_idThe response id is unknown to the provider or was deleted.Use the id the gateway returned, and keep store: true when you plan to continue.
403 Forbidden. The response id is not associated with the user, who this key belongs to. ... (or team)The response id was created by another user or team.Use your own response ids. A single tenant gateway can set general_settings.disable_responses_id_security: true.
403 Forbidden. This response id was not issued by this proxy, ...The id did not come from this gateway, so its owner is unknown.Use ids this gateway returned, or set general_settings.allow_unmanaged_response_ids: true.
404 Polling response <id> not found or expiredA background response polled through the cache is unknown or past its ttl.Poll sooner or raise ttl.
500 Redis cache not configured. Polling requires Redis.polling_via_cache is on and no Redis cache is configured.Configure the Redis cache or turn polling through the cache off.
401 AuthenticationErrorThe key is missing, wrong or expired.Use a live key from Virtual Keys.
422 budget_exceededThe key, team, user or organization budget is used up.Raise the budget or wait for its reset. spanway_settings.budget_exceeded_status_code can make this a 429.
429 RateLimitErrorThe key or team is over its rate limit, or the provider is throttling.Raise the limit or add deployments.
WebSocket closed with the session limitThe session ran longer than responses_websocket_session_limit_seconds.Reconnect, or raise the limit up to 7200 seconds.

Errors have the OpenAI shape, see exception mapping.

Logs​

Each call, and each turn of a WebSocket session, is one row on the Logs page (/ui/logs) with its key, model, deployment, tokens, cost and status, and the rows of one session share a trace id. Operator log lines are in the log reference.

Providers​

The gateway's endpoint support matrix marks 131 provider integrations as supporting this endpoint:

AI21, AI21 Chat, AIHubMix (aihubmix), AI/ML API, Amazon Nova, Anthropic, Anthropic Text, AssemblyAI (assemblyai), Auto Router (auto_router), Azure, Azure AI, Azure AI Foundry Agents, Azure Text, Baseten, AWS - Bedrock, Bedrock Mantle, Bytez, Cerebras, Charity Engine (charity_engine), ChatGPT Subscription, Clarifai, Cloudflare AI Workers, Codestral, Cognition, Cohere, Cohere Chat, CometAPI, CompactifAI, Cortecs, Crusoe (crusoe), Cursor BYOK, Custom, Custom OpenAI (custom_openai), Dashscope, Databricks, DataRobot, Deepgram, DeepInfra, Deepseek, Docker Model Runner, Eden AI, ElevenLabs, EmpirioLabs (empiriolabs), Empower, Fal AI, Featherless AI, Fireworks AI, FriendliAI, Galadriel, Google AI Studio - Gemini, GigaChat, GitHub Models, GitHub Copilot, GMI Cloud, GradientAI, Groq AI, Helicone, Heroku, Hosted VLLM, Huggingface, Hyperbolic, Inception (inception), Lambda AI, LangGraph, Lemonade, Llamafile, LlamaGate, LM Studio, Manus, Maritalk, Meta Model API (meta), Meta - Llama API, Minimax, Mistral AI API, ModelScope, Moonshot, Morph, Nebius AI Studio, Neosantara, NLP Cloud, Novita AI (novita), Nscale, Nvidia NIM, OCI, Ollama, Ollama Chat, Oobabooga (oobabooga), OpenAI, OpenRouter, OVHCloud AI Endpoints, Parasail (parasail), Perplexity AI, Petals, Pinstripes, Predibase, Prism, PublicAI, Qianwen AI Platform, QwenCloud, RAGFlow, Reka, Replicate, AWS - Sagemaker, Sagemaker Chat, Sail, Sambanova, SAP Generative AI Hub, Sarvam, Scaleway, Snowflake, Spanway Proxy, Synthetic (synthetic), Tencent TokenHub (tencent), Tensormesh (tensormesh), Text Completion Codestral, Text Completion OpenAI, Together AI, Triton, V0, Venice.ai, Vercel AI Gateway, Google - Vertex AI, Vertex AI Agent Engine, VLLM, Volcengine, WandB Inference, IBM - Watsonx.ai, Watsonx Text, xAI, Xiaomi Mimo, Z.AI (Zhipu AI).