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

# Create chat completion

> Chat completion on the OpenRouter-compatible /api/v1 base. The same engine as POST /v1/chat/completions, with OpenRouter’s error envelope.


## OpenAPI

```yaml openapi.json post /api/v1/chat/completions
openapi: 3.1.0
info:
  title: Ocean One API
  version: 2.3.1
servers:
  - url: https://api.plungeai.com
paths:
  /api/v1/chat/completions:
    post:
      operationId: post-api-v1-chat-completions
      tags:
        - Compat
      summary: "Chat completion (proxied to inference-gateway). Phase 2: models[]/sort ordered fallback with retry + 30s outage exclusion, @preset/<slug>, guardrails, opt-in response cache."
      security:
        - ozkBearer: []
        - skOcean: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ChatCompletionRequest"
      responses:
        "200":
          description: Completion (model = the slug that actually served it, not necessarily the one requested). stream:true returns text/event-stream instead — see the developer guide for the streaming caveat.
          headers:
            x-cache:
              description: '"miss" or "hit" — present only when the org has response caching enabled and the request was cache-eligible (temperature:0, stream not true); absent otherwise.'
              schema:
                type: string
                enum:
                  - miss
                  - hit
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ChatCompletionResponse"
            text/event-stream:
              schema:
                type: string
        "400":
          description: invalid_json — body is not valid JSON; invalid_request_error — the gateway rejected the request (a missing or malformed field)
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CompatError"
        "401":
          description: Missing or invalid API key
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CompatError"
        "402":
          description: byok_required — this provider needs your own connected key on this plan
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CompatError"
        "403":
          description: model_not_allowed (routing candidates excluded by an allow-list) or content_blocked (prompt matched a guardrail regex)
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CompatError"
        "404":
          description: preset_not_found — @preset/<slug> does not exist or is inactive; model_not_found — no such model in the catalog
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CompatError"
        "405":
          description: "method_not_allowed — the path serves one method: the Allow header names it, plus OPTIONS"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CompatError"
          headers:
            Allow:
              description: The method this path serves, plus OPTIONS
              schema:
                type: string
        "429":
          description: rate_limit_exceeded (per-key/per-provider) or spend_cap_exceeded (guardrail cap reached)
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CompatError"
components:
  schemas:
    ChatCompletionRequest:
      type: object
      description: Money plane, ozk_ auth. Transparent proxy to inference-gateway — any OpenAI-compatible field is passed through untouched; the fields below are the ones Phase 2 routing adds on top.
      properties:
        model:
          type: string
          example: openai/gpt-4o-mini
          description: A single model slug ("provider/model", e.g. "anthropic/claude-sonnet-5"), or "@preset/<slug>" to expand a stored model+routing+params bundle (request-explicit fields below still override the preset). Required unless models[] is set, which replaces it.
        models:
          type: array
          items:
            type: string
          description: Ordered fallback candidates — alternative to model. One retry per candidate on 429/5xx/network, then failover to the next; a candidate whose provider just failed out is excluded for 30s.
        sort:
          type: string
          enum:
            - price
            - latency
            - throughput
          description: Reorders models[] before the first attempt. latency/throughput sort by rolling provider stats; a provider with no history yet sorts last.
        messages:
          type: array
          items:
            $ref: "#/components/schemas/ChatMessage"
        stream:
          type: boolean
          default: false
        temperature:
          type: number
          description: Set to exactly 0 to make the request response-cache eligible.
        max_tokens:
          type: integer
          example: 16
        top_p:
          type: number
      required:
        - model
        - messages
      additionalProperties: true
    ChatCompletionResponse:
      type: object
      description: model is the slug that ACTUALLY served the request (honest billing) — it may differ from the requested model/first models[] entry after a failover.
      properties:
        id:
          type: string
        object:
          type: string
        model:
          type: string
          description: The model that served this response — bill and log both key on this value.
        choices:
          type: array
          items:
            type: object
        usage:
          type: object
          properties:
            prompt_tokens:
              type: integer
            completion_tokens:
              type: integer
            total_tokens:
              type: integer
      required:
        - id
        - object
        - model
        - choices
    ChatMessage:
      type: object
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - tool
          example: user
        content:
          type: string
          example: Say hi in three words
      required:
        - role
        - content
    CompatError:
      type: object
      description: "OpenRouter's error envelope, worn by every /api/v1 error (guide 5.0, 5.7): a numeric `code` equal to the HTTP status, the Ocean detail in `metadata`. No X-Error-Code header."
      properties:
        error:
          type: object
          properties:
            code:
              type: integer
              description: The HTTP status
            message:
              type: string
            metadata:
              type: object
              properties:
                error_type:
                  type: string
                  description: "OpenRouter's error type: authentication, payment_required, rate_limit_exceeded, not_found, invalid_request, …"
                ocean_code:
                  type: string
                  description: The /v1 envelope's string error.code
                ocean_type:
                  type: string
                request_id:
                  type: string
                  description: Equals the x-request-id header
              required:
                - error_type
                - ocean_code
                - request_id
              additionalProperties: true
          required:
            - code
            - message
            - metadata
          additionalProperties: true
      required:
        - error
  securitySchemes:
    ozkBearer:
      type: http
      scheme: bearer
      description: "ozk_ platform API key (Authorization: Bearer ozk_…)"
    skOcean:
      type: http
      scheme: bearer
      description: "Legacy sk-ocean- inference key: still accepted on the money plane until the sk-ocean- sunset; new integrations use the ozk_ key"
```
