function_call output with the tool name and arguments for you to execute.
Basic Tool Calling
Tool Call Response
When the model decides to call a tool, the response includes afunction_call output:
Multi-Turn Tool Calling
In a multi-turn conversation, you build up the full history — user messages, model outputs (includingfunction_call items), and tool results (function_call_output items) — and send it with each request. The Responses API is stateless, so every request must contain the complete conversation.
This example walks through a two-turn exchange where the model calls a tool in the first turn, receives the result, then calls a second tool in the second turn before giving a final answer.
Codex models (
gpt-5.3-codex, gpt-5.2-codex): These models always operate under Zero Data Retention (store: false), so include: ["reasoning.encrypted_content"] is always enabled — even if you do not provide it. Encrypted reasoning tokens are returned in every response and can be passed back in subsequent requests to maintain reasoning continuity without any server-side storage. See Zero Data Retention for details.Turn 1 — Initial request
Send the user’s message and tool definitions:Turn 1 — Execute the tool and send the result back
Append the model’sfunction_call output and your function_call_output to the history, then make the next request:
search_file), repeat the same pattern — append its function_call, execute it, append the function_call_output, and send again. When the model returns a message output with no further function calls, the conversation is complete.
Conversation history shape
After two tool calls, theinput array you send looks like this:
Always include every
function_call item from the model’s output array verbatim in the next request’s input. Omitting any item will cause the API to reject the conversation as malformed.Multi-Turn with User Messages
After returning a tool result, you can append a new user message in the same request to continue the conversation. This lets the user ask follow-up questions based on the tool’s output without starting over.Turn 1 — User asks a question
Turn 2 — Return tool result and add a follow-up user message
Append the model’sfunction_call, your function_call_output, and the new user message together in input:
The new user message goes after the
function_call_output, not before it. The API processes the input array in order and expects tool results to appear immediately after their corresponding function_call.Tool Choice Options
Control how the model uses tools with thetool_choice parameter:
| Value | Behavior |
|---|---|
"auto" | The model decides whether to call a tool |
"required" | The model must call at least one tool |
"none" | The model cannot call any tools |
Request Parameters
Array of tool definitions. Each tool object contains:
type: Always"function"name: The function name the model will usedescription: Describes when and how to use this toolparameters: JSON Schema object defining the function’s parameters
Controls tool usage. Set to
"auto" (default), "required", or "none". To force a specific tool, pass {"type": "function", "name": "tool_name"}.When
true, the model may call multiple tools simultaneously. Default: trueUse Case: Coding Agent
A coding agent gives the model a set of file system and terminal tools and runs an agentic loop — calling the API, executing whatever tools the model requests, and feeding the results back — until the model returns a plain text response with no further tool calls. Define seven SWE tools:Python
Python
The agent loop continues until the model returns a response with no
function_call outputs. Always set a max_iterations guard to prevent runaway loops."Read main.py and tell me what the entry point function does.""Write a file /tmp/utils.py with a helper function for parsing JSON, then read it back to confirm.""Search app.py for all lines containing 'TODO' and list their line numbers.""Edit config.py: replace DEBUG = False with DEBUG = True, then verify the change.""Run python3 tests/test_api.py and report any failures.""List the project root and find all TypeScript files under src/."
Tool Calling with Encrypted Reasoning (ZDR)
Codex models (gpt-5.3-codex, gpt-5.2-codex) always operate under Zero Data Retention — store is enforced to false and no data is persisted between requests. To support stateless multi-turn tool calling, include: ["reasoning.encrypted_content"] is always enabled for these models, even if you do not provide it.
This means every response includes reasoning output items with an encrypted_content field. When building multi-turn conversations, pass these reasoning items back verbatim in the next request’s input array. The encrypted content is decrypted in-memory for generating the next response and then securely discarded — no intermediate state is ever persisted.