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

# Create a chat completion

> Generates the next assistant message for a conversation. Compatible with OpenAI's Chat Completions API. Set `stream: true` to receive the answer as server-sent events.



## OpenAPI

````yaml /openapi.yaml post /chat/completions
openapi: 3.1.0
info:
  title: fastrun API
  version: '1.0'
  description: >-
    OpenAI-compatible inference API. Point any OpenAI SDK at
    https://api.fastrun.si/v1 and send a fastrun API key as a bearer token.
servers:
  - url: https://api.fastrun.si/v1
security:
  - bearerAuth: []
tags:
  - name: Chat
    description: Conversations with chat messages.
  - name: Completions
    description: Raw text continuation.
  - name: Models
    description: The models you can use.
paths:
  /chat/completions:
    post:
      tags:
        - Chat
      summary: Create a chat completion
      description: >-
        Generates the next assistant message for a conversation. Compatible with
        OpenAI's Chat Completions API. Set `stream: true` to receive the answer
        as server-sent events.
      operationId: createChatCompletion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
            example:
              model: google/gemma-4-31b-it
              messages:
                - role: system
                  content: You are a concise assistant.
                - role: user
                  content: Explain prefix caching in one sentence.
              max_tokens: 200
      responses:
        '200':
          description: >-
            The completion. With `stream: true` the body is a
            `text/event-stream` of `chat.completion.chunk` events ending with
            `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'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '502':
          $ref: '#/components/responses/BadGateway'
        '503':
          $ref: '#/components/responses/Unavailable'
components:
  schemas:
    ChatCompletionRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          description: Model ID. See [Models](/models).
          examples:
            - google/gemma-4-31b-it
        messages:
          type: array
          description: The conversation so far, oldest first.
          minItems: 1
          items:
            $ref: '#/components/schemas/Message'
        stream:
          type: boolean
          default: false
          description: >-
            Send the answer as server-sent events while it is generated. See
            [Streaming](/guides/streaming).
        stream_options:
          type: object
          description: Options for streamed responses.
          properties:
            include_usage:
              type: boolean
              default: false
              description: >-
                Send one last chunk with `usage` and an empty `choices` before
                `data: [DONE]`.
        max_tokens:
          type: integer
          minimum: 1
          maximum: 16384
          description: Maximum number of tokens to generate.
        temperature:
          type: number
          minimum: 0
          maximum: 2
          description: Sampling temperature. Higher is more random; 0 is greedy.
        top_p:
          type: number
          minimum: 0
          maximum: 1
          description: >-
            Nucleus sampling. Considers the smallest set of tokens whose
            probabilities add up to `top_p`.
        top_k:
          type: integer
          minimum: 0
          maximum: 1000
          description: Considers only the `top_k` most likely tokens. 0 turns it off.
        min_p:
          type: number
          minimum: 0
          maximum: 1
          description: Drops tokens less likely than `min_p` times the most likely token.
        frequency_penalty:
          type: number
          minimum: -2
          maximum: 2
          description: Penalizes tokens by how often they already appeared.
        presence_penalty:
          type: number
          minimum: -2
          maximum: 2
          description: Penalizes tokens that already appeared at all.
        repetition_penalty:
          type: number
          minimum: 0
          maximum: 2
          description: Multiplicative penalty on repeated tokens. 1 turns it off.
        stop:
          description: >-
            Up to 4 sequences where generation stops. The stop sequence is not
            included in the output.
          oneOf:
            - type: string
            - type: array
              maxItems: 4
              items:
                type: string
        seed:
          type: integer
          minimum: 0
          maximum: 2147483647
          description: Seed for sampling.
        logprobs:
          type: boolean
          default: false
          description: Return the log probability of each output token.
        top_logprobs:
          type: integer
          minimum: 0
          maximum: 20
          description: >-
            With `logprobs`, also return this many most likely alternatives at
            each position.
        tools:
          type: array
          description: >-
            Functions the model may call. See [Tool
            calling](/guides/tool-calling).
          items:
            $ref: '#/components/schemas/Tool'
        tool_choice:
          description: >-
            `auto` (default when `tools` is set) lets the model decide, `none`
            turns tools off, `required` forces a call, and an object names the
            function to call.
          oneOf:
            - type: string
              enum:
                - none
                - auto
                - required
            - type: object
              required:
                - type
                - function
              properties:
                type:
                  type: string
                  enum:
                    - function
                function:
                  type: object
                  required:
                    - name
                  properties:
                    name:
                      type: string
        response_format:
          description: >-
            Constrain the output to JSON. See [Structured
            outputs](/guides/structured-outputs).
          oneOf:
            - type: object
              title: Text
              required:
                - type
              properties:
                type:
                  type: string
                  enum:
                    - text
            - type: object
              title: JSON object
              required:
                - type
              properties:
                type:
                  type: string
                  enum:
                    - json_object
            - type: object
              title: JSON schema
              required:
                - type
                - json_schema
              properties:
                type:
                  type: string
                  enum:
                    - json_schema
                json_schema:
                  type: object
                  required:
                    - name
                    - schema
                  properties:
                    name:
                      type: string
                    schema:
                      type: object
                      description: A JSON Schema the output must match.
                    strict:
                      type: boolean
        reasoning_effort:
          type: string
          enum:
            - none
            - low
            - medium
            - high
          description: >-
            Turns the model's thinking on (`low`, `medium`, `high`) or off
            (`none`). Off when omitted. See [Reasoning](/guides/reasoning).
        chat_template_kwargs:
          type: object
          description: >-
            Extra variables for the model's chat template, such as
            `{"enable_thinking": true}`. See [Reasoning](/guides/reasoning).
          additionalProperties: true
    ChatCompletion:
      type: object
      properties:
        id:
          type: string
        object:
          type: string
          enum:
            - chat.completion
        created:
          type: integer
          description: Unix time in seconds.
        model:
          type: string
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              message:
                type: object
                properties:
                  role:
                    type: string
                    enum:
                      - assistant
                  content:
                    type:
                      - string
                      - 'null'
                  reasoning:
                    type:
                      - string
                      - 'null'
                    description: The model's thinking, when reasoning is on.
                  tool_calls:
                    type: array
                    items:
                      $ref: '#/components/schemas/ToolCall'
              finish_reason:
                type: string
                enum:
                  - stop
                  - length
                  - tool_calls
                description: >-
                  `stop` at a natural end or stop sequence, `length` at
                  `max_tokens` or the context limit, `tool_calls` when the model
                  called a tool.
              logprobs:
                type:
                  - object
                  - 'null'
        usage:
          $ref: '#/components/schemas/Usage'
    ChatCompletionChunk:
      type: object
      description: 'One server-sent event (`data: {...}`).'
      properties:
        id:
          type: string
        object:
          type: string
          enum:
            - chat.completion.chunk
        created:
          type: integer
        model:
          type: string
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              delta:
                type: object
                properties:
                  role:
                    type: string
                  content:
                    type:
                      - string
                      - 'null'
                  reasoning:
                    type:
                      - string
                      - 'null'
                  tool_calls:
                    type: array
                    items:
                      type: object
              finish_reason:
                type:
                  - string
                  - 'null'
        usage:
          description: >-
            Only on the last chunk, and only with
            `stream_options.include_usage`.
          oneOf:
            - $ref: '#/components/schemas/Usage'
            - type: 'null'
    Message:
      type: object
      required:
        - role
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - tool
        content:
          description: >-
            The message text, or a list of text parts. fastrun serves text only;
            image, audio and video parts are rejected. May be null on an
            assistant message that only calls tools.
          oneOf:
            - type: string
            - type: 'null'
            - type: array
              items:
                type: object
                required:
                  - type
                  - text
                properties:
                  type:
                    type: string
                    enum:
                      - text
                  text:
                    type: string
        tool_calls:
          type: array
          description: On assistant messages, the tool calls the model made.
          items:
            $ref: '#/components/schemas/ToolCall'
        tool_call_id:
          type: string
          description: On tool messages, the `id` of the call this message answers.
    Tool:
      type: object
      required:
        - type
        - function
      properties:
        type:
          type: string
          enum:
            - function
        function:
          type: object
          required:
            - name
          properties:
            name:
              type: string
            description:
              type: string
            parameters:
              type: object
              description: JSON Schema of the arguments.
    ToolCall:
      type: object
      required:
        - id
        - type
        - function
      properties:
        id:
          type: string
        type:
          type: string
          enum:
            - function
        function:
          type: object
          required:
            - name
            - arguments
          properties:
            name:
              type: string
            arguments:
              type: string
              description: The arguments as a JSON string.
    Usage:
      type: object
      properties:
        prompt_tokens:
          type: integer
          description: Input tokens, including cached ones.
        completion_tokens:
          type: integer
          description: Generated tokens, including reasoning tokens.
        total_tokens:
          type: integer
        prompt_tokens_details:
          type: object
          properties:
            cached_tokens:
              type: integer
              description: >-
                Input tokens served from the prompt cache. See [Prompt
                caching](/guides/prompt-caching).
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - message
            - type
            - code
          properties:
            message:
              type: string
              description: What went wrong, for people.
            type:
              type: string
              description: Error category, for code.
              enum:
                - invalid_request_error
                - authentication_error
                - rate_limit_error
                - upstream_error
                - unavailable
            code:
              type: integer
              description: The HTTP status.
  responses:
    BadRequest:
      description: >-
        The request is malformed: the body is not a JSON object, `model` is
        missing, or the model rejected a parameter (for example, a prompt longer
        than the context window).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: model is required
              type: invalid_request_error
              code: 400
    Unauthorized:
      description: >-
        The API key is missing, unknown or revoked, or the account has not been
        approved yet.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: invalid or missing API key
              type: authentication_error
              code: 401
    TooManyRequests:
      description: >-
        Every GPU serving the model is busy. Retry after the number of seconds
        in `Retry-After`.
      headers:
        Retry-After:
          $ref: '#/components/headers/RetryAfter'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: all backends for this model are at capacity
              type: rate_limit_error
              code: 429
    BadGateway:
      description: The GPU servers failed to answer. Safe to retry.
      headers:
        Retry-After:
          $ref: '#/components/headers/RetryAfter'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: all backends refused the request
              type: upstream_error
              code: 502
    Unavailable:
      description: >-
        Temporarily unavailable: no GPU server for the model is up, or API keys
        cannot be checked right now. Retry after the number of seconds in
        `Retry-After`.
      headers:
        Retry-After:
          $ref: '#/components/headers/RetryAfter'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: no backend is available for this model
              type: unavailable
              code: 503
  headers:
    RetryAfter:
      description: Seconds to wait before retrying.
      schema:
        type: integer
        minimum: 1
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: A key from https://fastrun.si/dashboard/keys (starts with `fr_`).

````

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