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

# Create a chat completion

> OpenAI-compatible chat completion. Supports streaming (SSE), tool
calling (on models with `supports_tools`), vision input (on models
with `supports_images`), and the `reasoning_effort` vendor extension
(on models with `supports_reasoning`).

**Accepted request fields are exactly the ones listed below.**
OpenAI fields not listed (`n`, `presence_penalty`, `frequency_penalty`,
`logprobs`, `seed`, `response_format`, `stream_options`) are not part
of the contract.

**BYOK model syntax** — a `model` value starting with `@` routes the
request through your own registered provider credential instead of the
Square1 pool: `@<provider>/<upstreamModelId>` or
`@<provider>:<label>/<upstreamModelId>`. See the BYOK guide.




## OpenAPI

````yaml /openapi.yaml post /v1/chat/completions
openapi: 3.1.0
info:
  title: Square1 API
  version: 1.0.0
  description: |
    OpenAI-compatible LLM gateway API.

    All endpoints live on `https://inference.square1.dev` and require a
    Square1 API key (`sq-arca-...`, or a legacy `ws-...` key) sent as a
    Bearer token.

    The wire format follows the OpenAI Chat Completions / Embeddings /
    Models conventions, with a small set of documented vendor extensions:
    the `reasoning_effort` request field, the `reasoning` delta/message
    field, and the `wellspring` quota-receipt block on chat responses.
servers:
  - url: https://inference.square1.dev
security:
  - bearerAuth: []
tags:
  - name: Chat
    description: OpenAI-compatible chat completions.
  - name: Embeddings
    description: OpenAI-compatible embeddings.
  - name: Models
    description: The model catalog as visible to your key.
  - name: Account
    description: Read-only introspection for the authenticated key.
  - name: Illustration
    description: NovelAI-compatible synchronous image generation.
