Responses
Call Responses and distinguish raw output, SDK helpers, and stateful features.
Request and prerequisites
Responses is the protocol used by clients such as Codex CLI. Confirm model and line support, set the key from the API overview, and run this Bash example.
curl --fail-with-body 'https://gateway.irouter.io/v1/responses' \
-H "Authorization: Bearer $IROUTER_API_KEY" \
-H 'Content-Type: application/json' \
--data '{"model":"<model-id>","input":"Reply with a short greeting.","stream":false}'model selects the model and input provides its input. For role-based history, use supported message items. Validate optional instructions, tools, and output formats individually.
Read output
The raw output array can contain different item types. Extract output_text blocks from the content of message items instead of assuming its initial item is the answer. SDK response.output_text is a convenience property, not a guaranteed top-level field in raw HTTP JSON.
Check status, errors, and incomplete information before presenting the result. Empty text can also indicate a tool request or another output type.
Streaming and conversation state
With stream: true, handle Responses event types, including text deltas and completion events. They differ from Chat Completions chunks. See streaming.
Basic text compatibility does not establish support for previous_response_id, stored retrieval, background jobs, built-in tools, or WebSockets. Applications can maintain and submit history themselves. Validate stateful features against the intended line before depending on them.
Continue with Codex CLI. Protocol reference: OpenAI Responses.