Top.Mail.Ru
General icon
General
Галерея icon
Галерея
Unitool Labs icon
Unitool Labs
Блог icon
Блог
MCP icon
MCP

Responses API and Codex CLI

HTTP
POST https://api.unitool.ai/v1/responses

POST /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

curl
export OPENAI_BASE_URL=https://api.unitool.ai/v1
export OPENAI_API_KEY=ut_live_...
codex --model claude-sonnet-5-5

The 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

Python
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)
JavaScript
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

  • input is a string or a list of items: messages with roles user, system, developer, assistant (parts input_text, output_text, refusal, input_image, input_file), function_call, function_call_output, custom_tool_call, custom_tool_call_output, reasoning. instructions becomes a system message.
  • Images: input_image by link or data: URL. Files: input_file with file_data (base64 data: URL) or file_url (https). Uploaded file_id values are not supported.
  • max_output_tokens works like max_tokens in chat: omitted means the model's limit; a short balance lowers it with x-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_calls limits the request's web searches: 1 to 5, larger values are lowered to 5.

Tools

  • Your own function tools and free-form custom tools (Codex's apply_patch, for example: the call comes back as a custom_tool_call with plain text in input).
  • tool_choice: auto, none, required or {type: "function" | "custom", name}.
  • The only server-side tool is web_search (and web_search_preview and similar), see Web search. When the search reserve does not fit the balance or the key limit, the request runs without search and tools.web_search appears in x-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.

This page as Markdown

We use cookies

By continuing to use the site you agree to our Privacy Policy.