Responses API

OpenAI Responses API format, supporting function calling, built-in tools, and server-side multi-turn context management

POST/v1/responses

The Responses API is OpenAI's next-generation Agentic interface, providing more powerful capabilities than Chat Completions:

  • Function Calling: The model can call custom functions
  • Built-in tools: Ready-to-use tools such as web_search_preview (web search)
  • Server-side multi-turn context: Automatically maintains conversation history through previous_response_id, without requiring the client to send the complete message history
  • Reasoning effort control: Precisely adjusts reasoning depth through reasoning.effort

Note: Models marked Responses Only (such as gpt-5-pro-official and gpt-5.3-codex-official) support only this API and do not support Chat Completions. See the Model Overview for the complete model list.

Authorizations

AuthorizationstringRequired

Authenticated using a Bearer Token

Authorization: Bearer YOUR_API_KEY

Get an API Key: visit the API Key Management page

Body

modelstringRequired

Model name

Examples: "gpt-5-pro-official", "gpt-5.3-codex-official", "gpt-5.2-official"

inputstring | object[]Required

User input, supporting two formats:

  • String: Simple text input
  • Message array: Multi-turn conversation format
Show Message array formatHide Message array format
rolestringRequired

Message role: user, assistant, developer

contentstring | object[]Required

Message content, supporting plain text or an array of content blocks containing images

instructionsstring

System instructions that guide model behavior (equivalent to the system message in Chat Completions)

streambooleanDefault false

Whether to enable streaming output

max_output_tokensinteger

Maximum number of tokens to generate

temperaturenumberDefault 1

Sampling temperature, ranging from 0 to 2

top_pnumberDefault 1

Nucleus sampling probability threshold, ranging from 0 to 1

previous_response_idstring

ID of the previous response, used for automatically concatenating multi-turn context on the server without requiring the client to send the complete message history

reasoningobject

Reasoning configuration

Show reasoningHide reasoning
effortstring

Reasoning effort: high, medium, low, none

Higher values enable deeper reasoning and consume more reasoning tokens

toolsobject[]

List of available tools

Show tools[n]Hide tools[n]
typestringRequired

Tool type: function (custom function), web_search_preview (web search)

namestring

Function name (required when type is function)

descriptionstring

Function description

parametersobject

JSON Schema for function parameters

tool_choicestringDefault auto

Tool selection strategy: auto, none, required

Response

idstring

Unique response identifier (can be used as previous_response_id)

objectstring

Always response

statusstring

Response status: completed, failed, in_progress

outputobject[]

List of output items, which may include multiple types:

  • message: Text response containing content[].text
  • function_call: Function call request containing name and arguments
  • reasoning: Reasoning process (appears when reasoning.effort is not none)
  • web_search_call: Web search call record
usageobject

token usage statistics

  • usage.input_tokens: Number of input tokens
  • usage.output_tokens: Number of output tokens
  • usage.output_tokens_details.reasoning_tokens: Number of reasoning tokens
  • usage.total_tokens: Total number of tokens

Request Examples

curl --request POST \  --url https://api.maitoken.net/v1/responses \  --header 'Authorization: Bearer <token>' \  --header 'Content-Type: application/json' \  --data '{    "model": "gpt-5.3-codex-official",    "instructions": "You are a professional coding assistant",    "input": "Write a quicksort implementation in Python"  }'
curl --request POST \  --url https://api.maitoken.net/v1/responses \  --header 'Authorization: Bearer <token>' \  --header 'Content-Type: application/json' \  --data '{    "model": "gpt-5.3-codex-official",    "input": "What are the most popular AI frameworks in 2026?",    "tools": [{"type": "web_search_preview"}]  }'
curl --request POST \  --url https://api.maitoken.net/v1/responses \  --header 'Authorization: Bearer <token>' \  --header 'Content-Type: application/json' \  --data '{    "model": "gpt-5-pro-official",    "instructions": "You are a weather assistant",    "input": "What is the weather like in Beijing today?",    "tools": [      {        "type": "function",        "name": "get_weather",        "description": "Get the weather for a specified city",        "parameters": {          "type": "object",          "properties": {            "location": {"type": "string", "description": "City name"}          },          "required": ["location"]        }      }    ]  }'
curl --request POST \  --url https://api.maitoken.net/v1/responses \  --header 'Authorization: Bearer <token>' \  --header 'Content-Type: application/json' \  --data '{    "model": "gpt-5.3-codex-official",    "previous_response_id": "resp_abc123",    "input": [      {"role": "user", "content": "Now add error handling to this function"}    ]  }'
from openai import OpenAI client = OpenAI(    api_key="your-MaiToken-key",    base_url="https://api.maitoken.net/v1") response = client.responses.create(    model="gpt-5.3-codex-official",    instructions="You are a professional coding assistant",    input="Write a quicksort implementation in Python") print(response.output[0].content[0].text)
from openai import OpenAI client = OpenAI(    api_key="your-MaiToken-key",    base_url="https://api.maitoken.net/v1") response1 = client.responses.create(    model="gpt-5.3-codex-official",    instructions="You are a professional coding assistant",    input="Write a Fibonacci function") response2 = client.responses.create(    model="gpt-5.3-codex-official",    previous_response_id=response1.id,    input=[{"role": "user", "content": "Add input validation"}]) print(response2.output[0].content[0].text)
import OpenAI from "openai"; const client = new OpenAI({  apiKey: "your-MaiToken-key",  baseURL: "https://api.maitoken.net/v1",}); const response = await client.responses.create({  model: "gpt-5.3-codex-official",  instructions: "You are a professional coding assistant",  input: "Write a quicksort implementation in Python",}); console.log(response.output[0].content[0].text);

Response Examples

{  "id": "resp_abc123",  "object": "response",  "status": "completed",  "model": "gpt-5.3-codex-official",  "output": [    {      "type": "message",      "role": "assistant",      "content": [        {          "type": "output_text",          "text": "```python\ndef quicksort(arr):\n    if len(arr) <= 1:\n        return arr\n    pivot = arr[len(arr) // 2]\n    left = [x for x in arr if x < pivot]\n    middle = [x for x in arr if x == pivot]\n    right = [x for x in arr if x > pivot]\n    return quicksort(left) + middle + quicksort(right)\n```"        }      ]    }  ],  "usage": {    "input_tokens": 25,    "output_tokens": 80,    "total_tokens": 105  }}
{  "id": "resp_def456",  "object": "response",  "status": "completed",  "model": "gpt-5-pro-official",  "output": [    {      "type": "function_call",      "name": "get_weather",      "arguments": "{\"location\":\"Beijing\"}",      "call_id": "call_abc123"    }  ],  "usage": {    "input_tokens": 85,    "output_tokens": 24,    "total_tokens": 109  }}
{  "error": {    "code": "invalid_request_error",    "message": "The 'input' field is required.",    "type": "invalid_request_error"  }}

Background Tasks

Requests submitted with background: true immediately return a response object with a status of queued / in_progress. You can then poll or cancel the request (you must use the same API Key used for submission; the query window is 7 days):

GET  /v1/responses/{response_id}POST /v1/responses/{response_id}/cancel