openapi: 3.1.0
info:
  title: Prism Inference API
  version: 0.1.0
  description: OpenAI Chat Completions and Anthropic Messages compatible inference.
  license:
    name: Proprietary
    identifier: LicenseRef-Proprietary
servers:
  - url: https://api.prisminference.com
security:
  - BearerAuth: []
  - ApiKeyAuth: []
tags:
  - name: OpenAI
    description: OpenAI-compatible inference.
  - name: Models
    description: OpenAI-compatible model discovery.
  - name: Anthropic
    description: Anthropic-compatible inference.
paths:
  /v1/chat/completions:
    post:
      tags:
        - OpenAI
      summary: Create a chat completion
      operationId: createChatCompletion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
      responses:
        '200':
          description: A completion or Server-Sent Event stream.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletion'
            text/event-stream:
              schema:
                type: string
        '400':
          $ref: '#/components/responses/OpenAIError'
        '401':
          $ref: '#/components/responses/OpenAIError'
        '413':
          $ref: '#/components/responses/OpenAIError'
        '429':
          $ref: '#/components/responses/OpenAIError'
        default:
          $ref: '#/components/responses/OpenAIError'
  /v1/models:
    get:
      tags:
        - Models
      summary: List models
      operationId: listModels
      responses:
        '200':
          description: Models available to the authenticated API key.
          content:
            application/json:
              schema:
                type: object
                required:
                  - object
                  - data
                properties:
                  object:
                    type: string
                    const: list
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Model'
        '401':
          $ref: '#/components/responses/OpenAIError'
        default:
          $ref: '#/components/responses/OpenAIError'
  /v1/models/{model}:
    get:
      tags:
        - Models
      summary: Retrieve a model
      operationId: retrieveModel
      parameters:
        - name: model
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: The requested model.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Model'
        '401':
          $ref: '#/components/responses/OpenAIError'
        '404':
          $ref: '#/components/responses/OpenAIError'
        default:
          $ref: '#/components/responses/OpenAIError'
  /v1/messages:
    post:
      tags:
        - Anthropic
      summary: Create a message
      operationId: createMessage
      parameters:
        - $ref: '#/components/parameters/AnthropicVersion'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MessageRequest'
      responses:
        '200':
          description: A message or Anthropic event stream.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Message'
            text/event-stream:
              schema:
                type: string
        '400':
          $ref: '#/components/responses/AnthropicError'
        '401':
          $ref: '#/components/responses/AnthropicError'
        '413':
          $ref: '#/components/responses/AnthropicError'
        '429':
          $ref: '#/components/responses/AnthropicError'
        default:
          $ref: '#/components/responses/AnthropicError'
  /v1/messages/count_tokens:
    post:
      tags:
        - Anthropic
      summary: Count input tokens
      operationId: countMessageTokens
      parameters:
        - $ref: '#/components/parameters/AnthropicVersion'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TokenCountRequest'
      responses:
        '200':
          description: Input token count.
          content:
            application/json:
              schema:
                type: object
                required:
                  - input_tokens
                properties:
                  input_tokens:
                    type: integer
                    minimum: 0
        '400':
          $ref: '#/components/responses/AnthropicError'
        '401':
          $ref: '#/components/responses/AnthropicError'
        '413':
          $ref: '#/components/responses/AnthropicError'
        '429':
          $ref: '#/components/responses/AnthropicError'
        default:
          $ref: '#/components/responses/AnthropicError'
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
  parameters:
    AnthropicVersion:
      name: anthropic-version
      in: header
      required: true
      schema:
        type: string
        default: '2023-06-01'
  responses:
    OpenAIError:
      description: OpenAI-compatible error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OpenAIError'
    AnthropicError:
      description: Anthropic-compatible error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/AnthropicError'
  schemas:
    ModelId:
      type: string
      enum:
        - prism-glm53
        - prism-kimik3
        - prism-qwen
        - prism-minimax
        - prism-dsv4flash
    ChatCompletionRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          $ref: '#/components/schemas/ModelId'
        messages:
          type: array
          minItems: 1
          items:
            $ref: '#/components/schemas/ChatMessage'
        stream:
          type: boolean
          default: false
        stream_options:
          type: object
          properties:
            include_usage:
              type: boolean
        max_tokens:
          type: integer
          minimum: 1
        temperature:
          type: number
          minimum: 0
          maximum: 2
        top_p:
          type: number
          minimum: 0
          maximum: 1
        stop:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
        tools:
          type: array
          items:
            $ref: '#/components/schemas/OpenAITool'
        tool_choice: {}
        response_format:
          type: object
          additionalProperties: true
        reasoning:
          type: object
          properties:
            effort:
              type: string
              enum:
                - low
                - medium
                - high
        prompt_cache_key:
          type: string
          maxLength: 512
        cache_ttl:
          type: string
          enum:
            - 5m
            - 30m
            - 1h
            - 6h
            - 24h
      additionalProperties: true
    ChatMessage:
      type: object
      required:
        - role
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - tool
        content:
          oneOf:
            - type: string
            - type: array
              items:
                type: object
                additionalProperties: true
            - type: 'null'
        name:
          type: string
        tool_call_id:
          type: string
        tool_calls:
          type: array
          items:
            $ref: '#/components/schemas/OpenAIToolCall'
      additionalProperties: true
    OpenAITool:
      type: object
      required:
        - type
        - function
      properties:
        type:
          type: string
          const: function
        function:
          type: object
          required:
            - name
            - parameters
          properties:
            name:
              type: string
            description:
              type: string
            parameters:
              type: object
              additionalProperties: true
            strict:
              type: boolean
    OpenAIToolCall:
      type: object
      required:
        - id
        - type
        - function
      properties:
        id:
          type: string
        type:
          type: string
          const: function
        function:
          type: object
          required:
            - name
            - arguments
          properties:
            name:
              type: string
            arguments:
              type: string
    ChatCompletion:
      type: object
      required:
        - id
        - object
        - created
        - model
        - choices
      properties:
        id:
          type: string
        object:
          type: string
          const: chat.completion
        created:
          type: integer
        model:
          type: string
        choices:
          type: array
          items:
            type: object
            required:
              - index
              - message
              - finish_reason
            properties:
              index:
                type: integer
              message:
                $ref: '#/components/schemas/ChatMessage'
              finish_reason:
                type:
                  - string
                  - 'null'
        usage:
          $ref: '#/components/schemas/OpenAIUsage'
    OpenAIUsage:
      type: object
      required:
        - prompt_tokens
        - completion_tokens
        - total_tokens
      properties:
        prompt_tokens:
          type: integer
        completion_tokens:
          type: integer
        total_tokens:
          type: integer
    Model:
      type: object
      required:
        - id
        - object
        - created
        - owned_by
      properties:
        id:
          type: string
        object:
          type: string
          const: model
        created:
          type: integer
        owned_by:
          type: string
    MessageRequest:
      type: object
      required:
        - model
        - max_tokens
        - messages
      properties:
        model:
          $ref: '#/components/schemas/ModelId'
        max_tokens:
          type: integer
          minimum: 1
        messages:
          type: array
          minItems: 1
          items:
            $ref: '#/components/schemas/AnthropicInputMessage'
        system:
          oneOf:
            - type: string
            - type: array
              items:
                type: object
                additionalProperties: true
        stream:
          type: boolean
          default: false
        temperature:
          type: number
          minimum: 0
          maximum: 1
        top_p:
          type: number
          minimum: 0
          maximum: 1
        stop_sequences:
          type: array
          items:
            type: string
        tools:
          type: array
          items:
            $ref: '#/components/schemas/AnthropicTool'
        tool_choice:
          type: object
          additionalProperties: true
        thinking:
          type: object
          additionalProperties: true
      additionalProperties: true
    TokenCountRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          $ref: '#/components/schemas/ModelId'
        messages:
          type: array
          minItems: 1
          items:
            $ref: '#/components/schemas/AnthropicInputMessage'
        system:
          oneOf:
            - type: string
            - type: array
              items:
                type: object
                additionalProperties: true
        tools:
          type: array
          items:
            $ref: '#/components/schemas/AnthropicTool'
      additionalProperties: true
    AnthropicInputMessage:
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - user
            - assistant
        content:
          oneOf:
            - type: string
            - type: array
              items:
                type: object
                additionalProperties: true
    AnthropicTool:
      type: object
      required:
        - name
        - input_schema
      properties:
        name:
          type: string
        description:
          type: string
        input_schema:
          type: object
          additionalProperties: true
    Message:
      type: object
      required:
        - id
        - type
        - role
        - model
        - content
        - stop_reason
        - usage
      properties:
        id:
          type: string
        type:
          type: string
          const: message
        role:
          type: string
          const: assistant
        model:
          type: string
        content:
          type: array
          items:
            type: object
            additionalProperties: true
        stop_reason:
          type:
            - string
            - 'null'
        stop_sequence:
          type:
            - string
            - 'null'
        usage:
          type: object
          required:
            - input_tokens
            - output_tokens
          properties:
            input_tokens:
              type: integer
            output_tokens:
              type: integer
          additionalProperties: true
    OpenAIError:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - message
            - code
          properties:
            message:
              type: string
            type:
              type: string
            param:
              type:
                - string
                - 'null'
            code:
              type: string
    AnthropicError:
      type: object
      required:
        - type
        - error
      properties:
        type:
          type: string
          const: error
        error:
          type: object
          required:
            - type
            - message
          properties:
            type:
              type: string
            message:
              type: string
