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

# Chat completions

> The primary inference endpoint, OpenAI-compatible chat with streaming, tools, JSON mode, reasoning, and vision.

> [!NOTE]
>
> Parameters not listed here are outside the documented surface, some OpenAI parameters may be accepted, but their behavior isn't guaranteed. Per-model parameter support is listed in `supported_sampling_parameters` on [GET /models](/docs/reference/models.md).

Error bodies and retry guidance are in the [Inference API overview](/docs/reference/inference.md#errors).


## OpenAPI

````yaml /openapi/inference.yaml post /chat/completions
openapi: 3.1.0
info:
  title: Pearl Inference API
  version: '1.0'
  description: >-
    The data-plane API your applications call to run models: OpenAI- and
    Anthropic-compatible endpoints behind one base URL.
servers:
  - url: https://inference.pearlresearch.ai/v1
security:
  - inferenceKey: []
paths:
  /chat/completions:
    post:
      summary: Chat completions
      description: >-
        The primary inference endpoint, OpenAI-compatible chat with streaming,
        tools, JSON mode, reasoning, and vision.
      operationId: createChatCompletion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
            example:
              model: zai-org/GLM-5.3
              messages:
                - role: system
                  content: You are terse.
                - role: user
                  content: Why is the sky blue?
              temperature: 0.7
              max_tokens: 200
      responses:
        '200':
          description: The completion, or an event stream when streaming.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/X-Request-ID'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletion'
              examples:
                completion:
                  summary: Completion
                  value:
                    id: chatcmpl-2de22e60-5d2a-48e7-acfa-28c53fd9da40
                    object: chat.completion
                    created: 1785229039
                    model: zai-org/GLM-5.3
                    choices:
                      - index: 0
                        finish_reason: stop
                        logprobs: null
                        message:
                          role: assistant
                          content: Rayleigh scattering. …
                          reasoning: >-
                            The user wants a terse answer. The dominant effect
                            is …
                    usage:
                      prompt_tokens: 21
                      completion_tokens: 92
                      total_tokens: 113
                      prompt_tokens_details:
                        cached_tokens: 0
            text/event-stream:
              schema:
                type: string
                description: >-
                  With `stream: true` the response is a server-sent-event stream
                  of `chat.completion.chunk` objects terminated by `data:
                  [DONE]`. Each chunk's `choices[0].delta` carries the increment
                  (`content`, `reasoning`, or `tool_calls` fragments); the last
                  content chunk carries `finish_reason`. An error after the
                  stream has started arrives as a final error chunk, not as an
                  HTTP status.
              examples:
                stream:
                  summary: Stream
                  value: >-
                    data:
                    {"id":"chatcmpl-…","object":"chat.completion.chunk","created":1785229039,"model":"zai-org/GLM-5.3","choices":[{"index":0,"delta":{"content":"
                    scattering"},"finish_reason":null}]}


                    data:
                    {"id":"chatcmpl-…","object":"chat.completion.chunk","created":1785229039,"model":"zai-org/GLM-5.3","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}


                    data: [DONE]
                streamError:
                  summary: Error after the stream started
                  value: >-
                    data: {"error":{"message":"backend stream
                    interrupted","type":"api_error"}}


                    data: [DONE]
        '400':
          $ref: '#/components/responses/ChatCompletionsBadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/OutOfCredits'
        '403':
          $ref: '#/components/responses/WrongRegion'
        '404':
          $ref: '#/components/responses/ModelNotFound'
        '413':
          $ref: '#/components/responses/PayloadTooLarge'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
        '502':
          $ref: '#/components/responses/BadGateway'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
        '529':
          $ref: '#/components/responses/NoCapacity'
      x-codeSamples:
        - lang: bash
          label: cURL
          source: |
            curl https://inference.pearlresearch.ai/v1/chat/completions \
              -H "Authorization: Bearer $PEARL_API_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                "model": "zai-org/GLM-5.3",
                "messages": [
                  {"role": "system", "content": "You are terse."},
                  {"role": "user", "content": "Why is the sky blue?"}
                ],
                "temperature": 0.7,
                "max_tokens": 200
              }'
components:
  schemas:
    ChatCompletionRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          description: >-
            A catalog model ID, e.g. `deepseek-ai/DeepSeek-V4-Pro-0813`, the
            `id` field from `GET /models`.
        messages:
          type: array
          description: >-
            The conversation, oldest first. Roles: `system`, `developer`,
            `user`, `assistant`, `tool`. A user message's `content` is a string,
            or an array of `text` / `image_url` parts on vision models (images
            as base64 data URIs only, see [Vision](/vision)).
          items:
            type: object
            properties:
              role:
                type: string
                enum:
                  - system
                  - developer
                  - user
                  - assistant
                  - tool
              content:
                oneOf:
                  - title: string
                    type: string
                  - title: array
                    type: array
                    items:
                      type: object
                      properties:
                        type:
                          type: string
                          enum:
                            - text
                            - image_url
        max_tokens:
          type: integer
          description: >-
            Cap on generated tokens, on reasoning models the thinking counts
            against it. Hitting the cap sets `finish_reason: "length"`.
            Per-model ceilings are the `max_output_length` on `GET /models`.
        temperature:
          type: number
          minimum: 0
          maximum: 2
          description: Sampling temperature, 0 to 2. Lower is more deterministic.
        top_p:
          type: number
          minimum: 0
          maximum: 1
          description: Nucleus sampling mass, 0 to 1.
        top_k:
          type: integer
          minimum: 0
          maximum: 1024
          description: >-
            Sample only from the k most likely tokens (0 to 1024). A Pearl
            extension, pass via `extra_body` in the OpenAI SDKs.
        min_p:
          type: number
          minimum: 0
          maximum: 1
          description: >-
            Drop tokens below this probability relative to the top token (0 to
            1). Extension via `extra_body`; not all models, check
            `supported_sampling_parameters`.
        frequency_penalty:
          type: number
          minimum: -2
          maximum: 2
          description: −2 to 2. Positive values discourage token repetition by frequency.
        presence_penalty:
          type: number
          minimum: -2
          maximum: 2
          description: >-
            −2 to 2. Positive values discourage reusing tokens that already
            appeared.
        repetition_penalty:
          type: number
          minimum: 0
          maximum: 2
          description: >-
            Alternative repetition control (0 to 2, 1 is off), used by some
            model families instead of the frequency/presence pair. Extension via
            `extra_body`; not all models, check `supported_sampling_parameters`.
        stop:
          type: array
          maxItems: 4
          description: Up to 4 non-empty sequences that end generation when produced.
          items:
            type: string
            minLength: 1
        seed:
          type: integer
          description: >-
            Best-effort determinism for repeated sampling, not a reproducibility
            guarantee.
        stream:
          type: boolean
          description: >-
            Stream the response as server-sent events, see
            [Streaming](/streaming) and the chunk shape below.
        response_format:
          type: object
          description: >-
            `{"type": "text"}` (default) or `{"type": "json_object"}` for [JSON
            mode](/json-mode). The stricter `json_schema` type is not available.
          properties:
            type:
              type: string
              enum:
                - text
                - json_object
              default: text
        tools:
          type: array
          description: >-
            Function tool definitions (`{"type": "function", "function": {…}}`)
            the model may call, see [Function calling](/function-calling).
          items:
            type: object
            properties:
              type:
                type: string
                enum:
                  - function
              function:
                type: object
        reasoning:
          type: object
          description: >-
            The one reasoning control on reasoning models: `{"enabled": bool,
            "effort": string}`, both optional. Effort is `none` | `minimal` |
            `low` | `medium` | `high` | `xhigh` | `max`, resolved per model
            against `supported_efforts` in its [GET /models](/reference/models)
            reasoning block: a served level applies as is, any other rounds up
            to the next served level (or to the highest one past the top), and
            `none` is the disable control, not a rung. `{"effort": "none"}` (or
            `enabled: false`) disables thinking only on models not marked
            `mandatory` in that block (GLM-5.3 and GLM-5.3-Flash are, and reject
            the disable with `400`). A `max_tokens` member returns `400` on
            every model today (`supports_max_tokens: false`); bound thinking
            with the effort or the top-level `max_tokens`. Omission keeps the
            model's `default_effort`, `max` on GLM-5.3. Via `extra_body` in the
            OpenAI Python SDK. Provider-native switches (`thinking`,
            `chat_template_kwargs.enable_thinking`, and their siblings) return
            `400` on key presence.
          properties:
            enabled:
              type: boolean
            effort:
              type: string
              enum:
                - none
                - minimal
                - low
                - medium
                - high
                - xhigh
                - max
        reasoning_effort:
          type: string
          enum:
            - none
            - minimal
            - low
            - medium
            - high
            - xhigh
            - max
          description: >-
            OpenAI's flat spelling of `reasoning.effort`, with the same values
            and rounding. Sending both returns `400`.
        'n':
          type: integer
          minimum: 1
          maximum: 8
          default: 1
          description: Number of choices to generate, 1 to 8. Defaults to 1.
        stream_options:
          type: object
          description: >-
            `{"include_usage": bool}`. Streams always end with a usage chunk
            unless you set `include_usage: false`.
          properties:
            include_usage:
              type: boolean
              default: true
    ChatCompletion:
      type: object
      properties:
        id:
          type: string
          description: Completion ID, log it for request-level forensics.
        object:
          type: string
          enum:
            - chat.completion
            - chat.completion.chunk
          description: '`chat.completion`, or `chat.completion.chunk` when streaming.'
        created:
          type: integer
          description: Unix timestamp (seconds).
        model:
          type: string
          description: The model that served the request.
        choices:
          type: array
          items:
            type: object
            properties:
              message:
                type: object
                description: >-
                  `role` + `content`; reasoning models add `reasoning`, tool use
                  adds `tool_calls` (with `content: null`).
                properties:
                  role:
                    type: string
                  content:
                    type:
                      - string
                      - 'null'
                  reasoning:
                    type: string
                  tool_calls:
                    type: array
                    items:
                      type: object
              finish_reason:
                type: string
                enum:
                  - stop
                  - length
                  - tool_calls
                description: >-
                  `stop` (natural end or stop sequence), `length` (hit
                  `max_tokens`), or `tool_calls`.
        usage:
          type: object
          description: >-
            `prompt_tokens`, `completion_tokens`, `total_tokens`, what you're
            billed on. Worker-dependent details:
            `prompt_tokens_details.cached_tokens` and
            `completion_tokens_details.reasoning_tokens`.
          properties:
            prompt_tokens:
              type: integer
            completion_tokens:
              type: integer
            total_tokens:
              type: integer
            prompt_tokens_details:
              type: object
              properties:
                cached_tokens:
                  type: integer
            completion_tokens_details:
              type: object
              properties:
                reasoning_tokens:
                  type: integer
    OpenAIError:
      type: object
      description: Errors are JSON in OpenAI's shape, with the request ID in the body.
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
              enum:
                - invalid_request_error
                - authentication_error
                - permission_error
                - rate_limit_error
                - api_error
            code:
              type: string
              description: >-
                Present only when set, for example `model_not_found` or
                `no_capacity`.
            request_id:
              type: string
              description: The request ID.
  headers:
    X-Request-ID:
      description: >-
        The request ID. Send your own UUID in `X-Request-ID` to use it as the
        ID. Include the ID when you contact support.
      schema:
        type: string
      example: 6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87
    Retry-After:
      description: Seconds to wait before retrying.
      schema:
        type: integer
  responses:
    ChatCompletionsBadRequest:
      description: >-
        Invalid request: malformed JSON, a missing or wrongly typed field, an
        unsupported reasoning control, or image input to a model without vision.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/X-Request-ID'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OpenAIError'
          examples:
            malformedJson:
              summary: Malformed JSON
              value:
                error:
                  message: malformed JSON
                  type: invalid_request_error
                  request_id: 6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87
    Unauthorized:
      description: >-
        Missing, unknown, revoked, or expired API key, a key over its credit
        limit, or a management key.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/X-Request-ID'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OpenAIError'
          examples:
            unknownKey:
              summary: Unknown API key
              value:
                error:
                  message: unknown API key
                  type: authentication_error
                  request_id: 6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87
    OutOfCredits:
      description: >-
        Your organization is out of credits. Top up on the
        [Billing](https://platform.pearlresearch.ai/billing) page, then retry.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/X-Request-ID'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OpenAIError'
          examples:
            outOfCredits:
              summary: Out of credits
              value:
                error:
                  message: your organization is out of credits
                  type: api_error
                  request_id: 6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87
    WrongRegion:
      description: >-
        Wrong endpoint for your organization's [inference
        region](/data-residency).
      headers:
        X-Request-ID:
          $ref: '#/components/headers/X-Request-ID'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OpenAIError'
          examples:
            wrongRegion:
              summary: Wrong endpoint for the region
              value:
                error:
                  message: wrong endpoint for your organization's inference region
                  type: permission_error
                  request_id: 6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87
    ModelNotFound:
      description: >-
        Unknown model (code `model_not_found`), or one this endpoint doesn't
        serve.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/X-Request-ID'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OpenAIError'
          examples:
            unknownModel:
              summary: Unknown model
              value:
                error:
                  message: unknown model
                  type: invalid_request_error
                  code: model_not_found
                  request_id: 6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87
    PayloadTooLarge:
      description: Request body over 20 MiB.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/X-Request-ID'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OpenAIError'
          examples:
            bodyTooLarge:
              summary: Body over 20 MiB
              value:
                error:
                  message: request body over 20 MiB
                  type: invalid_request_error
                  request_id: 6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87
    RateLimited:
      description: >-
        A [rate limit](/plans) for your organization and the model was reached.
        Wait for the `Retry-After` header's seconds.
      headers:
        Retry-After:
          $ref: '#/components/headers/Retry-After'
        X-Request-ID:
          $ref: '#/components/headers/X-Request-ID'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OpenAIError'
          examples:
            rateLimited:
              summary: Rate limit reached
              value:
                error:
                  message: rate limit reached
                  type: rate_limit_error
                  request_id: 6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87
    InternalError:
      description: Internal error. Safe to retry with backoff.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/X-Request-ID'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OpenAIError'
          examples:
            internalError:
              summary: Internal error
              value:
                error:
                  message: internal error
                  type: api_error
                  request_id: 6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87
    BadGateway:
      description: >-
        The model server failed or returned a malformed response. Retry with
        backoff.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/X-Request-ID'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OpenAIError'
          examples:
            modelServerFailed:
              summary: Model server failed
              value:
                error:
                  message: the model server failed
                  type: api_error
                  request_id: 6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87
    ServiceUnavailable:
      description: >-
        Temporarily unavailable, for example during a deploy. Retry after the
        `Retry-After` header's seconds.
      headers:
        Retry-After:
          $ref: '#/components/headers/Retry-After'
        X-Request-ID:
          $ref: '#/components/headers/X-Request-ID'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OpenAIError'
          examples:
            unavailable:
              summary: Temporarily unavailable
              value:
                error:
                  message: temporarily unavailable
                  type: api_error
                  request_id: 6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87
    NoCapacity:
      description: >-
        No capacity for the model right now (code `no_capacity`). Retry with
        backoff.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/X-Request-ID'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OpenAIError'
          examples:
            noCapacity:
              summary: No capacity
              value:
                error:
                  message: no capacity for the model right now
                  type: api_error
                  code: no_capacity
                  request_id: 6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87
  securitySchemes:
    inferenceKey:
      type: http
      scheme: bearer
      description: >-
        `Bearer` followed by an inference API key (`sk-prl-infapi-`). Create
        keys on the [API Keys](https://platform.pearlresearch.ai/api-keys) page.
        Management keys (`sk-prl-mgmt-`) cannot call models.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.