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

# Create a chat completion (OpenAI-compatible)

> Drop-in compatible with OpenAI's Chat Completions API. Set `stream: true` for SSE.



## OpenAPI

````yaml /openapi.yaml post /v1/chat/completions
openapi: 3.1.0
info:
  title: Impossibl AI API
  version: 0.0.1
  description: >
    The Impossibl AI API is one API for all AI providers, OpenAI-compatible
    across OpenAI,

    Anthropic, Google, xAI, and more (`GET /v1/models` lists the full catalog),

    billed from a prepaid credit balance.


    Provider usage is billed at provider list prices with no usage markup.

    Prepaid credit purchases charge a separate fixed 5% platform fee before tax.


    **Agent quickstart**

    1. `POST /v1/accounts` — create a funded account; you get an API key and a
       signup-bonus balance in one call (no human step required).
    2. Call `POST /v1/chat/completions`, `POST /v1/responses`, or
       `POST /v1/audio/transcriptions` with
       `Authorization: Bearer <key>` and a `provider/model` id from `GET /v1/models`.
    3. Credits are deducted per request by token or audio-duration usage; check
    `GET /v1/account`.
servers:
  - url: https://api.impossibl.com
    description: Production
  - url: http://localhost:8787
    description: Local dev
security:
  - BearerKey: []
