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

# Chat Completions

> Send an OpenAI-compatible chat completions request to a Relace-hosted model.

OpenAI-compatible endpoint for open-weights models hosted on Relace infrastructure. You can also use this by pointing any OpenAI SDK at `https://models.relace.ai/v1` with your Relace API key.

## Models

| Model                  | `model` ID                           | Context | Input         | Output       | Cached Input  |
| ---------------------- | ------------------------------------ | ------- | ------------- | ------------ | ------------- |
| DeepSeek V4 Flash 0731 | `deepseek-ai/DeepSeek-V4-Flash-0731` | 1M      | \$0.065 / M   | \$0.18 / M   | \$0.016 / M   |
| Kimi K3                | `moonshotai/kimi-k3`                 | 1M      | \$3.00 / M    | \$15.00 / M  | \$0.30 / M    |
| GLM 5.3 Flash          | `z-ai/glm-5.3-flash`                 | 1M      | \$0.07125 / M | \$0.2375 / M | \$0.01425 / M |

See the [Open Models guide](/docs/open-models/quickstart) for SDK examples and streaming.

## Prompt Caching

Prompt caching is automatic. Cache hits are billed at the Cached Input rate and reported in `usage.prompt_tokens_details.cached_tokens`. To keep a multi-turn session on its cache, set `prompt_cache_key` to a stable value per session. See [Prompt Caching and Session Affinity](/docs/open-models/quickstart#prompt-caching-and-session-affinity).


## OpenAPI

````yaml POST /v1/chat/completions
openapi: 3.0.1
info:
  title: Relace API
  description: API for accessing Relace code generation models.
  version: 1.0.0
  license:
    name: MIT
servers:
  - url: https://models.relace.ai
    description: Server for model API endpoints
  - url: https://api.relace.run
    description: Server for general infrastructure
security:
  - bearerAuth: []
paths:
  /v1/chat/completions:
    post:
      description: >-
        Send an OpenAI-compatible chat completions request to a Relace-hosted
        model.
      requestBody:
        description: OpenAI-compatible chat completions request
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionsRequest'
            example:
              model: deepseek-ai/DeepSeek-V4-Flash-0731
              messages:
                - role: user
                  content: Write a binary search in Python.
              stream: false
      responses:
        '200':
          description: Chat completion generated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionsResponse'
            text/event-stream:
              schema:
                type: string
                description: >-
                  Stream of chat completion chunks in the OpenAI streaming
                  format. Token usage is reported in the final chunk.
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIError'
        '402':
          description: Out of credits, or no payment method on the account
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIError'
        '404':
          description: Route not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIError'
        '429':
          description: Rate limit exceeded, or the model is at capacity
          headers:
            Retry-After:
              schema:
                type: string
              description: Seconds to wait before retrying
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIError'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIError'
        '502':
          description: Model server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIError'
        '503':
          description: Model temporarily unavailable
          headers:
            Retry-After:
              schema:
                type: string
              description: Seconds to wait before retrying
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIError'
        '504':
          description: Request to the model timed out
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIError'
      servers:
        - url: https://models.relace.ai
components:
  schemas:
    ChatCompletionsRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          description: >-
            ID of the hosted model to use, e.g.
            `deepseek-ai/DeepSeek-V4-Flash-0731` or `moonshotai/kimi-k3`.
        messages:
          type: array
          items:
            type: object
          description: >-
            The conversation so far, as OpenAI-format message objects with
            `role` and `content`.
        stream:
          type: boolean
          description: >-
            If true, tokens are sent as server-sent events as they are
            generated. Token usage is always reported in the final chunk of the
            stream.
        max_tokens:
          type: integer
          description: >-
            Maximum number of tokens to generate. Reasoning tokens count toward
            this limit, so set a generous budget.
        temperature:
          type: number
          description: Sampling temperature. Higher values make output more random.
        top_p:
          type: number
          description: >-
            Nucleus sampling: only tokens within the top `top_p` probability
            mass are considered.
        top_k:
          type: integer
          description: Only the `top_k` most likely tokens are considered at each step.
        stop:
          type: array
          items:
            type: string
          description: Up to 4 sequences at which generation stops.
        frequency_penalty:
          type: number
          description: >-
            Penalizes tokens by how often they have appeared so far. Range -2 to
            2.
        presence_penalty:
          type: number
          description: Penalizes tokens that have appeared at all so far. Range -2 to 2.
        repetition_penalty:
          type: number
          description: >-
            Multiplicative penalty on repeated tokens. Values above 1 discourage
            repetition.
        tools:
          type: array
          items:
            type: object
          description: OpenAI-format function tool definitions the model may call.
        tool_choice:
          description: 'Controls tool use: `none`, `auto`, `required`, or a specific tool.'
        response_format:
          type: object
          description: 'Set to `{"type": "json_object"}` for JSON mode. Kimi K3 only.'
        prompt_cache_key:
          type: string
          maxLength: 512
          description: >-
            Cache affinity key. Requests with the same key are served by the
            same server, improving cache hit rates for multi-turn sessions. Use
            a stable value per conversation or session. Compatible with OpenAI's
            parameter of the same name.
      additionalProperties: true
      description: >-
        OpenAI-compatible request. Supported sampling parameters vary slightly
        by model.
    ChatCompletionsResponse:
      type: object
      properties:
        id:
          type: string
          description: Unique identifier for the completion
        object:
          type: string
          description: Always `chat.completion`
        created:
          type: integer
          description: Unix timestamp of when the completion was created
        model:
          type: string
          description: The model that served the request
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              message:
                type: object
                description: >-
                  The generated message, with `role` and `content` (and
                  `tool_calls` when the model called tools)
              finish_reason:
                type: string
                description: Why generation stopped, e.g. `stop`, `length`, or `tool_calls`
          description: The generated completions
        usage:
          type: object
          properties:
            prompt_tokens:
              type: integer
              description: Number of tokens in the prompt
            completion_tokens:
              type: integer
              description: Number of tokens in the completion
            total_tokens:
              type: integer
              description: Total number of tokens used
          description: Token usage information for the request
    OpenAIError:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              description: Error message
              example: >-
                Rate limit exceeded. Retry after the Retry-After interval, or
                contact support to raise your limits.
            type:
              type: string
              description: OpenAI error type
              enum:
                - invalid_request_error
                - authentication_error
                - insufficient_quota
                - rate_limit_error
                - api_error
              example: rate_limit_error
            param:
              type: string
              nullable: true
              description: Offending request parameter, when known
              example: null
            code:
              type: string
              nullable: true
              description: Always null on Relace-authored errors
              example: null
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Relace API key Authorization header using the Bearer scheme.

````