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

# Chat completion

> OpenAI-compatible chat completion. Name a model, or a Smart Router for automatic selection.



## OpenAPI

````yaml openapi.yaml POST /v1/chat/completions
openapi: 3.1.0
info:
  title: ForceAI Gateway API
  version: 1.0.0
  description: >
    Core ForceAI Gateway operations: add a model, mint a virtual key, register
    an A2A agent, and run a chat completion. The gateway is OpenAI compatible,
    so any OpenAI SDK works by pointing base_url at it. Management operations
    (add model, add key, add agent) are admin actions on the control plane; chat
    completions run on the gateway data plane.
servers:
  - url: https://gateway.your-domain.com
    description: >-
      ForceAI endpoint (gateway for chat completions; control plane for admin
      operations)
security:
  - bearerAuth: []
tags:
  - name: Chat
    description: OpenAI-compatible inference
  - name: Models
    description: Add and manage models (admin)
  - name: Keys
    description: Mint and scope virtual keys (admin)
  - name: Agents
    description: Register A2A agents (admin)
paths:
  /v1/chat/completions:
    post:
      tags:
        - Chat
      summary: Chat completion
      description: >
        OpenAI-compatible chat completion. Pass a model name, or the name of a
        Smart Router to let ForceAI pick the model per request. When a router is
        used, `response.model` echoes the router name; the resolved model is on
        the log row.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
            examples:
              smartRouter:
                summary: Via the Smart Router
                value:
                  model: smart-router
                  messages:
                    - role: user
                      content: What is a REST API? Answer in one sentence.
              directModel:
                summary: A specific model
                value:
                  model: gpt-5.4-mini
                  messages:
                    - role: user
                      content: What is a REST API? Answer in one sentence.
      responses:
        '200':
          description: The completion
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
              example:
                id: chatcmpl-DzMATVxiop5hLr5W1R9Sgggf37Sji
                model: smart-router
                choices:
                  - index: 0
                    message:
                      role: assistant
                      content: >-
                        A REST API is a web service interface that lets clients
                        access resources over HTTP using GET, POST, PUT, and
                        DELETE.
                    finish_reason: stop
                usage:
                  prompt_tokens: 17
                  completion_tokens: 33
                  total_tokens: 50
        '401':
          $ref: '#/components/responses/Unauthorized'
components:
  schemas:
    ChatCompletionRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          description: A model name, or a Smart Router name for automatic selection.
          example: smart-router
        messages:
          type: array
          items:
            $ref: '#/components/schemas/ChatMessage'
        max_tokens:
          type: integer
        temperature:
          type: number
        stream:
          type: boolean
          description: Set true for a streamed response.
    ChatCompletionResponse:
      type: object
      properties:
        id:
          type: string
        model:
          type: string
          description: The requested model or router name (not the resolved model).
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              message:
                $ref: '#/components/schemas/ChatMessage'
              finish_reason:
                type: string
        usage:
          type: object
          properties:
            prompt_tokens:
              type: integer
            completion_tokens:
              type: integer
            total_tokens:
              type: integer
    ChatMessage:
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - tool
        content:
          type: string
  responses:
    Unauthorized:
      description: Missing or invalid key
      content:
        application/json:
          example:
            error:
              message: Authentication Error, No api key passed in.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        A ForceAI virtual key or the master key, sent as `Authorization: Bearer
        <key>`.

````