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

# Create chat completion

> OpenRouter/OpenAI-compatible chat completions invocation.



## OpenAPI

````yaml /openapi/v0-api/public.openapi.yaml post /api/v1/chat/completions
openapi: 3.1.0
info:
  title: MyRouter V0 Public API
  version: 0.1.0
  description: >-
    Customer-facing MyRouter V0 API. Core paths follow OpenRouter where
    possible; billing is a MyRouter extension using Stripe-style resource
    naming.
  license:
    name: Proprietary
    identifier: LicenseRef-Proprietary
  x-platform-contract-commit: 56b047ef2c076be151e090aa4e2f5e974180ea14
  x-phase-sources:
    - phase1/2026-05-28-source-inventory.md
    - phase8/2026-05-28-public-v0-api-review-matrix.md
servers:
  - url: https://api.myrouter.example
    description: Placeholder until public environment is finalized.
security:
  - bearerApiKey: []
paths:
  /api/v1/chat/completions:
    post:
      tags:
        - Runtime
      summary: Create chat completion
      description: OpenRouter/OpenAI-compatible chat completions invocation.
      operationId: createChatCompletion
      parameters:
        - $ref: '#/components/parameters/RequestIdHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
      responses:
        '200':
          description: Create chat completion response.
          headers:
            x-request-id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  parameters:
    RequestIdHeader:
      name: x-request-id
      in: header
      required: false
      schema:
        type: string
      description: Optional caller request id.
      x-source: Platform error contracts and product API convention
      x-owner: shared
      x-status: product-to-build
      x-platform-dependency: Platform runtime errors and product API errors
      x-rationale: Every API needs a stable supportable error envelope with request id.
  schemas:
    ChatCompletionRequest:
      type: object
      additionalProperties: true
      required:
        - model
        - messages
      properties:
        model:
          type: string
          description: Public MyRouter model id visible from /models.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
        messages:
          type: array
          items:
            $ref: '#/components/schemas/OpenAIMessage'
          description: Ordered OpenAI-compatible messages.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
          minItems: 1
        stream:
          type: boolean
          description: Whether to stream server-sent events.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
        max_tokens:
          type: integer
          description: Maximum output tokens.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
          minimum: 1
        temperature:
          type: number
          description: Sampling temperature.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
          minimum: 0
          maximum: 2
        top_p:
          type: number
          description: Nucleus sampling value.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
          minimum: 0
          maximum: 1
        tools:
          type: array
          items:
            type: object
            additionalProperties: true
          description: OpenAI-compatible tool definitions.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
        tool_choice:
          oneOf:
            - type: string
            - type: object
              additionalProperties: true
          description: Tool selection policy.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
        response_format:
          type: object
          description: Structured response format options.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
          additionalProperties: true
        user:
          type: string
          description: Customer end-user correlation id, not MyRouter principal.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
      x-source: >-
        OpenRouter /chat/completions plus platform OpenAI-compatible
        invocation@56b047e
      x-owner: platform
      x-status: current-platform-supported
      x-platform-dependency: Platform OpenAI-compatible chat completions
      x-rationale: >-
        Primary public runtime API follows OpenRouter path while runtime
        implementation remains platform-owned.
    ChatCompletionResponse:
      type: object
      additionalProperties: false
      required:
        - id
        - object
        - created
        - model
        - choices
      properties:
        id:
          type: string
          description: Platform-generated completion id.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
        object:
          type: string
          description: OpenAI-compatible object discriminator.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
        created:
          type: integer
          description: Unix timestamp.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
        model:
          type: string
          description: Model id used.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
        choices:
          type: array
          items:
            $ref: '#/components/schemas/OpenAIChoice'
          description: Completion choices.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
        usage:
          $ref: '#/components/schemas/TokenUsage'
          description: Runtime usage facts, not invoice-grade charge evidence.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
      x-source: >-
        OpenRouter /chat/completions plus platform OpenAI-compatible
        invocation@56b047e
      x-owner: platform
      x-status: current-platform-supported
      x-platform-dependency: Platform OpenAI-compatible chat completions
      x-rationale: >-
        Primary public runtime API follows OpenRouter path while runtime
        implementation remains platform-owned.
    OpenAIMessage:
      type: object
      additionalProperties: false
      required:
        - role
        - content
      properties:
        role:
          type: string
          description: Message role.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
          enum:
            - system
            - developer
            - user
            - assistant
            - tool
        content:
          oneOf:
            - type: string
            - type: array
              items:
                type: object
                additionalProperties: true
          description: Message content.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
        name:
          type: string
          description: Optional participant name.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
        tool_call_id:
          type: string
          description: Tool call id for tool result messages.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
      x-source: >-
        OpenRouter /chat/completions plus platform OpenAI-compatible
        invocation@56b047e
      x-owner: platform
      x-status: current-platform-supported
      x-platform-dependency: Platform OpenAI-compatible chat completions
      x-rationale: >-
        Primary public runtime API follows OpenRouter path while runtime
        implementation remains platform-owned.
    OpenAIChoice:
      type: object
      additionalProperties: false
      required:
        - index
        - message
      properties:
        index:
          type: integer
          description: Choice index.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
        message:
          $ref: '#/components/schemas/OpenAIMessage'
          description: Assistant message.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
        finish_reason:
          type: string
          description: Reason generation stopped.
          x-source: >-
            OpenRouter /chat/completions plus platform OpenAI-compatible
            invocation@56b047e
          x-owner: platform
          x-status: current-platform-supported
          x-platform-dependency: Platform OpenAI-compatible chat completions
          x-rationale: >-
            Primary public runtime API follows OpenRouter path while runtime
            implementation remains platform-owned.
      x-source: >-
        OpenRouter /chat/completions plus platform OpenAI-compatible
        invocation@56b047e
      x-owner: platform
      x-status: current-platform-supported
      x-platform-dependency: Platform OpenAI-compatible chat completions
      x-rationale: >-
        Primary public runtime API follows OpenRouter path while runtime
        implementation remains platform-owned.
    TokenUsage:
      type: object
      additionalProperties: false
      required: []
      properties:
        input_tokens:
          type: integer
          description: Input token count when available.
          x-source: >-
            OpenAI/Anthropic usage report pattern plus June 4 platform usage
            aggregation
          x-owner: shared
          x-status: june-4-dependent
          x-platform-dependency: >-
            Platform usage aggregation by API key/account with 5-minute
            granularity
          x-rationale: >-
            Usage reports expose physical meters only, not customer charge
            amounts.
          minimum: 0
        output_tokens:
          type: integer
          description: Output token count when available.
          x-source: >-
            OpenAI/Anthropic usage report pattern plus June 4 platform usage
            aggregation
          x-owner: shared
          x-status: june-4-dependent
          x-platform-dependency: >-
            Platform usage aggregation by API key/account with 5-minute
            granularity
          x-rationale: >-
            Usage reports expose physical meters only, not customer charge
            amounts.
          minimum: 0
        total_tokens:
          type: integer
          description: Total token count when available.
          x-source: >-
            OpenAI/Anthropic usage report pattern plus June 4 platform usage
            aggregation
          x-owner: shared
          x-status: june-4-dependent
          x-platform-dependency: >-
            Platform usage aggregation by API key/account with 5-minute
            granularity
          x-rationale: >-
            Usage reports expose physical meters only, not customer charge
            amounts.
          minimum: 0
        cache_read_tokens:
          type: integer
          description: Cache-read token count when available.
          x-source: >-
            OpenAI/Anthropic usage report pattern plus June 4 platform usage
            aggregation
          x-owner: shared
          x-status: june-4-dependent
          x-platform-dependency: >-
            Platform usage aggregation by API key/account with 5-minute
            granularity
          x-rationale: >-
            Usage reports expose physical meters only, not customer charge
            amounts.
          minimum: 0
        cache_write_tokens:
          type: integer
          description: Cache-write token count when available.
          x-source: >-
            OpenAI/Anthropic usage report pattern plus June 4 platform usage
            aggregation
          x-owner: shared
          x-status: june-4-dependent
          x-platform-dependency: >-
            Platform usage aggregation by API key/account with 5-minute
            granularity
          x-rationale: >-
            Usage reports expose physical meters only, not customer charge
            amounts.
          minimum: 0
        reasoning_tokens:
          type: integer
          description: Reasoning token count when available.
          x-source: >-
            OpenAI/Anthropic usage report pattern plus June 4 platform usage
            aggregation
          x-owner: shared
          x-status: june-4-dependent
          x-platform-dependency: >-
            Platform usage aggregation by API key/account with 5-minute
            granularity
          x-rationale: >-
            Usage reports expose physical meters only, not customer charge
            amounts.
          minimum: 0
      x-source: >-
        OpenAI/Anthropic usage report pattern plus June 4 platform usage
        aggregation
      x-owner: shared
      x-status: june-4-dependent
      x-platform-dependency: Platform usage aggregation by API key/account with 5-minute granularity
      x-rationale: Usage reports expose physical meters only, not customer charge amounts.
    ErrorEnvelope:
      type: object
      additionalProperties: false
      required:
        - error
        - request_id
      properties:
        error:
          type: object
          additionalProperties: false
          required:
            - code
            - message
          properties:
            code:
              type: string
              description: Stable machine-readable error code.
              x-source: Platform error contracts and product API convention
              x-owner: shared
              x-status: product-to-build
              x-platform-dependency: Platform runtime errors and product API errors
              x-rationale: >-
                Every API needs a stable supportable error envelope with request
                id.
            message:
              type: string
              description: Human-readable error message.
              x-source: Platform error contracts and product API convention
              x-owner: shared
              x-status: product-to-build
              x-platform-dependency: Platform runtime errors and product API errors
              x-rationale: >-
                Every API needs a stable supportable error envelope with request
                id.
            type:
              type: string
              description: Error category.
              x-source: Platform error contracts and product API convention
              x-owner: shared
              x-status: product-to-build
              x-platform-dependency: Platform runtime errors and product API errors
              x-rationale: >-
                Every API needs a stable supportable error envelope with request
                id.
          x-source: Platform error contracts and product API convention
          x-owner: shared
          x-status: product-to-build
          x-platform-dependency: Platform runtime errors and product API errors
          x-rationale: Every API needs a stable supportable error envelope with request id.
        request_id:
          type: string
          description: Effective request id for support.
          x-source: Platform error contracts and product API convention
          x-owner: shared
          x-status: product-to-build
          x-platform-dependency: Platform runtime errors and product API errors
          x-rationale: Every API needs a stable supportable error envelope with request id.
      x-source: Platform error contracts and product API convention
      x-owner: shared
      x-status: product-to-build
      x-platform-dependency: Platform runtime errors and product API errors
      x-rationale: Every API needs a stable supportable error envelope with request id.
  headers:
    RequestId:
      schema:
        type: string
      description: Effective request id.
      x-source: Platform error contracts and product API convention
      x-owner: shared
      x-status: product-to-build
      x-platform-dependency: Platform runtime errors and product API errors
      x-rationale: Every API needs a stable supportable error envelope with request id.
  responses:
    BadRequest:
      description: Invalid request.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    Unauthorized:
      description: Missing or invalid authentication.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    Forbidden:
      description: Authenticated principal is not allowed.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    NotFound:
      description: Resource not found.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    RateLimited:
      description: Rate limit exceeded.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    InternalError:
      description: Internal error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
  securitySchemes:
    bearerApiKey:
      type: http
      scheme: bearer
      bearerFormat: MyRouter API key

````