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

# Create a chat completion (legacy path)

> Supported compatibility surface — kept working indefinitely, but not the path for new integrations. Modern equivalent: `POST /responses`.

Backward-compatible path for /chat/completions, including historical field spellings and session memory.



## OpenAPI

````yaml /openapi.json post /chat
openapi: 3.1.0
info:
  title: NinjaChat API
  version: 1.0.0
  description: >-
    Clean-break NinjaChat v1. Chat and Responses bill actual token usage; images
    and videos use catalog unit pricing.
servers:
  - url: https://www.ninjachat.ai/api/v1
security: []
paths:
  /chat:
    post:
      summary: Create a chat completion (legacy path)
      description: >-
        Supported compatibility surface — kept working indefinitely, but not the
        path for new integrations. Modern equivalent: `POST /responses`.


        Backward-compatible path for /chat/completions, including historical
        field spellings and session memory.
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties: {}
      responses:
        '200':
          description: Chat completion or SSE stream.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
            text/event-stream:
              schema:
                type: string
        '400':
          description: Invalid or unsupported request parameter.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Missing or invalid API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '402':
          description: Insufficient balance or project spend limit reached.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: Rate limit exceeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Gateway error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - bearerAuth: []
components:
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      schema:
        type: string
        minLength: 1
        maxLength: 255
      description: >-
        Safely retry the same logical write without duplicate billing or
        execution.
  schemas:
    ChatCompletionResponse:
      type: object
      properties:
        cost:
          type: object
          properties:
            this_request:
              type: string
            per_image:
              type: string
            per_video:
              type: string
            images:
              type: integer
              minimum: 0
          required:
            - this_request
          additionalProperties: false
        balance:
          type: string
        metadata:
          type: object
          properties:
            latency_ms:
              type: number
              minimum: 0
            group:
              type: string
            search_depth:
              type: string
            results_count:
              type: integer
              minimum: 0
          required:
            - latency_ms
          additionalProperties: false
        id:
          type: string
        object:
          type: string
          enum:
            - chat.completion
        created:
          type: integer
        model:
          type: string
          minLength: 1
          maxLength: 160
        resolved_model:
          type: string
          minLength: 1
          maxLength: 160
        provider:
          type:
            - string
            - 'null'
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              message:
                type: object
                properties:
                  role:
                    type: string
                    enum:
                      - assistant
                  content:
                    type:
                      - string
                      - 'null'
                  reasoning_content:
                    type: string
                  tool_calls:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          minLength: 1
                          maxLength: 128
                        type:
                          type: string
                          enum:
                            - function
                        extra_content:
                          type: object
                          properties:
                            google:
                              type: object
                              properties:
                                thought_signature:
                                  type: string
                                  minLength: 1
                              required:
                                - thought_signature
                              additionalProperties: false
                          additionalProperties: false
                        function:
                          type: object
                          properties:
                            name:
                              type: string
                              minLength: 1
                              maxLength: 64
                            arguments:
                              type: string
                          required:
                            - name
                            - arguments
                          additionalProperties: false
                      required:
                        - id
                        - type
                        - function
                      additionalProperties: false
                required:
                  - role
                  - content
                additionalProperties: false
              finish_reason:
                type:
                  - string
                  - 'null'
            required:
              - index
              - message
              - finish_reason
            additionalProperties: false
        usage:
          $ref: '#/components/schemas/ChatUsage'
        cost_usd:
          type: number
          minimum: 0
        request_id:
          type: string
        routing:
          $ref: '#/components/schemas/RoutingSummary'
      required:
        - id
        - object
        - created
        - model
        - resolved_model
        - provider
        - choices
        - usage
        - cost_usd
        - request_id
        - routing
      additionalProperties: false
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
            code:
              type: string
            param:
              type:
                - string
                - 'null'
          required:
            - message
            - type
            - code
          additionalProperties: false
      required:
        - error
      additionalProperties: false
    ChatUsage:
      type: object
      properties:
        prompt_tokens:
          type: integer
          minimum: 0
        completion_tokens:
          type: integer
          minimum: 0
        total_tokens:
          type: integer
          minimum: 0
        prompt_tokens_details:
          type: object
          properties:
            cached_tokens:
              type: integer
              minimum: 0
            cache_creation_tokens:
              type: integer
              minimum: 0
          additionalProperties: false
        completion_tokens_details:
          type: object
          properties:
            reasoning_tokens:
              type: integer
              minimum: 0
          additionalProperties: false
      required:
        - prompt_tokens
        - completion_tokens
        - total_tokens
      additionalProperties: false
    RoutingSummary:
      type: object
      properties:
        strategy:
          type: string
          enum:
            - balanced
            - cost
            - latency
            - quality
        requested_models:
          type: array
          items:
            type: string
            minLength: 1
            maxLength: 160
        resolved_model:
          type: string
          minLength: 1
          maxLength: 160
        provider:
          type:
            - string
            - 'null'
        provider_attempts:
          type: array
          items:
            $ref: '#/components/schemas/ProviderAttemptReceipt'
        fallbacks_allowed:
          type: boolean
        data_policy:
          type: string
          enum:
            - default
            - no_training
            - zero_retention
        caching:
          type: string
          enum:
            - auto
        source:
          type: string
          enum:
            - request
            - project
            - default
        router:
          $ref: '#/components/schemas/RouterDecisionSummary'
      required:
        - strategy
        - requested_models
        - resolved_model
        - provider
        - fallbacks_allowed
        - data_policy
      additionalProperties: false
    ProviderAttemptReceipt:
      type: object
      properties:
        provider:
          type: string
        outcome:
          type: string
          enum:
            - served
            - failed_over
            - failed
        attempt_index:
          type: integer
          minimum: 0
      required:
        - provider
        - outcome
        - attempt_index
      additionalProperties: false
    RouterDecisionSummary:
      type: object
      properties:
        id:
          type: string
          enum:
            - ninja/auto
        task:
          type: string
        classified_by:
          type: string
          enum:
            - regex
            - llm
            - llm-cached
        override:
          type:
            - string
            - 'null'
          enum:
            - long_context
            - multilingual
        reasoning:
          type: string
        candidates:
          type: array
          items:
            type: string
            minLength: 1
            maxLength: 160
        considered:
          type: array
          items:
            type: object
            properties: {}
      required:
        - id
        - task
        - classified_by
        - override
        - reasoning
        - candidates
        - considered
      additionalProperties: false
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: NinjaChat API key
      description: Use an API key created in the NinjaChat developer console.

````