paths:
  /v1/chat/completions:
    post:
      tags:
        - Chat
      summary: Create a chat completion
      description: |
        OpenAI-compatible chat completion. Supports streaming (SSE), tool
        calling (on models with `supports_tools`), vision input (on models
        with `supports_images`), and the `reasoning_effort` vendor extension
        (on models with `supports_reasoning`).

        **Accepted request fields are exactly the ones listed below.**
        OpenAI fields not listed (`n`, `presence_penalty`, `frequency_penalty`,
        `logprobs`, `seed`, `response_format`, `stream_options`) are not part
        of the contract.

        **BYOK model syntax** — a `model` value starting with `@` routes the
        request through your own registered provider credential instead of the
        Square1 pool: `@<provider>/<upstreamModelId>` or
        `@<provider>:<label>/<upstreamModelId>`. See the BYOK guide.
      operationId: createChatCompletion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
            examples:
              basic:
                summary: Basic request
                value:
                  model: deepseek-v4-pro
                  messages:
                    - role: user
                      content: Hello!
              streaming:
                summary: Streaming with reasoning effort
                value:
                  model: deepseek-v4-pro
                  stream: true
                  reasoning_effort: high
                  messages:
                    - role: system
                      content: You are a helpful assistant.
                    - role: user
                      content: Explain quicksort.
      responses:
        '200':
          description: |
            Completion result.

            With `stream: false` the body is a single JSON object that carries
            the exact post-request quota receipt in the `wellspring` block.

            With `stream: true` the body is a Server-Sent Events stream of
            `data:` lines, each a `ChatCompletionChunk` JSON object. The
            stream may interleave SSE comment lines (`: ping`) as keep-alive
            when the upstream is idle for more than 8 seconds — clients must
            ignore them. The final frames are: a chunk carrying `usage` and
            the `wellspring` receipt, then `data: [DONE]`.
          headers:
            x-sq1-request-id:
              description: Correlation ID present on every response.
              schema:
                type: string
            x-request-id:
              description: >
                The request-log ID of this completion (distinct from
                `x-sq1-request-id`).
              schema:
                type: string
            x-ratelimit-limit-requests:
              description: Your per-model requests-per-minute limit.
              schema:
                type: integer
            x-ratelimit-remaining-requests:
              description: Requests remaining in the current minute window.
              schema:
                type: integer
            x-ratelimit-reset-requests:
              description: Seconds until the RPM window resets.
              schema:
                type: integer
            x-session-used-pct:
              description: >
                Session pool used, percent. Exact for non-streaming responses; a
                reservation-time estimate for streaming (headers flush before
                generation finishes — the exact figure arrives in the
                `wellspring` block).
              schema:
                type: number
            x-session-remaining-pct:
              schema:
                type: number
            x-session-reset:
              description: Seconds until the session window resets (integer).
              schema:
                type: integer
            x-weekly-used-pct:
              schema:
                type: number
            x-weekly-remaining-pct:
              schema:
                type: number
            x-weekly-reset:
              description: Seconds until the weekly window resets (integer).
              schema:
                type: integer
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
            text/event-stream:
              schema:
                type: string
                description: >
                  SSE stream of `ChatCompletionChunk` JSON frames terminated by
                  `data: [DONE]`.
        '400':
          description: >
            Invalid request. Codes include `model_not_found`,
            `invalid_messages`, `invalid_json`, `input_too_long`,
            `invalid_reasoning_effort` (the message lists the values that model
            accepts), `tools_not_supported`, and `model_not_chat` (the id is an
            embedding model — use `/v1/embeddings`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          description: |
            Quota or rate limit hit. Codes:

            - `rate_limited` — per-model RPM window exceeded.
            - `abuse_cooldown` — account-level burst cooldown tripped;
              every model rejects until `resets_at`.
            - `session_exhausted` / `weekly_exhausted` — your weighted token
              pool is used up; the envelope carries an extra `resets_at`
              field (ISO 8601).
            - `model_quota_exceeded` — that model's shared daily token cap
              is spent; resets 09:00 KST.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          $ref: '#/components/responses/UpstreamError'
        '503':
          $ref: '#/components/responses/Unavailable'
        '529':
          description: >
            `model_overloaded` — that model's concurrent in-flight cap is
            saturated. Retry after the number of seconds in the message
            (typically 5).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    ChatCompletionRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          description: >
            A catalog model id from `GET /v1/models`, or a BYOK reference
            (`@provider/model` or `@provider:label/model`).
          examples:
            - deepseek-v4-pro
            - '@openai/gpt-5.1'
        messages:
          type: array
          items:
            $ref: '#/components/schemas/Message'
        stream:
          type: boolean
          default: false
        temperature:
          type: number
        max_tokens:
          type: integer
          description: |
            Output token cap. Clamped to the model's `max_output_tokens`.
        top_p:
          type: number
        stop:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
        reasoning_effort:
          type: string
          description: >
            Vendor extension for models with `supports_reasoning`. The accepted
            values are per-model (subsets of `none`, `low`, `high`, `max`); an
            unsupported value returns 400 `invalid_reasoning_effort` with the
            allowed values in the message.
        tools:
          type: array
          description: >
            Function tools (models with `supports_tools` only; otherwise 400
            `tools_not_supported`). Up to 128 tools; names must match
            `^[a-zA-Z0-9_-]{1,64}$`.
          items:
            $ref: '#/components/schemas/ToolDefinition'
        tool_choice:
          $ref: '#/components/schemas/ToolChoice'
        parallel_tool_calls:
          type: boolean
    ChatCompletionResponse:
      type: object
      required:
        - id
        - object
        - created
        - model
        - choices
        - usage
      properties:
        id:
          type: string
        object:
          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:
                type: object
                required:
                  - role
                  - content
                properties:
                  role:
                    const: assistant
                  content:
                    type:
                      - string
                      - 'null'
                  reasoning:
                    type: string
                    description: >-
                      Vendor extension — reasoning text, when the model emitted
                      any.
                  tool_calls:
                    type: array
                    items:
                      $ref: '#/components/schemas/ToolCall'
              finish_reason:
                type: string
                description: '`stop`, `length`, or `tool_calls`.'
        usage:
          $ref: '#/components/schemas/TokenUsage'
        wellspring:
          $ref: '#/components/schemas/WellspringBlock'
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - message
            - type
          properties:
            message:
              type: string
              description: |
                Human-readable description. User-facing messages are in Korean.
            type:
              type: string
              description: >
                Error family, e.g. `invalid_request_error`, `rate_limit_error`,
                `quota_exceeded`, `access_denied`, `overloaded_error`,
                `server_error`, `service_unavailable`.
            code:
              type: string
              description: Machine-readable code (see the Errors guide).
            resets_at:
              type: string
              format: date-time
              description: >
                Present on `session_exhausted`, `weekly_exhausted`, and
                `abuse_cooldown` so clients can render a countdown.
    Message:
      oneOf:
        - title: System message
          type: object
          required:
            - role
            - content
          properties:
            role:
              const: system
            content:
              oneOf:
                - type: string
                - type: array
                  items:
                    $ref: '#/components/schemas/ContentPart'
        - title: User message
          type: object
          required:
            - role
            - content
          properties:
            role:
              const: user
            content:
              oneOf:
                - type: string
                - type: array
                  items:
                    $ref: '#/components/schemas/ContentPart'
        - title: Assistant message
          type: object
          required:
            - role
            - content
          properties:
            role:
              const: assistant
            content:
              type:
                - string
                - 'null'
            tool_calls:
              type: array
              items:
                $ref: '#/components/schemas/ToolCall'
            reasoning:
              type: string
              description: Vendor extension — the model's reasoning text.
        - title: Tool result message
          type: object
          required:
            - role
            - tool_call_id
            - content
          properties:
            role:
              const: tool
            tool_call_id:
              type: string
            content:
              type: string
    ToolDefinition:
      type: object
      required:
        - type
        - function
      properties:
        type:
          const: function
        function:
          type: object
          required:
            - name
          properties:
            name:
              type: string
              pattern: ^[a-zA-Z0-9_-]{1,64}$
            description:
              type: string
            parameters:
              type: object
              description: JSON Schema for the arguments.
            strict:
              type: boolean
    ToolChoice:
      oneOf:
        - type: string
          enum:
            - auto
            - required
            - none
        - type: object
          required:
            - type
            - function
          properties:
            type:
              const: function
            function:
              type: object
              required:
                - name
              properties:
                name:
                  type: string
    ToolCall:
      type: object
      required:
        - id
        - type
        - function
      properties:
        id:
          type: string
          description: Always `call_` followed by 32 hex characters.
        type:
          const: function
        function:
          type: object
          required:
            - name
            - arguments
          properties:
            name:
              type: string
            arguments:
              type: string
              description: JSON-encoded argument object.
    TokenUsage:
      type: object
      required:
        - prompt_tokens
        - completion_tokens
        - total_tokens
      properties:
        prompt_tokens:
          type: integer
        completion_tokens:
          type: integer
        total_tokens:
          type: integer
    WellspringBlock:
      type: object
      description: |
        Per-request quota receipt (vendor extension, sibling of `usage`).
        Exact post-request figures — unlike the response headers, which are
        reservation-time estimates on streaming requests. In streams it
        arrives as its own frame immediately before `data: [DONE]`.
        This block is best-effort: on internal failure it is omitted rather
        than failing the request.
      required:
        - request_id
        - session
        - weekly
        - rpm
      properties:
        request_id:
          type: string
        session:
          $ref: '#/components/schemas/WellspringPool'
        weekly:
          $ref: '#/components/schemas/WellspringPool'
        rpm:
          type: object
          required:
            - limit
            - remaining
          properties:
            limit:
              type: integer
            remaining:
              type: integer
    ContentPart:
      type: object
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - text
            - image_url
        text:
          type: string
        image_url:
          type: object
          properties:
            url:
              type: string
              description: HTTPS URL or `data:` URI.
            detail:
              type: string
              enum:
                - auto
                - low
                - high
    WellspringPool:
      type: object
      required:
        - used_pct
        - remaining_pct
        - resets_at
        - resets_in_seconds
      properties:
        request_pct:
          type: number
          description: >
            This request's share of the pool, percent (2 decimals). Only present
            when the account's plan surfaces it.
        used_pct:
          type: number
        remaining_pct:
          type: number
        resets_at:
          type:
            - string
            - 'null'
          format: date-time
        resets_in_seconds:
          type: integer
  responses:
    Unauthorized:
      description: '`invalid_api_key` — missing, malformed, or revoked key.'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Forbidden:
      description: >
        Access denied. Codes include `geo_restricted` (service is
        region-locked), `account_unlinked` (community re-verification required —
        visit the dashboard), `legacy_account_upgrade_required` (finish the
        account upgrade in the dashboard), `guest_expired`, and `email_required`
        (when email enforcement is enabled).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    UpstreamError:
      description: >
        `upstream_error` (and related codes) — the model service failed. Square1
        uses HTTP 500 for upstream failures (never 502).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unavailable:
      description: >
        Service unavailable. Codes: `maintenance` (operator maintenance window),
        `model_disabled` (operator turned this model off), `server_draining`
        (restart in progress — retry shortly).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >
        A Square1 API key: `Authorization: Bearer sq-arca-...` (legacy `ws-...`
        keys remain valid). Create and rotate keys from the dashboard.

````