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

# Create a chat completion

> Generate an OpenAI-compatible chat completion from conversation messages. Supports streaming, multimodal content, structured outputs, and tool calling.



## OpenAPI

````yaml /openapi/naga-api.json post /v1/chat/completions
openapi: 3.1.0
info:
  title: NagaAI API
  summary: Unified AI API with OpenAI and Anthropic compatibility layers.
  version: '2026-03-31'
  contact:
    name: NagaAI
    url: https://naga.ac
  termsOfService: https://naga.ac/legal/terms
servers:
  - url: https://api.naga.ac
    description: Production
  - url: http://localhost:8500
    description: Local development
security: []
tags:
  - name: Chat Completions
    description: >-
      OpenAI-compatible chat completion requests, including streaming, tools,
      and multimodal input.
  - name: Messages
    description: >-
      Anthropic-compatible Messages API requests used by Claude-style clients
      and agents.
  - name: Responses
    description: >-
      OpenAI-compatible Responses API requests for structured input, tools, and
      streaming output items.
  - name: Embeddings
    description: >-
      Create vector embeddings for search, retrieval, clustering, and ranking
      use cases.
  - name: Images
    description: >-
      Generate or edit images with multimodal models and OpenAI-compatible
      payloads.
  - name: Audio
    description: >-
      Generate speech or convert uploaded audio into transcriptions and
      translations.
  - name: Moderations
    description: Classify text and image inputs for safety policy categories.
  - name: Models
    description: List available models, capabilities, and pricing metadata.
  - name: Startups
    description: >-
      Public metadata about AI startups and model providers surfaced by the
      gateway.
  - name: Account
    description: Provisioning-key protected account balance and usage endpoints.
  - name: API Keys
    description: Provisioning-key protected API key management endpoints.
paths:
  /v1/chat/completions:
    post:
      tags:
        - Chat Completions
      summary: Create a chat completion
      description: >-
        Generate an OpenAI-compatible chat completion from conversation
        messages. Supports streaming, multimodal content, structured outputs,
        and tool calling.
      operationId: createChatCompletion
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletions'
            examples:
              basic:
                summary: Basic text request
                value:
                  model: gpt-4o-mini
                  messages:
                    - role: user
                      content: Write a two-line summary of Tokyo.
                  temperature: 0.2
              tool_calling:
                summary: Tool calling request
                value:
                  model: gpt-4.1-mini
                  messages:
                    - role: user
                      content: >-
                        What is the weather in Berlin and should I bring an
                        umbrella?
                  tools:
                    - type: function
                      function:
                        name: get_weather
                        description: Look up current weather for a city.
                        parameters:
                          type: object
                          properties:
                            city:
                              type: string
                            unit:
                              type: string
                              enum:
                                - c
                                - f
                          required:
                            - city
                  tool_choice: auto
        required: true
      responses:
        '200':
          description: >-
            JSON response when stream=false, or Server-Sent Events when
            stream=true.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
            text/event-stream:
              schema:
                type: string
                description: >-
                  Server-Sent Events stream. Each data frame contains a JSON
                  object shaped like chat.completion.chunk.
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '402':
          description: Insufficient credits
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '410':
          description: Model deprecated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '422':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationErrorResponse'
        '429':
          description: Rate limited
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '503':
          description: Upstream service error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
      security:
        - bearerAuth: []
        - xApiKeyAuth: []
