> ## 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.

# Run a saved preset

> Chat completion using a preset's saved model, routing, system prompt, and parameters. Send only your messages; pass model/models to override the preset's chain for this call. Response headers include X-Ninja-Preset and X-Ninja-Preset-Version.



## OpenAPI

````yaml /openapi.json post /presets/{slug}/chat/completions
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:
  /presets/{slug}/chat/completions:
    post:
      summary: Run a saved preset
      description: >-
        Chat completion using a preset's saved model, routing, system prompt,
        and parameters. Send only your messages; pass model/models to override
        the preset's chain for this call. Response headers include
        X-Ninja-Preset and X-Ninja-Preset-Version.
      parameters:
        - schema:
            type: string
          required: true
          name: slug
          in: path
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PresetChatCompletionsRequest'
      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'
        '404':
          description: No active preset with that slug on this account.
          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: []
      x-codeSamples:
        - lang: javascript
          label: TypeScript SDK
          source: >-
            import { NinjaChat } from "@ninjachat/sdk";


            const client = new NinjaChat({ apiKey:
            process.env.NINJACHAT_API_KEY! });


            const completion = await client.chat.completions.create({
              model: "@support",
              messages: [{ role: "user", content: "Help me reset my workspace." }],
            });
        - lang: python
          label: Python SDK
          source: |-
            import os
            from ninjachat import NinjaChat

            client = NinjaChat(api_key=os.environ["NINJACHAT_API_KEY"])

            completion = client.chat.completions.create(
                model="@support",
                messages=[{"role": "user", "content": "Help me reset my workspace."}],
            )
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:
    PresetChatCompletionsRequest:
      type: object
      properties:
        model:
          type: string
          minLength: 1
          maxLength: 160
        models:
          type: array
          items:
            type: string
            minLength: 1
            maxLength: 160
          minItems: 1
          maxItems: 15
        messages:
          type: array
          items:
            oneOf:
              - type: object
                properties:
                  role:
                    type: string
                    enum:
                      - developer
                  content:
                    anyOf:
                      - type: string
                        minLength: 1
                      - type: array
                        items:
                          type: object
                          properties:
                            type:
                              type: string
                              enum:
                                - text
                            text:
                              type: string
                              minLength: 1
                          required:
                            - type
                            - text
                          additionalProperties: false
                        minItems: 1
                required:
                  - role
                  - content
                additionalProperties: false
              - type: object
                properties:
                  role:
                    type: string
                    enum:
                      - system
                  content:
                    anyOf:
                      - type: string
                        minLength: 1
                      - type: array
                        items:
                          type: object
                          properties:
                            type:
                              type: string
                              enum:
                                - text
                            text:
                              type: string
                              minLength: 1
                          required:
                            - type
                            - text
                          additionalProperties: false
                        minItems: 1
                required:
                  - role
                  - content
                additionalProperties: false
              - type: object
                properties:
                  role:
                    type: string
                    enum:
                      - user
                  content:
                    anyOf:
                      - type: string
                        minLength: 1
                      - type: array
                        items:
                          anyOf:
                            - type: object
                              properties:
                                type:
                                  type: string
                                  enum:
                                    - text
                                text:
                                  type: string
                                  minLength: 1
                              required:
                                - type
                                - text
                              additionalProperties: false
                            - type: object
                              properties:
                                type:
                                  type: string
                                  enum:
                                    - image_url
                                image_url:
                                  type: object
                                  properties:
                                    url:
                                      type: string
                                      minLength: 1
                                      maxLength: 7000000
                                    detail:
                                      type: string
                                      enum:
                                        - auto
                                        - low
                                        - high
                                  required:
                                    - url
                                  additionalProperties: false
                              required:
                                - type
                                - image_url
                              additionalProperties: false
                            - type: object
                              properties:
                                type:
                                  type: string
                                  enum:
                                    - file
                                file:
                                  type: object
                                  properties:
                                    filename:
                                      type: string
                                      minLength: 1
                                      maxLength: 255
                                    file_data:
                                      type: string
                                      minLength: 1
                                      maxLength: 7000000
                                    file_url:
                                      type: string
                                      maxLength: 4096
                                      format: uri
                                    media_type:
                                      type: string
                                      enum:
                                        - application/pdf
                                        - text/plain
                                        - text/markdown
                                        - text/csv
                                        - application/json
                                  additionalProperties: false
                              required:
                                - type
                                - file
                              additionalProperties: false
                        minItems: 1
                required:
                  - role
                  - content
                additionalProperties: false
              - type: object
                properties:
                  role:
                    type: string
                    enum:
                      - assistant
                  content:
                    anyOf:
                      - type: string
                        minLength: 1
                      - type: array
                        items:
                          type: object
                          properties:
                            type:
                              type: string
                              enum:
                                - text
                            text:
                              type: string
                              minLength: 1
                          required:
                            - type
                            - text
                          additionalProperties: false
                        minItems: 1
                      - type: 'null'
                  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
                additionalProperties: false
              - type: object
                properties:
                  role:
                    type: string
                    enum:
                      - tool
                  content:
                    anyOf:
                      - type: string
                      - type: array
                        items:
                          anyOf:
                            - type: object
                              properties:
                                type:
                                  type: string
                                  enum:
                                    - text
                                text:
                                  type: string
                                  minLength: 1
                              required:
                                - type
                                - text
                              additionalProperties: false
                            - type: object
                              properties:
                                type:
                                  type: string
                                  enum:
                                    - image_url
                                image_url:
                                  type: object
                                  properties:
                                    url:
                                      type: string
                                      minLength: 1
                                      maxLength: 7000000
                                    detail:
                                      type: string
                                      enum:
                                        - auto
                                        - low
                                        - high
                                  required:
                                    - url
                                  additionalProperties: false
                              required:
                                - type
                                - image_url
                              additionalProperties: false
                            - type: object
                              properties:
                                type:
                                  type: string
                                  enum:
                                    - file
                                file:
                                  type: object
                                  properties:
                                    filename:
                                      type: string
                                      minLength: 1
                                      maxLength: 255
                                    file_data:
                                      type: string
                                      minLength: 1
                                      maxLength: 7000000
                                    file_url:
                                      type: string
                                      maxLength: 4096
                                      format: uri
                                    media_type:
                                      type: string
                                      enum:
                                        - application/pdf
                                        - text/plain
                                        - text/markdown
                                        - text/csv
                                        - application/json
                                  additionalProperties: false
                              required:
                                - type
                                - file
                              additionalProperties: false
                        minItems: 1
                  tool_call_id:
                    type: string
                    minLength: 1
                    maxLength: 128
                required:
                  - role
                  - content
                  - tool_call_id
                additionalProperties: false
          minItems: 1
        max_completion_tokens:
          type: integer
          exclusiveMinimum: 0
          maximum: 9007199254740991
          description: >-
            Maximum completion tokens, including reasoning where the provider
            counts it. Must fit the selected provider's output and context
            limits. Defaults to 2048 when omitted.
        temperature:
          type: number
          minimum: 0
          maximum: 2
        top_p:
          type: number
          minimum: 0
          maximum: 1
        stop:
          anyOf:
            - type: string
            - type: array
              items:
                type: string
              minItems: 1
              maxItems: 4
        frequency_penalty:
          type: number
          minimum: -2
          maximum: 2
        presence_penalty:
          type: number
          minimum: -2
          maximum: 2
        seed:
          type: integer
        user:
          type: string
          maxLength: 256
        stream:
          type: boolean
          default: false
        stream_options:
          type: object
          properties:
            include_usage:
              type: boolean
          additionalProperties: false
        response_format:
          oneOf:
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - text
              required:
                - type
              additionalProperties: false
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - json_object
              required:
                - type
              additionalProperties: false
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - json_schema
                json_schema:
                  type: object
                  properties:
                    name:
                      type: string
                      minLength: 1
                      maxLength: 128
                    description:
                      type: string
                    schema:
                      type: object
                      additionalProperties: {}
                    strict:
                      type: boolean
                      default: true
                  required:
                    - name
                    - schema
                  additionalProperties: false
              required:
                - type
                - json_schema
              additionalProperties: false
        tools:
          type: array
          items:
            type: object
            properties:
              type:
                type: string
                enum:
                  - function
              function:
                type: object
                properties:
                  name:
                    type: string
                    minLength: 1
                    maxLength: 64
                    pattern: ^[a-zA-Z0-9_-]+$
                  description:
                    type: string
                  parameters:
                    type: object
                    additionalProperties: {}
                    default: {}
                  strict:
                    type: boolean
                required:
                  - name
                additionalProperties: false
            required:
              - type
              - function
            additionalProperties: false
        tool_choice:
          anyOf:
            - type: string
              enum:
                - none
                - auto
                - required
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - function
                function:
                  type: object
                  properties:
                    name:
                      type: string
                      minLength: 1
                      maxLength: 128
                  required:
                    - name
                  additionalProperties: false
              required:
                - type
                - function
              additionalProperties: false
        parallel_tool_calls:
          type: boolean
        reasoning:
          $ref: '#/components/schemas/ChatReasoning'
        routing:
          $ref: '#/components/schemas/RoutingPolicy'
      required:
        - messages
      additionalProperties: false
    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
    ChatReasoning:
      type: object
      properties:
        effort:
          type: string
          enum:
            - none
            - minimal
            - low
            - medium
            - high
            - xhigh
        max_tokens:
          type: integer
          minimum: 0
          maximum: 9007199254740991
        enabled:
          type: boolean
      additionalProperties: false
    RoutingPolicy:
      type: object
      properties:
        strategy:
          type: string
          enum:
            - balanced
            - cost
            - latency
            - quality
        providers:
          type: object
          properties:
            only:
              type: array
              items:
                type: string
                minLength: 1
                maxLength: 128
              minItems: 1
              maxItems: 20
            exclude:
              type: array
              items:
                type: string
                minLength: 1
                maxLength: 128
              minItems: 1
              maxItems: 20
            order:
              type: array
              items:
                type: string
                minLength: 1
                maxLength: 128
              minItems: 1
              maxItems: 20
          additionalProperties: false
        allow_fallbacks:
          type: boolean
          default: true
        require_parameters:
          type: boolean
          default: true
        data_policy:
          type: string
          enum:
            - default
            - no_training
            - zero_retention
          default: default
        caching:
          type: string
          enum:
            - auto
        max_cost_usd:
          type: number
          exclusiveMinimum: 0
          maximum: 1000
      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.

````