> ## 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.14 / M | \$0.28 / M  | \$0.028 / M  |
| Kimi K3                | `moonshotai/kimi-k3`                 | 1M      | \$3.00 / M | \$15.00 / M | \$0.30 / M   |

The [catalog](/api-reference/open-models/list-models) endpoint returns the current catalog with pricing and supported features.

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


## 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/Error400'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error401'
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error429'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error500'
      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`. See
            the List Models endpoint for the full catalog.
        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.'
      additionalProperties: true
      description: >-
        OpenAI-compatible request. Supported sampling parameters vary slightly
        by model; the List Models endpoint reports
        `supported_sampling_parameters` and `supported_features` per 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
    Error400:
      type: object
      properties:
        error:
          type: string
          description: Error message
          example: Invalid JSON in request body
    Error401:
      type: object
      properties:
        error:
          type: string
          description: Error message
          example: Authorized header required
    Error429:
      type: object
      properties:
        error:
          type: string
          description: Error message
          example: Rate limit exceeded
    Error500:
      type: object
      properties:
        error:
          type: string
          description: Error message
          example: Error fetching from origin server
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Relace API key Authorization header using the Bearer scheme.

````