components:
  schemas:
    ChatCompletions:
      properties:
        model:
          type: string
          title: Model
          description: Model identifier to route the request to.
          examples:
            - gpt-4o-mini
        messages:
          items:
            $ref: '#/components/schemas/ChatMessage'
          type: array
          minItems: 1
          title: Messages
          description: Conversation history in OpenAI Chat Completions format.
        tools:
          anyOf:
            - items:
                $ref: '#/components/schemas/Tool'
              type: array
            - type: 'null'
          title: Tools
        tool_choice:
          anyOf:
            - type: string
            - additionalProperties: true
              type: object
          title: Tool Choice
        response_format:
          anyOf:
            - $ref: '#/components/schemas/TextResponseFormat'
            - $ref: '#/components/schemas/JsonObjectResponseFormat'
            - $ref: '#/components/schemas/JsonSchemaResponseFormat'
            - type: 'null'
          title: Response Format
        temperature:
          anyOf:
            - type: number
              maximum: 2
              minimum: 0
            - type: 'null'
          title: Temperature
        top_p:
          anyOf:
            - type: number
              maximum: 1
              minimum: 0
            - type: 'null'
          title: Top P
        stream:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Stream
          default: false
        stream_options:
          anyOf:
            - $ref: '#/components/schemas/StreamOptions'
            - type: 'null'
        stop:
          anyOf:
            - type: string
            - items:
                type: string
              type: array
            - type: 'null'
          title: Stop
        max_completion_tokens:
          anyOf:
            - type: integer
              minimum: 1
            - type: 'null'
          title: Max Completion Tokens
        reasoning_effort:
          type: string
          enum:
            - none
            - minimal
            - low
            - medium
            - high
            - xhigh
          title: Reasoning Effort
        presence_penalty:
          anyOf:
            - type: number
              maximum: 2
              minimum: -2
            - type: 'null'
          title: Presence Penalty
        frequency_penalty:
          anyOf:
            - type: number
              maximum: 2
              minimum: -2
            - type: 'null'
          title: Frequency Penalty
        logit_bias:
          additionalProperties: true
          type: object
          title: Logit Bias
        parallel_tool_calls:
          type: boolean
          title: Parallel Tool Calls
        prediction:
          anyOf:
            - $ref: '#/components/schemas/Prediction'
            - type: 'null'
        web_search_options:
          additionalProperties: true
          type: object
          title: Web Search Options
        image_config:
          anyOf:
            - $ref: '#/components/schemas/ImageConfig'
            - type: 'null'
      type: object
      required:
        - model
        - messages
      title: ChatCompletions
      examples:
        - messages:
            - content: You are a concise assistant.
              role: system
            - content: Summarize vector databases in 2 sentences.
              role: user
          model: gpt-4o-mini
          temperature: 0.3
    ChatCompletionResponse:
      properties:
        id:
          type: string
          title: Id
        object:
          type: string
          const: chat.completion
          title: Object
          default: chat.completion
        created:
          type: integer
          title: Created
        model:
          type: string
          title: Model
        choices:
          items:
            $ref: '#/components/schemas/ChatCompletionChoiceResponse'
          type: array
          title: Choices
        usage:
          anyOf:
            - $ref: '#/components/schemas/ChatCompletionUsageResponse'
            - type: 'null'
      additionalProperties: true
      type: object
      required:
        - id
        - created
        - model
        - choices
      title: ChatCompletionResponse
      examples:
        - choices:
            - finish_reason: stop
              index: 0
              message:
                content: >-
                  Tokyo is Japan's capital and one of the world's largest
                  metropolitan areas. It blends dense modern districts with
                  historic neighborhoods, food, and culture.
                role: assistant
          created: 1743393600
          id: chatcmpl_123
          model: gpt-4o-mini
          object: chat.completion
          usage:
            completion_tokens: 30
            completion_tokens_details:
              image_tokens: 0
            prompt_tokens: 15
            total_tokens: 45
    ErrorEnvelope:
      properties:
        error:
          $ref: '#/components/schemas/ErrorBody'
      additionalProperties: true
      type: object
      required:
        - error
      title: ErrorEnvelope
      examples:
        - error:
            message: The request body is invalid.
            type: invalid_request_error
    HTTPValidationErrorResponse:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationErrorItem'
          type: array
          title: Detail
      additionalProperties: true
      type: object
      required:
        - detail
      title: HTTPValidationErrorResponse
    ChatMessage:
      properties:
        role:
          type: string
          title: Role
          description: Message role such as system, user, assistant, or tool.
          examples:
            - user
        content:
          anyOf:
            - type: string
            - items:
                anyOf:
                  - $ref: '#/components/schemas/TextContent'
                  - $ref: '#/components/schemas/ImageContent'
                  - $ref: '#/components/schemas/FileContent'
                  - $ref: '#/components/schemas/AudioContent'
              type: array
            - type: 'null'
          title: Content
          description: >-
            Message content as a plain string or an array of multimodal content
            blocks.
        images:
          anyOf:
            - items:
                $ref: '#/components/schemas/ImageContent'
              type: array
            - type: 'null'
          title: Images
        reasoning_details:
          anyOf:
            - items:
                anyOf:
                  - $ref: '#/components/schemas/ReasoningSummary'
                  - $ref: '#/components/schemas/ReasoningEncrypted'
                  - $ref: '#/components/schemas/ReasoningText'
              type: array
            - type: 'null'
          title: Reasoning Details
        name:
          type: string
          title: Name
        tool_call_id:
          type: string
          title: Tool Call Id
        tool_calls:
          items: {}
          type: array
          title: Tool Calls
      type: object
      required:
        - role
      title: ChatMessage
    Tool:
      properties:
        type:
          type: string
          const: function
          title: Type
        function:
          $ref: '#/components/schemas/FunctionDefinition'
      type: object
      required:
        - type
        - function
      title: Tool
    TextResponseFormat:
      properties:
        type:
          type: string
          const: text
          title: Type
      type: object
      required:
        - type
      title: TextResponseFormat
    JsonObjectResponseFormat:
      properties:
        type:
          type: string
          const: json_object
          title: Type
      type: object
      required:
        - type
      title: JsonObjectResponseFormat
    JsonSchemaResponseFormat:
      properties:
        type:
          type: string
          const: json_schema
          title: Type
        json_schema:
          $ref: '#/components/schemas/JsonSchemaConfig'
      type: object
      required:
        - type
        - json_schema
      title: JsonSchemaResponseFormat
    StreamOptions:
      properties:
        include_usage:
          type: boolean
          title: Include Usage
          description: Include usage in the final streaming chunk.
      type: object
      title: StreamOptions
    Prediction:
      properties:
        static_content:
          anyOf:
            - $ref: '#/components/schemas/StaticContent'
            - type: 'null'
      type: object
      title: Prediction
    ImageConfig:
      properties:
        aspect_ratio:
          anyOf:
            - type: string
              enum:
                - '1:1'
                - '1:4'
                - '1:8'
                - '2:3'
                - '3:2'
                - '3:4'
                - '4:1'
                - '4:3'
                - '4:5'
                - '5:4'
                - '8:1'
                - '9:16'
                - '16:9'
                - '21:9'
            - type: 'null'
          title: Aspect Ratio
        image_size:
          anyOf:
            - type: string
              enum:
                - 1K
                - 2K
                - 4K
            - type: 'null'
          title: Image Size
      type: object
      title: ImageConfig
    ChatCompletionChoiceResponse:
      properties:
        index:
          type: integer
          title: Index
          default: 0
        message:
          $ref: '#/components/schemas/ChatCompletionMessageResponse'
        finish_reason:
          anyOf:
            - type: string
            - type: 'null'
          title: Finish Reason
        logprobs:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Logprobs
      additionalProperties: true
      type: object
      required:
        - message
      title: ChatCompletionChoiceResponse
    ChatCompletionUsageResponse:
      properties:
        prompt_tokens:
          type: integer
          title: Prompt Tokens
        completion_tokens:
          type: integer
          title: Completion Tokens
        total_tokens:
          type: integer
          title: Total Tokens
        prompt_tokens_details:
          anyOf:
            - $ref: '#/components/schemas/ChatPromptTokensDetailsResponse'
            - type: 'null'
        completion_tokens_details:
          anyOf:
            - $ref: '#/components/schemas/ChatCompletionTokensDetailsResponse'
            - type: 'null'
      additionalProperties: true
      type: object
      required:
        - prompt_tokens
        - completion_tokens
        - total_tokens
      title: ChatCompletionUsageResponse
    ErrorBody:
      properties:
        type:
          type: string
          title: Type
          description: Stable machine-readable error type.
        message:
          type: string
          title: Message
          description: Human-readable error message.
        code:
          anyOf:
            - type: string
            - type: integer
            - type: 'null'
          title: Code
        param:
          anyOf:
            - type: string
            - type: 'null'
          title: Param
      additionalProperties: true
      type: object
      required:
        - type
        - message
      title: ErrorBody
    ValidationErrorItem:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Loc
        msg:
          type: string
          title: Msg
        type:
          type: string
          title: Type
      additionalProperties: true
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationErrorItem
    TextContent:
      properties:
        type:
          type: string
          const: text
          title: Type
        text:
          type: string
          title: Text
          description: Plain text content block.
          examples:
            - Write a haiku about distributed systems.
      type: object
      required:
        - type
        - text
      title: TextContent
    ImageContent:
      properties:
        type:
          type: string
          const: image_url
          title: Type
        image_url:
          $ref: '#/components/schemas/app__api__v1__chat__completions__ImageUrl'
      type: object
      required:
        - type
        - image_url
      title: ImageContent
    FileContent:
      properties:
        type:
          type: string
          const: file
          title: Type
        file:
          $ref: '#/components/schemas/File'
      type: object
      required:
        - type
        - file
      title: FileContent
    AudioContent:
      properties:
        type:
          type: string
          const: input_audio
          title: Type
        input_audio:
          $ref: '#/components/schemas/InputAudio'
      type: object
      required:
        - type
        - input_audio
      title: AudioContent
    ReasoningSummary:
      properties:
        id:
          anyOf:
            - type: string
            - type: 'null'
          title: Id
        index:
          anyOf:
            - type: integer
            - type: 'null'
          title: Index
        type:
          type: string
          const: reasoning.summary
          title: Type
        summary:
          type: string
          title: Summary
      type: object
      required:
        - type
        - summary
      title: ReasoningSummary
    ReasoningEncrypted:
      properties:
        id:
          anyOf:
            - type: string
            - type: 'null'
          title: Id
        index:
          anyOf:
            - type: integer
            - type: 'null'
          title: Index
        type:
          type: string
          const: reasoning.encrypted
          title: Type
        data:
          type: string
          title: Data
      type: object
      required:
        - type
        - data
      title: ReasoningEncrypted
    ReasoningText:
      properties:
        id:
          anyOf:
            - type: string
            - type: 'null'
          title: Id
        index:
          anyOf:
            - type: integer
            - type: 'null'
          title: Index
        type:
          type: string
          const: reasoning.text
          title: Type
        text:
          type: string
          title: Text
      type: object
      required:
        - type
        - text
      title: ReasoningText
    FunctionDefinition:
      properties:
        name:
          type: string
          title: Name
          description: Function name exposed to the model.
          examples:
            - get_weather
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
        parameters:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Parameters
        strict:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Strict
      type: object
      required:
        - name
      title: FunctionDefinition
    JsonSchemaConfig:
      properties:
        name:
          type: string
          title: Name
          description: Name of the JSON schema response format.
          examples:
            - calendar_event
        description:
          type: string
          title: Description
        schema:
          additionalProperties: true
          type: object
          title: Schema
        strict:
          type: boolean
          title: Strict
      type: object
      required:
        - name
      title: JsonSchemaConfig
    StaticContent:
      properties:
        content:
          anyOf:
            - type: string
            - items: {}
              type: array
          title: Content
        type:
          type: string
          title: Type
      type: object
      required:
        - content
        - type
      title: StaticContent
    ChatCompletionMessageResponse:
      properties:
        role:
          type: string
          title: Role
        content:
          anyOf:
            - type: string
            - items:
                additionalProperties: true
                type: object
              type: array
            - type: 'null'
          title: Content
        refusal:
          anyOf:
            - type: string
            - type: 'null'
          title: Refusal
        tool_calls:
          anyOf:
            - items:
                $ref: '#/components/schemas/ChatCompletionToolCallResponse'
              type: array
            - type: 'null'
          title: Tool Calls
        annotations:
          anyOf:
            - items:
                additionalProperties: true
                type: object
              type: array
            - type: 'null'
          title: Annotations
        reasoning_content:
          anyOf:
            - type: string
            - type: 'null'
          title: Reasoning Content
        reasoning_details:
          anyOf:
            - items:
                additionalProperties: true
                type: object
              type: array
            - type: 'null'
          title: Reasoning Details
        images:
          anyOf:
            - items:
                additionalProperties: true
                type: object
              type: array
            - type: 'null'
          title: Images
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
        tool_call_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Tool Call Id
      additionalProperties: true
      type: object
      required:
        - role
      title: ChatCompletionMessageResponse
    ChatPromptTokensDetailsResponse:
      properties:
        cached_tokens:
          anyOf:
            - type: integer
            - type: 'null'
          title: Cached Tokens
      additionalProperties: true
      type: object
      title: ChatPromptTokensDetailsResponse
    ChatCompletionTokensDetailsResponse:
      properties:
        image_tokens:
          anyOf:
            - type: integer
            - type: 'null'
          title: Image Tokens
      additionalProperties: true
      type: object
      title: ChatCompletionTokensDetailsResponse
    app__api__v1__chat__completions__ImageUrl:
      properties:
        url:
          type: string
          minLength: 1
          format: uri
          title: Url
          description: Remote URL or data URI for an input image.
          examples:
            - https://example.com/receipt.png
        detail:
          type: string
          enum:
            - low
            - high
            - auto
          title: Detail
          default: low
      type: object
      required:
        - url
      title: ImageUrl
    File:
      properties:
        filename:
          type: string
          title: Filename
          description: Filename associated with the uploaded or referenced file.
          examples:
            - report.pdf
        file_data:
          type: string
          minLength: 1
          format: uri
          title: File Data
          description: Remote URL or data URI for the file payload.
          examples:
            - https://example.com/report.pdf
      type: object
      required:
        - filename
        - file_data
      title: File
    InputAudio:
      properties:
        data:
          type: string
          title: Data
          description: Raw base64 encoded string (not a Data URI)
          examples:
            - UklGRiQAAABXQVZFZm10IBAAAAABAAEAIlYAAESsAAACABAAZGF0YQAAAAA=
        format:
          type: string
          enum:
            - wav
            - mp3
          title: Format
          description: Audio encoding for the raw base64 payload.
          examples:
            - wav
      type: object
      required:
        - data
        - format
      title: InputAudio
    ChatCompletionToolCallResponse:
      properties:
        id:
          anyOf:
            - type: string
            - type: 'null'
          title: Id
        type:
          type: string
          const: function
          title: Type
          default: function
        function:
          $ref: '#/components/schemas/ChatCompletionFunctionCallResponse'
      additionalProperties: true
      type: object
      required:
        - function
      title: ChatCompletionToolCallResponse
    ChatCompletionFunctionCallResponse:
      properties:
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
        arguments:
          type: string
          title: Arguments
          default: ''
      additionalProperties: true
      type: object
      title: ChatCompletionFunctionCallResponse
  securitySchemes:
    bearerAuth:
      type: http
      description: >-
        Primary authentication for inference endpoints. Send your Naga API key
        as `Authorization: Bearer <api-key>`.
      scheme: bearer
    xApiKeyAuth:
      type: apiKey
      description: >-
        Alternate authentication for inference endpoints. Useful for clients
        that send `x-api-key: <api-key>`.
      in: header
      name: x-api-key

````