Skip to main content
POST
/
api
/
v1
/
responses
Create Codex Response
curl --request POST \
  --url https://api.kie.ai/api/v1/responses \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "gpt-5.1-codex",
  "input": [
    {
      "role": "user",
      "content": [
        {
          "type": "input_text",
          "text": "What is in this image?"
        },
        {
          "type": "input_image",
          "image_url": "https://file.aiquickdraw.com/custom-page/akr/section-images/1759055072437dqlsclj2.png"
        }
      ]
    }
  ],
  "tools": [
    {
      "type": "web_search"
    }
  ],
  "reasoning": {
    "effort": "high"
  }
}
'
event: response.output_text.delta
data: {"content_index":0,"delta":"Hello","item_id":"msg_xxx","output_index":1,"sequence_number":1,"type":"response.output_text.delta"}

event: response.output_text.delta
data: {"content_index":0,"delta":"!","item_id":"msg_xxx","output_index":1,"sequence_number":2,"type":"response.output_text.delta"}

event: response.output_text.delta
data: {"content_index":0,"delta":" How","item_id":"msg_xxx","output_index":1,"sequence_number":3,"type":"response.output_text.delta"}

event: response.output_text.delta
data: {"content_index":0,"delta":" can","item_id":"msg_xxx","output_index":1,"sequence_number":4,"type":"response.output_text.delta"}

event: response.output_text.delta
data: {"content_index":0,"delta":" I help you today?","item_id":"msg_xxx","output_index":1,"sequence_number":5,"type":"response.output_text.delta"}

event: response.completed
data: {"credits_consumed":0.49,"response":{"usage":{"input_tokens":4427,"input_tokens_details":{"cached_tokens":3584},"output_tokens":137,"output_tokens_details":{"reasoning_tokens":64},"total_tokens":4564}},"type":"response.completed"}

data: [DONE]

Multimodal Input

Supports mixed text, image, and file inputs in a single message.

Reasoning Control

Adjustable reasoning effort from minimal to xhigh.

Tools & Web Search

Integrates web search or custom function calling tools.

Unified Endpoint

Uses the unified /api/v1/responses endpoint with model set to one of gpt-5-codex, gpt-5.1-codex, gpt-5.2-codex, or gpt-5.3-codex.

Tools & tool_choice

The tools array enables web search or function calling capabilities.
Web Search and Function Calling are mutually exclusive.
In a single request you should choose only one: do not include both {"type": "web_search"} and {"type": "function", ...} in the same tools array.
Define business functions that the model can call when needed:
{
  "tools": [
    {
      "type": "function",
      "name": "get_current_weather",
      "description": "Get the current weather in a given location",
      "parameters": {
        "type": "object",
        "properties": {
          "location": {
            "type": "string",
            "description": "The city and state, e.g. San Francisco, CA"
          },
          "unit": {
            "type": "string",
            "enum": ["celsius", "fahrenheit"]
          }
        },
        "required": ["location", "unit"]
      }
    }
  ],
  "tool_choice": "auto"
}
When function tools are configured in tools, set tool_choice to "auto" so the model can decide when to call them.
If you do not configure any function tools, omit the tool_choice field.
event: response.output_text.delta
data: {"content_index":0,"delta":"Hello","item_id":"msg_xxx","output_index":1,"sequence_number":1,"type":"response.output_text.delta"}

event: response.output_text.delta
data: {"content_index":0,"delta":"!","item_id":"msg_xxx","output_index":1,"sequence_number":2,"type":"response.output_text.delta"}

event: response.output_text.delta
data: {"content_index":0,"delta":" How","item_id":"msg_xxx","output_index":1,"sequence_number":3,"type":"response.output_text.delta"}

event: response.output_text.delta
data: {"content_index":0,"delta":" can","item_id":"msg_xxx","output_index":1,"sequence_number":4,"type":"response.output_text.delta"}

event: response.output_text.delta
data: {"content_index":0,"delta":" I help you today?","item_id":"msg_xxx","output_index":1,"sequence_number":5,"type":"response.output_text.delta"}

event: response.completed
data: {"credits_consumed":0.49,"response":{"usage":{"input_tokens":4427,"input_tokens_details":{"cached_tokens":3584},"output_tokens":137,"output_tokens_details":{"reasoning_tokens":64},"total_tokens":4564}},"type":"response.completed"}

data: [DONE]

Authorizations

Authorization
string
header
required

All APIs require authentication via Bearer Token.

Get API Key:

  1. Visit API Key Management Page to get your API Key

Usage: Add to request header: Authorization: Bearer YOUR_API_KEY

Note:

  • Keep your API Key secure and do not share it with others
  • If you suspect your API Key has been compromised, reset it immediately in the management page

Body

application/json
model
enum<string>
required

Target model name. Allowed values: gpt-5-codex, gpt-5.1-codex, gpt-5.2-codex, gpt-5.3-codex.

Available options:
gpt-5-codex,
gpt-5.1-codex,
gpt-5.2-codex,
gpt-5.3-codex
Example:

"gpt-5.1-codex"

input
required

Input can be a string.

reasoning
object

Reasoning configuration for the model.

tools
object[]

Optional tools that the model may call. Either web search OR function calling should be configured, but not both simultaneously.

Web search tool configuration.

tool_choice
string

Tool selection behavior. When function tools are configured in tools, set this to auto so the model can decide when to call them.

Example:

"auto"

Response

Request successful. Responses are only available as streaming Server-Sent Events (SSE).

Streaming responses are sent as Server-Sent Events (SSE) with Content-Type: text/event-stream.

Standard output

  • Text delta event: event: response.output_text.delta
    • data.delta: The incremental text content in the stream
    • data.type: Event type, always response.output_text.delta
  • Completion event: event: response.completed
    • data.response.usage: Token usage information, such as input_tokens and output_tokens

Function Calling

  • Function call arguments delta event: event: response.function_call_arguments.delta
    • data.delta: Incremental string content of the function call arguments
    • data.type: Event type, always response.function_call_arguments.delta
  • Completion event: event: response.completed
    • data.response.usage: Token usage information, such as input_tokens and output_tokens

The final line data: [DONE] is the stream end marker, indicating that no more events will be sent.