Responses API and Codex CLI
POST https://api.unitool.ai/v1/responsesPOST /v1/responses is OpenAI's Responses API without server-side state. It works with Codex CLI and the OpenAI SDKs. The key needs the inference scope. Any text model from GET /v1/models works.
Codex CLI
export OPENAI_BASE_URL=https://api.unitool.ai/v1
export OPENAI_API_KEY=ut_live_...
codex --model claude-sonnet-5-5The model is any text model id from the catalog. Codex talks to us over HTTP. When web search is on, Codex sends the web_search tool on every turn and each request reserves 5 searches on top of the usual hold. With a small balance, turn web search off in Codex.
OpenAI SDK
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.unitool.ai/v1", api_key=os.environ["UNITOOL_API_KEY"])
response = client.responses.create(model="claude-sonnet-5-5", input="Hi!", max_output_tokens=1024)
print(response.output_text, response.usage)
with client.responses.stream(model="claude-sonnet-5-5", input="Write a haiku about APIs") as stream:
for event in stream:
if event.type == "response.output_text.delta":
print(event.delta, end="", flush=True)import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.unitool.ai/v1", apiKey: process.env.UNITOOL_API_KEY });
const response = await client.responses.create({ model: "claude-sonnet-5-5", input: "Hi!", max_output_tokens: 1024 });
console.log(response.output_text, response.usage);Nothing is stored
Send the whole conversation in input on every call: the items of earlier answers (reasoning, message, function_call, custom_tool_call) exactly as you received them, then your tool results. store is ignored (the answer says store: false). previous_response_id, conversation, background and stored prompts (prompt, item_reference) are refused with 400 unsupported_parameter.
Keep reasoning items in the conversation as they are: encrypted_content carries the model's reasoning state (for Claude models, the signed thinking a tool-use turn requires). It is always included; you do not need include.
Input
inputis a string or a list of items: messages with rolesuser,system,developer,assistant(partsinput_text,output_text,refusal,input_image,input_file),function_call,function_call_output,custom_tool_call,custom_tool_call_output,reasoning.instructionsbecomes a system message.- Images:
input_imageby link ordata:URL. Files:input_filewithfile_data(base64data:URL) orfile_url(https). Uploadedfile_idvalues are not supported. max_output_tokensworks likemax_tokensin chat: omitted means the model's limit; a short balance lowers it withx-unitool-output-capped, see Billing.temperature,top_p(dropped for models that take neither),reasoning.effort(a level the model has, else 400),text.format(text,json_object,json_schema),prompt_cache_key.max_tool_callslimits the request's web searches: 1 to 5, larger values are lowered to 5.
Tools
- Your own
functiontools and free-formcustomtools (Codex'sapply_patch, for example: the call comes back as acustom_tool_callwith plain text ininput). tool_choice:auto,none,requiredor{type: "function" | "custom", name}.- The only server-side tool is
web_search(andweb_search_previewand similar), see Web search. When the search reserve does not fit the balance or the key limit, the request runs without search andtools.web_searchappears inx-unitool-ignored-params. With search switched off, the tool is dropped with the same header. - Other tool types:
400 unsupported_parameter.
Accepted but unused parameters (text.verbosity, parallel_tool_calls, reasoning.summary, unknown fields) are listed in the x-unitool-ignored-params header.
Streaming
Events as with OpenAI: response.created, response.in_progress, response.output_item.added / done, response.content_part.added / done, response.output_text.delta / done, response.refusal.delta / done, response.function_call_arguments.delta / done, response.custom_tool_call_input.delta / done, response.reasoning_summary_part.added / done, response.reasoning_summary_text.delta / done, then response.completed or response.incomplete. sequence_number starts at 0 with no gaps. The SDK's responses.stream() rebuilds the response from these events. The reasoning item is finished at the end of the answer: the reasoning signature may arrive after the text and the tool calls.
A response cut by max_output_tokens has status: "incomplete".
Usage and errors
usage: input_tokens, input_tokens_details.cached_tokens (and cache_write_5m_tokens, cache_write_1h_tokens), output_tokens, output_tokens_details.reasoning_tokens, total_tokens, plus our cost_tokens (what the request cost in balance tokens), estimated and server_tool_use.
An error before the stream is a regular HTTP answer in the error format. If the model fails after the stream started, the last event is response.failed with response.error {code, message}. A stream that already produced output is charged for that output: response.usage has the usual counts and cost_tokens. If nothing was produced, nothing is charged and usage is absent.