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

# Create chat completion

> Generate text, vision, tool-calling, and streaming responses in OpenAI-compatible format

## Models you can use

Pass any chat-capable model ID in `model`, for example:

| Model ID                 | Notes                                                         |
| ------------------------ | ------------------------------------------------------------- |
| `gpt-5.4`                | GPT-5 flagship — top reasoning / coding / agentic, 1M context |
| `gpt-5.4-mini`           | Lightweight, balanced — great for high-volume and fallback    |
| `gemini-3.1-pro-preview` | Gemini flagship — strong multimodal, 1M context               |
| `deepseek-v4-pro`        | DeepSeek cost-effective reasoning model                       |

See [`GET /v1/models`](/api-reference/models/list-models) or the
[pricing page](https://api.getinfinityblue.com/pricing) for the full list.

## Streaming

Set `stream: true` to receive Server-Sent Events (SSE). Each line is
`data: {json}` and the stream ends with `data: [DONE]`:

```
data: {"id":"chatcmpl-...","choices":[{"delta":{"content":"He"}}]}
data: {"id":"chatcmpl-...","choices":[{"delta":{"content":"llo"}}]}
data: [DONE]
```

## Reasoning models

For reasoning-capable models, use `reasoning_effort` (`low` /
`medium` / `high`) to control reasoning depth. The model returns its
reasoning in the `reasoning_content` field — render it collapsed in
your UI.

## Tool calling

Define functions as JSON Schema in `tools`. The model returns
structured `tool_calls` that your application executes and feeds back
in a follow-up request. Use `tool_choice` to control the strategy
(`auto` / `none` / `required`, or a specific function).


## OpenAPI

````yaml /openapi/chat.en.yaml post /v1/chat/completions
openapi: 3.1.0
info:
  title: InfinityBlue API — Chat
  version: 1.0.0
  summary: Unified AI model API gateway — Chat endpoints
  description: >
    InfinityBlue is a unified API gateway for AI models. It exposes

    **OpenAI-, Google Gemini-, and Anthropic Claude-compatible** endpoints,

    backed by models from OpenAI, Google, DeepSeek, ByteDance (Seedance),

    Kuaishou (Kling), and more.


    You don't need to integrate each vendor separately — just point your

    base URL at InfinityBlue and keep using the official SDK you already know.


    ## Authentication


    Every request must include your API key in the header:


    ```

    Authorization: Bearer YOUR_API_KEY

    ```


    Create and manage your API keys in the
    [console](https://api.getinfinityblue.com/console).


    ## Endpoint format conventions


    | Path prefix | Compatible format |

    | --- | --- |

    | `/v1/*` | OpenAI (Chat Completions, Responses, Images, etc.) |

    | `/v1/messages` | Anthropic Claude Messages |

    | `/v1beta/models/*` | Google Gemini native |


    ## Model selection


    Pass any model ID in the `model` parameter. See

    [`GET /v1/models`](/api-reference/models/list-models)

    or the [pricing page](https://api.getinfinityblue.com/pricing)

    for the full list.
  contact:
    name: InfinityBlue
    url: https://getinfinityblue.com
servers:
  - url: https://api.getinfinityblue.com
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Chat
    description: |
      Text conversations, vision, tool calling, streaming, and reasoning
      models — all through a single chat endpoint.
paths:
  /v1/chat/completions:
    post:
      tags:
        - Chat
      summary: Create chat completion
      description: |
        Create a model response for the given conversation. Supports both
        streaming and non-streaming responses. Fully compatible with the
        OpenAI Chat Completions API — just point your SDK's base URL at
        InfinityBlue.
      operationId: createChatCompletion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
            examples:
              simple:
                summary: Basic text chat
                value:
                  model: gpt-5.4
                  messages:
                    - role: user
                      content: Introduce yourself in one sentence.
              streaming:
                summary: Streaming response
                value:
                  model: gpt-5.4
                  stream: true
                  messages:
                    - role: user
                      content: Write a haiku about programming.
              vision:
                summary: Vision (multimodal input)
                value:
                  model: gpt-5.4
                  messages:
                    - role: user
                      content:
                        - type: text
                          text: What's in this image?
                        - type: image_url
                          image_url:
                            url: https://example.com/cat.jpg
              tool_calling:
                summary: Tool calling (function calling)
                value:
                  model: gpt-5.4
                  messages:
                    - role: user
                      content: What's the weather in Beijing?
                  tools:
                    - type: function
                      function:
                        name: get_weather
                        description: Get the current weather for a city
                        parameters:
                          type: object
                          properties:
                            city:
                              type: string
                              description: City name
                          required:
                            - city
                  tool_choice: auto
              json_schema:
                summary: Structured output (JSON Schema)
                value:
                  model: gpt-5.4
                  messages:
                    - role: system
                      content: Extract the city and country from the user's message.
                    - role: user
                      content: I just moved to Paris, France.
                  response_format:
                    type: json_schema
                    json_schema:
                      name: location
                      schema:
                        type: object
                        properties:
                          city:
                            type: string
                          country:
                            type: string
                        required:
                          - city
                          - country
                        additionalProperties: false
              reasoning:
                summary: Reasoning model
                value:
                  model: deepseek-v4-pro
                  reasoning_effort: high
                  messages:
                    - role: user
                      content: >-
                        A farmer must ferry a wolf, a goat, and a cabbage across
                        a river. The boat holds only one at a time. How?
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
            text/event-stream:
              schema:
                type: string
                description: |
                  Server-Sent Events stream when `stream=true`. Each line is
                  `data: {json}`; the stream ends with `data: [DONE]`.
        '400':
          description: Invalid request parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Invalid or missing API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    ChatCompletionRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          description: Model ID, e.g. `gpt-5.4`. See `GET /v1/models` for the full list.
          examples:
            - gpt-5.4
        messages:
          type: array
          description: The messages comprising the conversation so far, in order.
          items:
            $ref: '#/components/schemas/Message'
        temperature:
          type: number
          minimum: 0
          maximum: 2
          default: 1
          description: |
            Sampling temperature between 0 and 2. Higher values (e.g. 0.8)
            make output more random; lower values (e.g. 0.2) make it more
            focused and deterministic. Tune this or `top_p`, not both.
        top_p:
          type: number
          minimum: 0
          maximum: 1
          default: 1
          description: |
            Nucleus sampling. The model considers only tokens within the top
            `top_p` cumulative probability mass — e.g. 0.1 means only the top
            10%. Tune this or `temperature`, not both.
        'n':
          type: integer
          minimum: 1
          default: 1
          description: Number of completions to generate for each input message.
        stream:
          type: boolean
          default: false
          description: Whether to stream the response as Server-Sent Events.
        stream_options:
          type: object
          description: Options for streaming, only used when `stream=true`.
          properties:
            include_usage:
              type: boolean
              description: Whether to include `usage` stats in the final chunk.
        stop:
          description: Up to 4 stop sequences. Generation stops at any of them.
          oneOf:
            - type: string
            - type: array
              items:
                type: string
        max_tokens:
          type: integer
          description: |
            Maximum tokens to generate in the completion (legacy). Use
            `max_completion_tokens` for reasoning models.
        max_completion_tokens:
          type: integer
          description: Maximum tokens to generate, including reasoning tokens.
        presence_penalty:
          type: number
          minimum: -2
          maximum: 2
          default: 0
          description: |
            Between -2.0 and 2.0. Positive values penalize tokens that have
            already appeared, increasing the model's likelihood to talk about
            new topics.
        frequency_penalty:
          type: number
          minimum: -2
          maximum: 2
          default: 0
          description: |
            Between -2.0 and 2.0. Positive values penalize tokens based on their
            existing frequency, decreasing verbatim repetition.
        logit_bias:
          type: object
          additionalProperties:
            type: number
          description: >-
            Bias map adjusting token likelihoods; keys are token IDs, values
            -100 to 100.
        user:
          type: string
          description: A unique identifier for your end user, useful for abuse monitoring.
        tools:
          type: array
          description: >-
            A list of tools the model may call. Currently only `function` is
            supported.
          items:
            $ref: '#/components/schemas/Tool'
        tool_choice:
          description: |
            Controls whether and how the model calls tools. `none` disables
            calls, `auto` lets the model decide, `required` forces at least one
            call; or pass an object to force a specific function.
          oneOf:
            - type: string
              enum:
                - none
                - auto
                - required
            - type: object
              properties:
                type:
                  type: string
                function:
                  type: object
                  properties:
                    name:
                      type: string
        response_format:
          $ref: '#/components/schemas/ResponseFormat'
        seed:
          type: integer
          description: >-
            Random seed. The same seed and params return results as consistent
            as possible.
        reasoning_effort:
          type: string
          enum:
            - low
            - medium
            - high
          description: Reasoning depth, only effective for reasoning-capable models.
        modalities:
          type: array
          description: The output modalities you want the model to return.
          items:
            type: string
            enum:
              - text
              - audio
        audio:
          type: object
          description: Audio output parameters, used when `modalities` includes `audio`.
          properties:
            voice:
              type: string
              description: Voice.
            format:
              type: string
              description: Audio format.
    ChatCompletionResponse:
      type: object
      properties:
        id:
          type: string
          description: Unique identifier for this completion.
        object:
          type: string
          examples:
            - chat.completion
        created:
          type: integer
          description: Unix timestamp (seconds) of creation.
        model:
          type: string
          description: The model that actually processed the request.
        choices:
          type: array
          description: The list of completions generated by the model.
          items:
            type: object
            properties:
              index:
                type: integer
              message:
                $ref: '#/components/schemas/Message'
              finish_reason:
                type: string
                enum:
                  - stop
                  - length
                  - tool_calls
                  - content_filter
                description: The reason generation stopped.
        usage:
          $ref: '#/components/schemas/Usage'
        system_fingerprint:
          type: string
    ErrorResponse:
      type: object
      description: Standard error response.
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              description: Error message.
              examples:
                - Invalid duration. Supported range is 4 to 15 seconds.
            type:
              type: string
              description: Error type.
              examples:
                - invalid_request_error
            param:
              type:
                - string
                - 'null'
              description: The parameter related to the error.
              examples:
                - seconds
            code:
              type:
                - string
                - 'null'
              description: Error code.
              examples:
                - invalid_duration
    Message:
      type: object
      required:
        - role
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - tool
            - developer
          description: The role of the message author.
        content:
          description: >-
            Message content — either a plain text string or an array of
            multimodal parts.
          oneOf:
            - type: string
            - type: array
              items:
                $ref: '#/components/schemas/MessageContent'
        name:
          type: string
          description: Author name, to distinguish participants of the same role.
        tool_calls:
          type: array
          description: Tool calls initiated by an assistant message.
          items:
            $ref: '#/components/schemas/ToolCall'
        tool_call_id:
          type: string
          description: The tool call ID this `tool`-role message responds to.
        reasoning_content:
          type: string
          description: The reasoning trace returned by reasoning models.
    Tool:
      type: object
      description: A tool definition the model may call.
      properties:
        type:
          type: string
          description: Tool type, currently `function`.
          examples:
            - function
        function:
          type: object
          properties:
            name:
              type: string
              description: Function name.
            description:
              type: string
              description: >-
                What the function does, to help the model decide when to call
                it.
            parameters:
              type: object
              description: Parameter definition in JSON Schema format.
    ResponseFormat:
      type: object
      description: Controls the format of the model output.
      properties:
        type:
          type: string
          enum:
            - text
            - json_object
            - json_schema
          description: Output format type.
        json_schema:
          type: object
          description: The JSON Schema definition when `type=json_schema`.
    Usage:
      type: object
      description: Token usage statistics for the request.
      properties:
        prompt_tokens:
          type: integer
          description: Tokens consumed by the prompt.
        completion_tokens:
          type: integer
          description: Tokens consumed by the completion.
        total_tokens:
          type: integer
          description: Total tokens consumed.
        prompt_tokens_details:
          type: object
          properties:
            cached_tokens:
              type: integer
              description: Tokens served from cache.
            text_tokens:
              type: integer
            audio_tokens:
              type: integer
            image_tokens:
              type: integer
        completion_tokens_details:
          type: object
          properties:
            text_tokens:
              type: integer
            audio_tokens:
              type: integer
            reasoning_tokens:
              type: integer
              description: Tokens consumed by reasoning.
    MessageContent:
      type: object
      description: A multimodal message content part.
      properties:
        type:
          type: string
          enum:
            - text
            - image_url
            - input_audio
            - file
            - video_url
          description: Content part type.
        text:
          type: string
          description: Text content, used when `type=text`.
        image_url:
          type: object
          description: Image content, used when `type=image_url`.
          properties:
            url:
              type: string
              description: Image URL or base64 data URI.
            detail:
              type: string
              enum:
                - low
                - high
                - auto
              description: Image parsing fidelity.
        input_audio:
          type: object
          description: Audio content, used when `type=input_audio`.
          properties:
            data:
              type: string
              description: Base64-encoded audio data.
            format:
              type: string
              enum:
                - wav
                - mp3
              description: Audio format.
        file:
          type: object
          description: File content, used when `type=file`.
          properties:
            filename:
              type: string
            file_data:
              type: string
              description: Base64-encoded file data.
            file_id:
              type: string
        video_url:
          type: object
          description: Video content, used when `type=video_url`.
          properties:
            url:
              type: string
    ToolCall:
      type: object
      description: A tool call initiated by the model.
      properties:
        id:
          type: string
          description: Tool call ID.
        type:
          type: string
          examples:
            - function
        function:
          type: object
          properties:
            name:
              type: string
              description: The name of the called function.
            arguments:
              type: string
              description: Model-generated arguments, as a JSON string.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: >
        Bearer token authentication, format: `Authorization: Bearer sk-xxxxxx`.

        Get your API key in the
        [console](https://api.getinfinityblue.com/console).

````