openapi: 3.0.3
info:
  title: NeverRefuse API
  version: "1.0.0"
  description: |
    OpenAI-compatible API for curated refusal-reduced weights.
    Keys: https://neverrefuse.com/console/keys
    Human docs: https://neverrefuse.com/docs/quickstart
servers:
  - url: https://api.neverrefuse.com/v1
    description: Production API (path includes /v1)
paths:
  /chat/completions:
    post:
      operationId: createChatCompletion
      summary: Create a chat completion
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ChatCompletionRequest"
      responses:
        "200":
          description: Completion (JSON or SSE stream)
        "401":
          $ref: "#/components/responses/Unauthorized"
        "402":
          $ref: "#/components/responses/InsufficientCredits"
        "429":
          $ref: "#/components/responses/RateLimited"
        "503":
          $ref: "#/components/responses/UpstreamUnavailable"
  /models:
    get:
      operationId: listModels
      summary: List hosted models
      security:
        - bearerAuth: []
      responses:
        "200":
          description: OpenAI-style model list
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ModelList"
        "401":
          $ref: "#/components/responses/Unauthorized"
  /credits:
    get:
      operationId: getCreditBalance
      summary: Credit balance for the API key owner
      security:
        - bearerAuth: []
      responses:
        "200":
          description: Balance in USD cents and dollars
        "401":
          $ref: "#/components/responses/Unauthorized"
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Console API key (Bearer)
  schemas:
    ChatCompletionRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          description: Catalog model id
          enum:
            - glm-5.3
            - deepseek-v4-flash
            - kimi-k2
            - qwen3-32b
        messages:
          type: array
          items:
            type: object
            required:
              - role
              - content
            properties:
              role:
                type: string
                enum: [system, user, assistant]
              content:
                type: string
        stream:
          type: boolean
          default: false
    ModelList:
      type: object
      properties:
        object:
          type: string
          example: list
        data:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
              object:
                type: string
              owned_by:
                type: string
              context_window:
                type: string
    CatalogPricing:
      type: object
      description: Reference pricing and context from catalog.ts (USD per 1M tokens)
      properties:
        models:
          type: object
          additionalProperties: false
          properties:
          glm-5.3:
            display_name: "GLM 5.3"
            context_window: "1M"
            input_usd_per_million: 1.2
            output_usd_per_million: 3.6
          deepseek-v4-flash:
            display_name: "DeepSeek V4 Flash"
            context_window: "1M"
            input_usd_per_million: 0.2
            output_usd_per_million: 0.8
          kimi-k2:
            display_name: "Kimi K2"
            context_window: "256K"
            input_usd_per_million: 0.6
            output_usd_per_million: 2.4
          qwen3-32b:
            display_name: "Qwen3 32B"
            context_window: "128K"
            input_usd_per_million: 0.15
            output_usd_per_million: 0.45
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
            code:
              type: string
  responses:
    Unauthorized:
      description: Missing, revoked, or invalid API key
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Error"
    InsufficientCredits:
      description: Account balance too low for the call
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Error"
    RateLimited:
      description: Per-key rate limit; honor Retry-After when present
      headers:
        Retry-After:
          schema:
            type: integer
    UpstreamUnavailable:
      description: Model temporarily unavailable
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Error"
