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

# Chat Completions

> POST /v1/chat/completions — OpenAI-compatible chat

<Note>
  Unknown parameters are forwarded to the upstream provider as-is. Errors for unsupported parameters (e.g. `tools`, `response_format`) come from the provider, not Routify.
</Note>


## OpenAPI

````yaml POST /v1/chat/completions
openapi: 3.1.0
info:
  title: Routify API
  version: 0.1.0
  description: |
    Routify MVP API contract.
    /v1/chat/completions is a strict MVP subset of OpenAI-compatible APIs.
    /v1/responses is a native pass-through proxy to upstream.
servers:
  - url: https://api.routify.ru
    description: Production server
security:
  - bearerAuth: []
tags:
  - name: Chat
  - name: Responses
  - name: Models
paths:
  /v1/chat/completions:
    post:
      tags:
        - Chat
      summary: Create a chat completion
      description: >
        OpenAI-compatible chat completions. Streaming uses SSE and ends with
        [DONE].

        Requires `Authorization: Bearer $ROUTIFY_API_KEY`.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
      responses:
        '200':
          description: Successful response (JSON or SSE stream)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
            text/event-stream:
              schema:
                $ref: '#/components/schemas/ChatCompletionStreamChunk'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/RateLimited'
        '502':
          $ref: '#/components/responses/BadGateway'
      x-codeSamples:
        - lang: curl
          label: cURL
          source: |
            curl https://api.routify.ru/v1/chat/completions \
              -H "Authorization: Bearer $ROUTIFY_API_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                "model": "gpt-4.1",
                "messages": [
                  {"role": "system", "content": "You are a helpful assistant."},
                  {"role": "user", "content": "Hello!"}
                ]
              }'
        - lang: python
          label: Python
          source: |
            from openai import OpenAI

            client = OpenAI(
                api_key="$ROUTIFY_API_KEY",
                base_url="https://api.routify.ru/v1"
            )

            response = client.chat.completions.create(
                model="gpt-4.1",
                messages=[
                    {"role": "system", "content": "You are a helpful assistant."},
                    {"role": "user", "content": "Hello!"}
                ]
            )
            print(response.choices[0].message.content)
        - lang: javascript
          label: Node.js
          source: |
            import OpenAI from "openai";

            const client = new OpenAI({
              apiKey: process.env.ROUTIFY_API_KEY,
              baseURL: "https://api.routify.ru/v1"
            });

            const response = await client.chat.completions.create({
              model: "gpt-4.1",
              messages: [
                { role: "system", content: "You are a helpful assistant." },
                { role: "user", content: "Hello!" }
              ]
            });
            console.log(response.choices[0].message.content);
