> ## 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

> Send messages to a model and get a completion, or stream it as SSE chunks. Ordered fallback with `models[]`, `sort`, presets and an opt-in response cache.


## OpenAPI

```yaml openapi.json post /v1/chat/completions
openapi: 3.1.0
info:
  title: Ocean One API
  version: 2.1.0
servers:
  - url: https://api.plungeai.com
paths:
  /v1/chat/completions:
    post:
      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:
        - 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
        "401":
          description: Missing/invalid sk-ocean- key
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "402":
          description: byok_required — this provider needs your own connected key on this plan
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "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/Error"
        "404":
          description: preset_not_found — @preset/<slug> does not exist or is inactive
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "429":
          description: rate_limit_exceeded (per-key/per-provider) or spend_cap_exceeded (guardrail cap reached)
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "503":
          description: money_plane_unavailable — INFERENCE_GATEWAY_SERVICE not bound on this tier
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
components:
  schemas:
    ChatCompletionRequest:
      type: object
      description: Money plane, sk-ocean- 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
          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). Ignored if models[] is set.
        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
        top_p:
          type: number
      required:
        - 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
        content:
          type: string
      required:
        - role
        - content
    Error:
      type: object
      description: Standard error envelope. Every error response also carries an `X-Error-Code` response header equal to error.code, so a client branches on the header regardless of the negotiated body format (json | yaml | markdown | text). When the request created an execution, the `X-Execution-Id` response header is also set. Errors follow the negotiated format like success bodies.
      properties:
        error:
          type: object
          properties:
            code:
              type: string
            message:
              type: string
          required:
            - code
            - message
          additionalProperties: true
      required:
        - error
  securitySchemes:
    skOcean:
      type: http
      scheme: bearer
      description: sk-ocean- inference key (money plane, forwarded downstream)
```
