---
title: "Chat completions (OpenAI-compatible)"
method: POST
path: "/api/v1/ai/chat/completions"
tags: ["AI"]
---

# Chat completions (OpenAI-compatible)

`POST /api/v1/ai/chat/completions`

## Request

- Base URL: `https://core.blink.new`
- URL: `https://core.blink.new/api/v1/ai/chat/completions`
- Auth: one of:
  - HTTP bearer
  - HTTP bearer

OpenAI-compatible chat completions endpoint. Use your Blink workspace API key (or, from a Blink backend, the backend AI key `env.BLINK_BACKEND_AI_KEY`) in place of an OpenAI key. The default model is `anthropic/claude-sonnet-4.6`. `response_format: { type: "json_object" }` is silently converted to no format constraint — use `json_schema` instead. For streaming requests, `stream_options.include_usage` is injected automatically.

## Request body

- object
  - `model` string: Model identifier (gateway format `provider/model`)
  - `messages` Message[], required: Array of messages in the conversation.
    - `role` 'system' | 'user' | 'assistant', required: Message role
    - `content` union, required: Message content - either simple text or array of content items for multimodal support
      - string: Simple text content (legacy format)
      - MessageContent[]: Array of content items (multimodal format)
        - union
          - TextContent
            - `type` 'text', required: Content type identifier
            - `text` string, required: Text content
          - ImageContent
            - `type` 'image', required: Content type identifier
            - `image` string, uri, required: HTTPS URL to image. Supported formats: JPEG, PNG, GIF, WebP
  - `stream` boolean: Enable SSE streaming (text/event-stream)
  - `temperature` number
  - `max_tokens` integer
  - `top_p` number
  - `response_format` object: `json_object` is auto-converted; prefer `json_schema`
    - `type` 'json_schema' | 'text'
  - `tools` object[]: Function/tool definitions (OpenAI tool calling spec)
  - `tool_choice` union: Controls which tool (if any) is called.
    - 'auto' | 'none' | 'required'
    - object

## Response `200`

Chat completion response (OpenAI format).
When `stream: true`, returns `text/event-stream` SSE data ending with `[DONE]`.

- object
  - `id` string
  - `object` string
  - `created` integer
  - `model` string
  - `choices` object[]
    - `index` integer
    - `message` Message
      - `role` 'system' | 'user' | 'assistant', required: Message role
      - `content` union, required: Message content - either simple text or array of content items for multimodal support
        - string: Simple text content (legacy format)
        - MessageContent[]: Array of content items (multimodal format)
          - union
            - TextContent
              - …
            - ImageContent
              - …
    - `finish_reason` 'stop' | 'length' | 'tool_calls' | 'content_filter'
  - `usage` object
    - `prompt_tokens` integer
    - `completion_tokens` integer
    - `total_tokens` integer
    - `market_cost` number: Upstream cost in USD

## Other responses

- `400`: Invalid request — missing or empty `messages` array
- `401`: Authentication required or invalid API key
- `402`: Insufficient credits — workspace balance exhausted
- `403`: Free tier blocked or model not available on current plan
- `500`: Internal server error

---

[API](https://skmtc.dev/blink/apis/blink-apis.md) - [All operations](https://skmtc.dev/blink/apis/blink-apis/llms.txt) - [OpenAPI document](https://skmtc.dev/blink/apis/blink-apis/revisions/4c59c706078e?raw)
