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

# Create chat completion

> Creates a chat completion. Set `stream: true` for **server-sent events** with content type `text/event-stream`. Body matches OpenAI **Create chat completion**; `model` uses `provider/model` form.



## OpenAPI

````yaml /api-reference/ageneral-models-openapi.json post /v1/chat/completions
openapi: 3.1.0
info:
  title: Models
  version: 1.0.0
  description: >-
    OpenAI-compatible inference for Ageneral. Base URL:
    `https://models.ageneral.ai`.


    **HTTP methods:** **GET** is allowed only for **`/v1/models`**. **POST** is
    allowed for inference routes listed in this document. Other HTTP methods
    return **405**.


    **Authentication:** Send `Authorization: Bearer <token>`. Use an **Ageneral
    virtual key** in `sk-bf-…` form for your account or project member key, or a
    **worker-plane service JWT** for private fleet requests to this host. Envoy
    **`ext_authz`** may substitute a member virtual key upstream for worker JWT
    mode. Other `sk-…` formats are rejected with **401**.


    **Spend:** Requests are subject to account and project credit limits; you
    may receive **402** when balance is exhausted.


    **Wire format:** Request and response JSON follow the same shapes as OpenAI
    **Chat Completions**, **Responses**, and **List models**. Use
    `provider/model` identifiers such as `openai/gpt-4o`. For fields not listed
    in this spec, refer to the [OpenAI API
    reference](https://platform.openai.com/docs/api-reference) for the matching
    operation.
  contact:
    name: Ageneral
    url: https://ageneral.ai
servers:
  - url: https://models.ageneral.ai
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Models
    description: Discover models available to your credentials.
  - name: Chat
    description: Multi-turn chat with SSE streaming support.
  - name: Responses
    description: >-
      OpenAI Responses–compatible API, including reasoning streams where the
      model supports them.
paths:
  /v1/chat/completions:
    post:
      tags:
        - Chat
      summary: Create chat completion
      description: >-
        Creates a chat completion. Set `stream: true` for **server-sent events**
        with content type `text/event-stream`. Body matches OpenAI **Create chat
        completion**; `model` uses `provider/model` form.
      operationId: createChatCompletion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
            examples:
              singleTurn:
                summary: Single user message
                value:
                  model: openai/gpt-4o-mini
                  messages:
                    - role: user
                      content: Say hello in one sentence.
      responses:
        '200':
          description: Success. JSON object, or `text/event-stream` when `stream` is true.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
            text/event-stream:
              schema:
                type: string
                description: SSE stream of completion chunks.
        '401':
          description: Unauthorized.
        '402':
          description: Insufficient credits.
        '503':
          description: Service unavailable when billing or inference is not configured.
      security:
        - bearerAuth: []
components:
  schemas:
    ChatCompletionRequest:
      type: object
      required:
        - model
        - messages
      description: >-
        Aligned with OpenAI Chat Completions. Optional fields such as tools,
        `stream`, and `response_format` follow the same JSON shape as OpenAI.
      properties:
        model:
          type: string
          description: Model id in `provider/model` form.
          example: openai/gpt-4o-mini
        messages:
          type: array
          description: Conversation messages.
          items:
            type: object
            additionalProperties: true
        stream:
          type: boolean
          description: If true, the response uses SSE as `text/event-stream`.
        temperature:
          type: number
        max_tokens:
          type: integer
        max_completion_tokens:
          type: integer
        tools:
          type: array
          items:
            type: object
            additionalProperties: true
        tool_choice:
          oneOf:
            - type: string
            - type: object
              additionalProperties: true
      additionalProperties: true
    ChatCompletionResponse:
      type: object
      description: OpenAI-compatible chat completion object.
      additionalProperties: true
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Ageneral virtual key as `sk-bf-…` or worker-plane JWT where configured.
        Send as `Authorization: Bearer <token>`.

````