components:
  schemas:
    ChatCompletionRequest:
      type: object
      additionalProperties: false
      properties:
        model:
          type: string
          description: >
            Model ID used to generate the response. Use `GET /v1/models` to list
            all available models.
        messages:
          type: array
          minItems: 1
          description: A list of messages comprising the conversation so far.
          items:
            $ref: '#/components/schemas/ChatMessage'
        stream:
          type: boolean
          default: false
          description: >
            If set to true, the response is streamed to the client as it is
            generated using server-sent events. The stream ends with `data:
            [DONE]`.
        max_tokens:
          type: integer
          minimum: 1
          description: >
            An upper bound for the number of tokens that can be generated in the
            completion.
        reasoning_effort:
          type: string
          enum:
            - low
            - medium
            - high
            - xhigh
          description: >
            Constrains effort on reasoning for reasoning models (e.g. o3,
            o4-mini). Supported values: `low`, `medium`, `high`, `xhigh`. Lower
            effort reduces latency and cost; higher effort improves accuracy on
            complex tasks.
        verbosity:
          type: string
          enum:
            - low
            - medium
            - high
          description: Controls verbosity of the model response.
        reasoningSummary:
          type: string
          enum:
            - auto
            - detail
            - concise
          description: >
            Controls the format of reasoning summaries in the response.
            Supported values: `auto`, `detail`, `concise`.
        temperature:
          type: number
          minimum: 0
          maximum: 2
          description: >
            What sampling temperature to use, between 0 and 2. Higher values
            like 0.8 will make the output more random, while lower values like
            0.2 will make it more focused and deterministic. We recommend
            altering this or `top_p` but not both.
        top_p:
          type: number
          minimum: 0
          maximum: 1
          description: >
            An alternative to sampling with temperature, called nucleus
            sampling, where the model considers only the tokens with top_p
            probability mass. So 0.1 means only the tokens comprising the top
            10% probability mass are considered. We recommend altering this or
            `temperature` but not both.
        stop:
          description: >
            Up to 4 sequences where the API will stop generating further tokens.
            The returned text will not contain the stop sequence.
          oneOf:
            - type: string
            - type: array
              items:
                type: string
              minItems: 1
              maxItems: 4
      required:
        - model
        - messages
    ChatCompletionResponse:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
          description: A unique identifier for the chat completion.
        object:
          type: string
          const: chat.completion
          description: The object type. Always `chat.completion`.
        created:
          type: integer
          description: >-
            The Unix timestamp (in seconds) of when the chat completion was
            created.
        model:
          type: string
          description: The model used for the chat completion.
        choices:
          type: array
          minItems: 1
          description: A list of chat completion choices.
          items:
            $ref: '#/components/schemas/ChatCompletionChoice'
        usage:
          $ref: '#/components/schemas/Usage'
      required:
        - id
        - object
        - created
        - model
        - choices
        - usage
    ChatCompletionStreamChunk:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
        object:
          type: string
          const: chat.completion.chunk
        created:
          type: integer
        model:
          type: string
        choices:
          type: array
          minItems: 1
          items:
            $ref: '#/components/schemas/ChatCompletionStreamChoice'
      required:
        - id
        - object
        - created
        - model
        - choices
    ChatMessage:
      type: object
      additionalProperties: false
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - developer
            - tool
          description: The role of the message author.
        content:
          type: string
          description: The content of the message.
      required:
        - role
        - content
    ChatCompletionChoice:
      type: object
      additionalProperties: false
      properties:
        index:
          type: integer
          description: The index of the choice in the list of generated choices.
        finish_reason:
          type: string
          enum:
            - stop
            - length
            - content_filter
            - tool_calls
            - error
          description: >
            The reason the model stopped generating tokens. `stop` means the
            model hit a natural stop point or a provided stop sequence. `length`
            means the maximum token count was reached. `content_filter` means
            content was omitted due to a policy. `tool_calls` means the model
            called a tool.
        message:
          $ref: '#/components/schemas/ChatCompletionChoiceMessage'
      required:
        - index
        - finish_reason
        - message
    Usage:
      type: object
      additionalProperties: false
      properties:
        prompt_tokens:
          type: integer
          minimum: 0
          description: Number of tokens in the prompt.
        prompt_tokens_details:
          type: object
          additionalProperties: false
          description: Breakdown of tokens used in the prompt.
          properties:
            cached_tokens:
              type: integer
              minimum: 0
              description: Tokens that were served from the prompt cache.
            cache_write_tokens:
              type: integer
              minimum: 0
              description: Tokens written to the prompt cache in this request.
        completion_tokens:
          type: integer
          minimum: 0
          description: Number of tokens in the generated completion.
        total_tokens:
          type: integer
          minimum: 0
          description: Total number of tokens used (prompt + completion).
      required:
        - prompt_tokens
        - completion_tokens
        - total_tokens
    ChatCompletionStreamChoice:
      type: object
      additionalProperties: false
      properties:
        index:
          type: integer
        delta:
          $ref: '#/components/schemas/ChatCompletionStreamDelta'
        finish_reason:
          type:
            - string
            - 'null'
          enum:
            - stop
            - length
            - content_filter
            - tool_calls
            - error
            - null
      required:
        - index
        - delta
        - finish_reason
    ErrorResponse:
      type: object
      additionalProperties: false
      properties:
        error:
          type: object
          additionalProperties: false
          properties:
            message:
              type: string
            type:
              $ref: '#/components/schemas/ErrorType'
          required:
            - message
            - type
      required:
        - error
    ChatCompletionChoiceMessage:
      type: object
      additionalProperties: false
      properties:
        role:
          type: string
          enum:
            - assistant
          description: The role of the author of this message. Always `assistant`.
        content:
          type: string
          description: The content of the message.
      required:
        - role
        - content
    ChatCompletionStreamDelta:
      type: object
      additionalProperties: false
      properties:
        role:
          type: string
          enum:
            - assistant
        content:
          type: string
    ErrorType:
      type: string
      enum:
        - invalid_request_error
        - auth_error
        - billing_error
        - rate_limit_error
        - provider_error
  responses:
    BadRequest:
      description: Invalid request or unsupported field
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              message: model is required
              type: invalid_request_error
    Unauthorized:
      description: Missing or invalid API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              message: invalid api key
              type: auth_error
    PaymentRequired:
      description: Insufficient balance
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              message: insufficient balance
              type: billing_error
    NotFound:
      description: Model or resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              message: model not found
              type: invalid_request_error
    RateLimited:
      description: Rate limit exceeded
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              message: rate limit exceeded
              type: rate_limit_error
    BadGateway:
      description: Upstream provider failure
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              message: all providers unavailable
              type: provider_error
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: token
      description: >
        Bearer authentication header of the form `Authorization: Bearer
        $ROUTIFY_API_KEY`.

````