SDKs and API formats
Responses API
Use the OpenAI Responses API format with any model on Inworld Inference, with routing, fallbacks, and web search
Inworld Inference serves the OpenAI Responses API at https://api.inworld.ai/v1/responses, alongside chat completions. Send the Responses format (input, instructions, typed output items, reasoning and tool items) to any model whose endpoints in List models includes /v1/responses; that is most models. Some, such as OpenAI's, run on a native Responses API. The others, including Anthropic, Google and Inworld-hosted models, are translated for you.
The router's model selection works here as it does on chat completions: provider/model ids, auto, saved routers (inworld/<router-id>), fallback models, and sort.
| Endpoint | Purpose |
|---|---|
POST /v1/responses | Create a response, streaming or not |
GET /v1/responses/{response_id} | Retrieve a stored response |
DELETE /v1/responses/{response_id} | Delete a stored response |
POST /v1/responses/{response_id}/cancel | Cancel a background response |
GET /v1/responses/{response_id}/input_items | List a stored response's input items |
The four {response_id} endpoints work only with responses stored by a model that can store them.
Quickstart
Run these examples on your server. Set INWORLD_API_KEY to the complete Base64 credentials copied from Portal or the CLI; see OpenAI compatibility.
import os
from openai import OpenAI
api_key = os.environ["INWORLD_API_KEY"]
client = OpenAI(
base_url="https://api.inworld.ai/v1",
api_key=api_key,
default_headers={"Authorization": f"Basic {api_key}"},
)
response = client.responses.create(
model="anthropic/claude-sonnet-4-6",
instructions="You are terse.",
input="What is the capital of France?",
)
print(response.output_text)import OpenAI from 'openai';
const apiKey = process.env.INWORLD_API_KEY;
const client = new OpenAI({
baseURL: 'https://api.inworld.ai/v1',
apiKey,
defaultHeaders: { Authorization: `Basic ${apiKey}` },
});
const response = await client.responses.create({
model: 'anthropic/claude-sonnet-4-6',
instructions: 'You are terse.',
input: 'What is the capital of France?',
});
console.log(response.output_text);curl https://api.inworld.ai/v1/responses \
-H "Authorization: Basic $INWORLD_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-sonnet-4-6",
"instructions": "You are terse.",
"input": "What is the capital of France?"
}'Request parameters
model and input are required. input is a string, which becomes a single user message, or an array of input items.
An input_image's image_url and an input_file's file_url, in a message or in a function_call_output, must be https, http or data URLs. Any other scheme returns 400, and so does a file_url with no scheme, such as gs://bucket/report.pdf or bucket/report.pdf. The error's param names the field:
{
"error": {
"message": "input[0].content[1].file_url must be an https, http or data URL",
"param": "input[0].content[1].file_url",
"type": "invalid_request_error"
}
}For a file in cloud storage, send a signed HTTPS URL or a data URL.
These Responses API parameters are passed to the model: instructions, tools, tool_choice, parallel_tool_calls, max_tool_calls, temperature, top_p, max_output_tokens, reasoning, text (including text.format for JSON schema output), stream, stream_options, store, background, previous_response_id, include, metadata, truncation, service_tier, prompt_cache_key, prompt_cache_retention, safety_identifier, and user. Other top-level keys are forwarded to the provider unchanged, except the chat-only and unsupported parameters below and the routing options.
When the selected model does not support temperature, top_p, or reasoning.effort, the router drops that parameter rather than failing the request, and lists it in routing.attempts[].warnings (reasoning.effort appears there as reasoning_effort).
Some models have a minimum output length. A max_output_tokens below it, including 0 or a negative value, is raised to the minimum rather than refused. A warning in that attempt's routing.attempts[].warnings array says so, for example max_output_tokens 5 is below the 16-token minimum for openai/gpt-5.4; sent 16, and usage.output_tokens can then be up to the minimum.
top_logprobs is not supported. A value from 0 to 20 is accepted, then dropped and listed in routing.attempts[].warnings. A value outside that range returns 400.
Not supported
| Parameter | Result |
|---|---|
conversation | 400 with code: "unsupported_parameter". Continue a conversation with previous_response_id, or send the history in input |
prompt (hosted prompt templates) | 400 with code: "unsupported_parameter". Send instructions and input directly |
item_reference input items | 400 with code: "unsupported_parameter" |
Chat Completions parameters: messages, max_tokens, max_completion_tokens, response_format, n, logprobs, stop, seed, frequency_penalty, presence_penalty, logit_bias, reasoning_effort, web_search_options, modalities, audio, prompt_variables, thinking, and other chat-only fields | 400 naming the parameter. Use the Responses equivalent (for example max_output_tokens, text.format, reasoning.effort), or send the request to /v1/chat/completions |
Image output and voice responses are available only on chat completions. modalities, image_config, and audio return 400 here, so use image generation or voice responses on /v1/chat/completions. Inworld's cache_control and compression fields are also chat-only and return 400.
A Content-Type other than application/json is refused with 415.
Routing options
Set these Inworld options at the top level of the body or inside extra_body (the OpenAI SDK's field for extra parameters). If both set the same option, the top-level value takes precedence.
| Option | Description |
|---|---|
models | Fallback models, tried in order when the primary fails. See specific models |
ignore | Models to exclude from auto selection |
sort | Ranking for auto and fallbacks, for example ["price"] or ["latency"]. See auto model selection |
provider | {"order": [...], "allow_fallbacks": true} to control which providers serve the model |
fallback | {"ttft_timeout": "2s"} to fall back when the first token is slower than this duration (at least 300ms) |
session | A session id (up to 128 printable ASCII characters, not default) for grouping the requests of one conversation |
web_search | Router-run web search; see below |
Unrecognized keys inside extra_body are refused with 400. auto cannot appear in models, ignore, or provider.order.
With a saved router (model: "inworld/<router-id>"), the router's model selection replaces models, ignore, sort and provider. Its generation settings apply only when the request sets none of temperature, top_p, max_output_tokens, top_logprobs and reasoning.effort. If the request sets any of them, none of the router's generation settings apply. Router settings that have no Responses equivalent (output modalities, audio output, image settings and prompt compression) are not applied, and the request runs without them. The successful attempt in routing.attempts[] then carries a warning that names them, such as the route sets compression, which is not available on /v1/responses; the request ran without it.
Some Inworld-hosted models (inworld/models/...) may be available only on /v1/chat/completions. For those, the request is refused with 400 and a message pointing there. To check before you call, look for /v1/responses in the model's endpoints in the List models response, or list only those models with ?endpoints=/v1/responses.
Response
The response is an OpenAI Response object, with these differences:
routingis added to every response created withPOST /v1/responses. It has the same fields asmetadataon chat completions:attempts(each with the provider-qualifiedmodel,success,status_code,duration_ms,time_to_first_token_msandwarnings),generation_id, andtotal_duration_ms, plusroute_idandvariant_idwhen a saved router chose the model. Themetadatafield is left for your own request metadata, as in OpenAI's API.modelis the model id the provider reports, for examplegpt-5.4. For the provider-qualified id (openai/gpt-5.4), readrouting.attempts[].model.- Retrieve, delete, cancel and input-item responses carry no
routingobject.
A response from openai/gpt-5.4:
{
"id": "resp_1",
"object": "response",
"model": "gpt-5.4",
"status": "completed",
"output": [
{
"id": "msg_1",
"type": "message",
"role": "assistant",
"content": [{ "type": "output_text", "text": "Paris." }]
}
],
"usage": { "input_tokens": 21, "output_tokens": 3, "total_tokens": 24 },
"routing": {
"attempts": [
{ "model": "openai/gpt-5.4", "success": true, "time_to_first_token_ms": 80 }
],
"generation_id": "5f0c1c3e-3b53-4d8e-9f53-0c2b8a4de6b1",
"total_duration_ms": 412
}
}Streaming
With stream: true, the response is a server-sent event stream of named events (response.created, response.output_text.delta, response.completed, and so on), as in OpenAI's API. The OpenAI SDKs read it unchanged.
- The stream ends after the terminal event (
response.completed,response.incomplete, orresponse.failed). There is nodata: [DONE]line. routingis included on events that carry theresponseobject, such asresponse.createdandresponse.completed.- A failure after the stream starts is sent as an
errorevent,{"type": "error", "code": ..., "message": ..., "param": ..., "sequence_number": ...}, and the stream ends. - While the model sends nothing after the stream has started, the router writes an SSE comment line,
: keepalive, at the keepalive interval, so idle connections stay open. SSE parsers, including those in the OpenAI SDKs, skip comment lines. Some models also sendkeepaliveevents of their own, such as{"type": "keepalive", "sequence_number": 3}, so skip any event type your code does not handle. - A response has the chat completions time limits, for one model attempt and for the whole request with its fallbacks. Past either limit, a request that has not started streaming returns
504withtype: "timeout_error", and a stream ends with anerrorevent.
Web search
Two ways to ground a response with web results:
- Router-run search. Set
web_search, as on chat completions:{"engine": "exa", "max_results": 3, "max_steps": 1}. The router gives the model a search tool, runs the searches, and returns one response withurl_citationannotations on the final message. Usage is summed across the search steps. Router-run search is refused withbackgroundorprevious_response_id. - Native search. Set
web_search: {"engine": "native"}, or pass the hosted tool directly:"tools": [{"type": "web_search"}]. The provider runs the search. It works on models whosespec.capabilities.webSearchistruein List models, and with background mode and continuation.
Stored responses and continuation
Only some models can store a response, continue one, or run in the background. The List models API has no field for this yet; the router checks every model a request can reach and refuses the request before it runs:
store: truereturns400withparam: "store"when a model the request can reach cannot store responses.background: truereturns400withparam: "background"when a model the request can reach cannot run in the background.previous_response_idreturns400withparam: "model"unless the request names one model that can continue the stored response.- Retrieve, delete, cancel and input items return
400withcode: "unsupported_operation"for a response these endpoints can't reach.
Store is off unless you ask for it. With Inworld-managed credentials, a response is stored only when the request sets store: true or background: true. That differs from OpenAI's API, where store defaults to true. With your own provider key, the provider's default applies. To continue a conversation with previous_response_id, set store: true on every turn you will continue from.
first = client.responses.create(
model="openai/gpt-5.4",
input="Pick a number between 1 and 10.",
store=True,
)
second = client.responses.create(
model="openai/gpt-5.4",
input="Double it.",
previous_response_id=first.id,
store=True,
)A continuation (previous_response_id) must name one model on the provider that stored the response. Sending fallback models with previous_response_id returns 400. A saved router can continue only a response that this endpoint stored for your workspace.
With Inworld-managed credentials, a stored response id is usable only by the workspace that created it, for 7 days. An unknown id, or one created by another workspace, returns 404. With your own provider key, the provider's own storage rules apply.
Background mode
background: true runs the response asynchronously, on models that support it. Poll it with retrieve, or stop it with cancel. Background responses are billed for the tokens they use, including a response you cancel.
With Inworld-managed credentials, background mode must be enabled for your workspace. Otherwise the request is refused with 400. Contact support to enable it. With your own provider key, this enablement isn't needed, but the model must still be able to run in the background.
Zero data retention
For a workspace with zero data retention, nothing is stored. store: true, background and previous_response_id are refused with 400 (code: "unsupported_parameter"), and so are the four {response_id} endpoints.
Errors
Errors use the router's format: {"error": {"message", "type", "code", "param"}}. When models were tried, the error body also has a top-level metadata object with attempts, as chat completions errors do. Errors carry no routing object; routing appears only on responses.
| Status | Common causes |
|---|---|
400 | Invalid JSON, missing model or input, an unsupported parameter, store/background/previous_response_id on a model that cannot store |
401 | Missing or invalid API key. The body is plain text (Unauthorized) |
402 | code: "insufficient_credits" |
404 | Unknown saved router, no model matches the request, or an unknown response id |
415 | Content-Type is not application/json |
429 | Rate limited. Retry after Retry-After |
503 | Every candidate model is unavailable, or the service is temporarily unavailable. Retry after Retry-After |
504 | The request ran out of time: one model attempt, or the whole request with its fallbacks, reached its limit (Time limits). Retry after Retry-After |
When every candidate model fails, the status is the last failure's, and the message lists each model's error.