POST /v1/responses runs either a model (scope inference) or an agent (scope agents). Send exactly one of them.
Request
input (string or items), instructions, tools (function tools with a JSON Schema parameters), tool_choice, stream, store (default true), conversation, previous_response_id, metadata, max_output_tokens, temperature. conversation and previous_response_id cannot be combined.
- Model mode runs on the Allternit model router. Tool calls come back as
function_callitems for your code to run; send the result as afunction_call_outputitem withprevious_response_id. - Agent mode runs on the project’s hosted runtime with the agent’s own tools. A response chain is a conversation: it is created if absent, and
previous_response_idmust be the conversation’s latest response (409 previous_response_not_latest). Agent mode refusesstore: false, clienttoolsand mixed modes with400.
Response object
id (resp_), status (in_progress, completed, failed, incomplete, requires_action), model, agent_id, conversation_id, previous_response_id, output (items), incomplete_details ({"reason": "max_output_tokens"} when the model stopped at max_output_tokens, else null), required_actions (see below), usage, error, metadata, created_at, completed_at.
Items have object: "item" and a type: message, function_call, function_call_output, tool_call (a hosted tool) or approval_request. Every item also carries conversation_id, response_id and created_at. A tool_call item has name, input, output, status and error, plus call_id when the agent’s runtime gave the call an id. The same call_id is on that call’s response.tool_call.* stream events and on the conversation’s tool.* events (as tool_call_id), so you can match them.
When an agent’s action needs the owner’s approval, that tool call fails with a “try again once they approve” result and the turn ends. From then on, while the approval is pending, the stored response reads status: "requires_action" with one entry per pending approval, oldest first:
POST /v1/approvals/{id} (or watch the approval.resolved webhook), then send a new response with previous_response_id set to this one. Once no approval is pending, GET /v1/responses/{id} returns the stored status again (completed, failed or incomplete) and required_actions is []. The stream and the POST /v1/responses answer of the turn itself end completed: the approval is raised after the turn finishes, so read the response again (or follow approval.requested) to see it. A text or call from an agent with autonomy ask raises one of these approvals the first time it tries to send; see Agents. Approvals raised by a developer’s own POST /v1/computers/{id}/toolset call belong to no response and never show here.
Streaming
Withstream: true: response.created, response.output_item.added, response.output_text.delta, response.output_text.done, response.function_call_arguments.done, response.tool_call.started, response.tool_call.completed, response.tool_call.failed, response.output_item.done, response.completed, response.incomplete, response.failed, error. Skip event names you do not know.
Long turns and how a response ends
Send agent turns withstream: true. An agent turn can take minutes, for example when the project’s hosted computer has to wake up first. A non-streaming request sends nothing until the turn ends, and Cloudflare closes an idle request after 100 seconds with a 524 error. The stream sends response.created at once and keeps sending events while the agent works.
Every response ends completed, failed or incomplete. It never stays in_progress:
- If your client disconnects or times out, the turn still runs to its end and is stored. Read the result with
GET /v1/responses/{id}. If you never got the id, list the conversation’s items. - If the agent’s runtime does not finish within 10 minutes, the response ends
failedwitherror.code: "turn_timeout". The assistant reply is stored as a failed item, and the conversation takes new turns again. - If a turn is cut short on our side (for example by a restart during a deploy), the response is marked
failedwitherror.code: "turn_abandoned"within about 20 minutes. Send the request again.
Billing
The project pays for every response, in both modes. The project needs a card on file first, sandbox included; without one the request answers402 payment_method_required (see Billing). Model tokens are recorded as tokens_in and tokens_out usage rows and billed to the project at the model’s list price plus 15%, as in Pricing. They count toward the project’s monthly spend cap: at the cap a new response answers 402 spend_cap_reached. In model mode no member’s personal credits are used, whichever key or console session made the call. A streamed response is billed once, when it ends. A response that fails at the model is not billed.