> ## Documentation Index
> Fetch the complete documentation index at: https://old-docs.kie.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# GPT Codex

> GPT Codex API is a multimodal chat-completions style endpoint that accepts structured input arrays, supports adjustable reasoning effort, and integrates web search or function calling tools.

<CardGroup cols={2}>
  <Card title="Multimodal Input" icon="image">
    Supports mixed text, image, and file inputs in a single message.
  </Card>

  <Card title="Reasoning Control" icon="brain">
    Adjustable reasoning effort from minimal to xhigh.
  </Card>

  <Card title="Tools & Web Search" icon="wand-magic-sparkles">
    Integrates web search or custom function calling tools.
  </Card>

  <Card title="Unified Endpoint" icon="code">
    Uses the unified <code>/api/v1/responses</code> endpoint with <code>model</code> set to one of <code>gpt-5-codex</code>, <code>gpt-5.1-codex</code>, <code>gpt-5.2-codex</code>, or <code>gpt-5.3-codex</code>.
  </Card>
</CardGroup>

## Tools & tool\_choice

The `tools` array enables **web search** or **function calling** capabilities.

<Warning>
  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.
</Warning>

<AccordionGroup>
  <Accordion title="Web Search">
    Use the built-in Web Search tool to retrieve up-to-date information:

    ```json theme={null}
    {
      "tools": [
        {
          "type": "web_search"
        }
      ]
    }
    ```
  </Accordion>

  <Accordion title="Function Calling">
    Define business functions that the model can call when needed:

    ```json theme={null}
    {
      "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.
  </Accordion>
</AccordionGroup>

<ResponseExample>
  ```text Streaming Events theme={null}
  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]
  ```
</ResponseExample>


## OpenAPI

````yaml market/codex/gpt-codex.json post /api/v1/responses
openapi: 3.0.0
info:
  title: GPT-5 Codex API
  description: kie.ai GPT-5 Codex API Documentation - Responses Endpoint
  version: 1.0.0
  contact:
    name: Technical Support
    email: support@kie.ai
servers:
  - url: https://api.kie.ai
    description: API Server
security:
  - BearerAuth: []
paths:
  /api/v1/responses:
    post:
      summary: Create Codex Response
      description: >-
        Create a multimodal response using GPT-5 Codex series models via the
        unified responses endpoint. Supports structured input arrays, adjustable
        reasoning effort, and optional tools for web search or function calling.


        ### Features

        - **Multimodal input**: Combine text, images, and files in a single
        message

        - **Unified endpoint**: Use `/api/v1/responses` and set `model` to one
        of `gpt-5-codex`, `gpt-5.1-codex`, `gpt-5.2-codex`, or `gpt-5.3-codex`

        - **Reasoning control**: Adjust reasoning effort from minimal to xhigh

        - **Tools support**: Choose between web search and function calling
        tools

        - **Streaming**: Supports server-sent events for incremental output (see
        documentation examples)
      operationId: gpt-codex-responses
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                model:
                  type: string
                  enum:
                    - gpt-5-codex
                    - gpt-5.1-codex
                    - gpt-5.2-codex
                    - gpt-5.3-codex
                  description: >-
                    Target model name. Allowed values: `gpt-5-codex`,
                    `gpt-5.1-codex`, `gpt-5.2-codex`, `gpt-5.3-codex`.
                  example: gpt-5.1-codex
                input:
                  oneOf:
                    - type: string
                      description: Input can be a string.
                    - type: array
                      description: >-
                        Input can be an array; each element is a message object
                        with role and content.
                      items:
                        $ref: '#/components/schemas/InputMessage'
                      minItems: 1
                reasoning:
                  type: object
                  description: Reasoning configuration for the model.
                  properties:
                    effort:
                      type: string
                      description: >-
                        Reasoning effort level. Higher values provide more
                        thorough reasoning but may increase latency. Defaults to
                        "low".
                      enum:
                        - minimal
                        - low
                        - medium
                        - high
                        - xhigh
                      default: low
                      example: low
                tools:
                  type: array
                  description: >-
                    Optional tools that the model may call. Either web search OR
                    function calling should be configured, but not both
                    simultaneously.
                  items:
                    oneOf:
                      - $ref: '#/components/schemas/ToolWebSearch'
                      - $ref: '#/components/schemas/ToolFunction'
                tool_choice:
                  type: string
                  description: >-
                    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
              required:
                - model
                - input
              example:
                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
      responses:
        '200':
          description: >-
            Request successful. Responses are only available as streaming
            Server-Sent Events (SSE).
          content:
            text/event-stream:
              schema:
                type: string
                description: >-
                  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.
        '400':
          description: Bad Request - Invalid request parameters
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      message:
                        type: string
                        example: Invalid request parameters
                      type:
                        type: string
                        example: invalid_request_error
        '401':
          description: Unauthorized - Invalid or missing API key
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      message:
                        type: string
                        example: Unauthorized
                      type:
                        type: string
                        example: authentication_error
        '429':
          description: Rate Limited - Too many requests
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      message:
                        type: string
                        example: Rate limit exceeded
                      type:
                        type: string
                        example: rate_limit_error
        '500':
          $ref: '#/components/responses/Error'
components:
  schemas:
    InputMessage:
      type: object
      description: Single message in the input array.
      properties:
        role:
          type: string
          description: Message role.
          enum:
            - user
            - assistant
            - system
            - developer
            - tool
          example: user
        content:
          type: array
          description: Array of content items supporting text, image, and file inputs.
          items:
            $ref: '#/components/schemas/InputContentItem'
          minItems: 1
      required:
        - role
        - content
    ToolWebSearch:
      type: object
      description: Web search tool configuration.
      properties:
        type:
          type: string
          enum:
            - web_search
          example: web_search
      required:
        - type
    ToolFunction:
      type: object
      description: Function calling tool definition.
      properties:
        type:
          type: string
          enum:
            - function
          example: function
        name:
          type: string
          description: Function name.
          example: get_current_weather
        description:
          type: string
          description: Human-readable description of what this function does.
        parameters:
          type: object
          description: JSON Schema describing the function parameters.
      required:
        - type
        - name
        - description
        - parameters
    InputContentItem:
      type: object
      description: Single content item inside the input message content array.
      oneOf:
        - type: object
          properties:
            type:
              type: string
              enum:
                - input_text
              example: input_text
            text:
              type: string
              description: Plain text content.
          required:
            - type
            - text
        - type: object
          properties:
            type:
              type: string
              enum:
                - input_image
              example: input_image
            image_url:
              type: string
              format: uri
              description: Publicly accessible image URL.
          required:
            - type
            - image_url
        - type: object
          properties:
            type:
              type: string
              enum:
                - input_file
              example: input_file
            file_url:
              type: string
              format: uri
              description: Publicly accessible file URL (PDF, DOC, etc.).
          required:
            - type
            - file_url
  responses:
    Error:
      description: Server Error
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: >-
        All APIs require authentication via Bearer Token.


        Get API Key:

        1. Visit [API Key Management Page](https://kie.ai/api-key) 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

````