paths:
  /v1/chat/completions:
    post:
      summary: Create a chat completion (OpenAI-compatible)
      description: >-
        Drop-in compatible with OpenAI's Chat Completions API. Set `stream:
        true` for SSE.
      operationId: createChatCompletion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
      responses:
        '200':
          description: >
            A `chat.completion` object. When `stream: true`, the body is instead
            an

            SSE stream of `chat.completion.chunk` objects terminated by `data:
            [DONE]`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletion'
            text/event-stream:
              schema:
                $ref: '#/components/schemas/ChatCompletionChunk'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/InsufficientCredits'
        '404':
          $ref: '#/components/responses/UnknownModel'
        '502':
          $ref: '#/components/responses/UpstreamError'
        '503':
          $ref: '#/components/responses/ProviderNotConfigured'
components:
  schemas:
    ChatCompletionRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          example: openai/gpt-4o-mini
        messages:
          type: array
          items:
            type: object
            properties:
              role:
                type: string
                enum:
                  - system
                  - developer
                  - user
                  - assistant
                  - tool
              content:
                description: >-
                  A text string, or an array of content parts (text, image_url,
                  input_audio, video_url) for multimodal input.
                oneOf:
                  - type: string
                  - type: array
                    items:
                      $ref: '#/components/schemas/ChatContentPart'
                  - type: 'null'
              tool_call_id:
                type: string
                description: On `tool` messages
                the id of the tool call this result is for.: null
              tool_calls:
                type: array
                description: >-
                  On `assistant` messages, tool calls being relayed back to the
                  model.
                items:
                  $ref: '#/components/schemas/ChatToolCall'
        stream:
          type: boolean
          default: false
        stream_options:
          type: object
          properties:
            include_usage:
              type: boolean
        temperature:
          type: number
        top_p:
          type: number
        max_tokens:
          type: integer
        max_completion_tokens:
          type: integer
        tools:
          type: array
          description: >-
            Function tools the model may call (relay mode — the gateway does not
            execute them).
          items:
            $ref: '#/components/schemas/ChatTool'
        tool_choice:
          description: >-
            `auto`, `none`, `required`, or `{ type: function, function: { name }
            }`.
          oneOf:
            - type: string
              enum:
                - auto
                - none
                - required
            - type: object
              properties:
                type:
                  type: string
                  const: function
                function:
                  type: object
                  properties:
                    name:
                      type: string
        parallel_tool_calls:
          type: boolean
        reasoning_effort:
          type: string
          enum:
            - none
            - minimal
            - low
            - medium
            - high
            - xhigh
          description: >-
            Forwarded across native OpenAI, Azure OpenAI, and OpenAI-compatible
            routes.
    ChatCompletion:
      type: object
      description: Non-streaming chat completion (OpenAI `chat.completion`).
      properties:
        id:
          type: string
          example: chatcmpl-...
        object:
          type: string
          const: chat.completion
        created:
          type: integer
          description: Unix seconds
        model:
          type: string
          example: openai/gpt-4o-mini
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              finish_reason:
                type: string
                enum:
                  - stop
                  - length
                  - content_filter
                  - tool_calls
                nullable: true
              message:
                type: object
                properties:
                  role:
                    type: string
                    const: assistant
                  content:
                    type: string
                    nullable: true
                  tool_calls:
                    type: array
                    description: >-
                      Present when the model called tools (finish_reason
                      `tool_calls`).
                    items:
                      $ref: '#/components/schemas/ChatToolCall'
        usage:
          $ref: '#/components/schemas/Usage'
    ChatCompletionChunk:
      type: object
      description: >-
        One SSE chunk (OpenAI `chat.completion.chunk`), sent as a `data:` line;
        the stream ends with a `[DONE]` sentinel.
      properties:
        id:
          type: string
        object:
          type: string
          const: chat.completion.chunk
        created:
          type: integer
        model:
          type: string
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              finish_reason:
                type: string
                nullable: true
              delta:
                type: object
                description: >-
                  Incremental update — `role` on the first chunk, then `content`
                  deltas, or `tool_calls` fragments.
                properties:
                  role:
                    type: string
                  content:
                    type: string
                  tool_calls:
                    type: array
                    description: >-
                      Streaming tool-call fragments; `index` correlates
                      fragments of the same call.
                    items:
                      type: object
                      properties:
                        index:
                          type: integer
                        id:
                          type: string
                        type:
                          type: string
                          const: function
                        function:
                          type: object
                          properties:
                            name:
                              type: string
                            arguments:
                              type: string
        usage:
          description: >-
            Present only on the final chunk when `stream_options.include_usage`
            is true.
          oneOf:
            - $ref: '#/components/schemas/Usage'
            - type: 'null'
    ChatContentPart:
      type: object
      properties:
        type:
          type: string
          enum:
            - text
            - image_url
            - input_audio
            - video_url
        text:
          type: string
          description: Present when `type` is `text`.
        image_url:
          type: object
          description: Present when `type` is `image_url`.
          properties:
            url:
              type: string
              description: An http(s) URL or a `data:` base64 URI.
            detail:
              type: string
              enum:
                - auto
                - low
                - high
        input_audio:
          type: object
          description: >-
            Present when `type` is `input_audio`. Only models advertising
            `audio` in `input_modalities` accept it.
          properties:
            data:
              type: string
              description: Base64-encoded audio (no data-URI prefix).
            format:
              type: string
              description: '`wav` or `mp3` (`aiff`, `aac`, `ogg`, `flac` also pass through).'
        video_url:
          type: object
          description: >-
            Present when `type` is `video_url`. Only models advertising `video`
            in `input_modalities` accept it.
          properties:
            url:
              type: string
              description: >-
                A `data:` base64 URI or an http(s) URL. YouTube URLs pass
                through to Gemini; other URLs are fetched by the gateway and
                sent inline (~20MB limit).
    ChatToolCall:
      type: object
      description: >-
        A complete tool call (non-streaming). `function.arguments` is a
        JSON-encoded string.
      properties:
        id:
          type: string
        type:
          type: string
          const: function
        function:
          type: object
          properties:
            name:
              type: string
            arguments:
              type: string
              description: JSON-encoded arguments string.
    ChatTool:
      type: object
      required:
        - type
        - function
      properties:
        type:
          type: string
          const: function
        function:
          type: object
          required:
            - name
          properties:
            name:
              type: string
            description:
              type: string
            parameters:
              type: object
              description: JSON Schema for the tool input.
    Usage:
      type: object
      description: OpenAI-style token usage.
      properties:
        prompt_tokens:
          type: integer
        completion_tokens:
          type: integer
        total_tokens:
          type: integer
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
              description: >-
                One of authentication_error, invalid_request_error,
                insufficient_quota, upstream_error, provider_not_configured.
  responses:
    BadRequest:
      description: Malformed request (bad JSON, or missing required fields).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: '`model` and `messages` are required'
              type: invalid_request_error
    Unauthorized:
      description: Missing or invalid API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: Invalid API key
              type: authentication_error
    InsufficientCredits:
      description: The account's credit balance is empty. Top up to continue.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: Insufficient credits. Top up to continue.
              type: insufficient_quota
    UnknownModel:
      description: The requested `model` id is not in the registry (see GET /v1/models).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: 'Unknown model: foo/bar'
              type: invalid_request_error
    UpstreamError:
      description: The upstream provider returned an error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: 'permission-denied: ...'
              type: upstream_error
    ProviderNotConfigured:
      description: The provider for this model has no API key configured on the gateway.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: 'Provider not configured: missing OPENAI_API_KEY'
              type: provider_not_configured
  securitySchemes:
    BearerKey:
      type: http
      scheme: bearer
      description: Gateway API key (`imp-rt-...`) from POST /v1/accounts or /v1/keys.

````