# Chat Completions

> POST /v1/chat/completions in the OpenAI format, for every text model on Vikey including Claude and Vikey Auto.

```http
POST https://api.vikey.ai/v1/chat/completions
```

The request and response follow [OpenAI Chat Completions](https://platform.openai.com/docs/api-reference/chat). This endpoint serves every text model on Vikey, not only OpenAI models.

## Example

```bash
curl https://api.vikey.ai/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-5.5",
    "max_tokens": 1024,
    "messages": [
      {"role": "system", "content": "Answer briefly."},
      {"role": "user", "content": "What is the difference between let and const in JavaScript?"}
    ]
  }'
```

## Common parameters

| Parameter | Notes |
| --- | --- |
| `model` | Required. A model id, such as `openai/gpt-6.1-sol` or `vikey/agent-gpt`. |
| `messages` | Required. Messages with a `role` (`system`, `user`, `assistant`, `tool`) and `content`. |
| `max_tokens` | Output token limit. Also used for the [balance check](/en/models/pricing/#balance-check), so keep it sensible. |
| `stream` | `true` for Server-Sent Events. The stream ends with `data: [DONE]`. |
| `tools`, `tool_choice` | Function calling in the OpenAI format. |
| `temperature`, `top_p`, `stop` | Passed to the model. |
| `response_format` | JSON mode or JSON schema, for models that support it. |

Other parameters are passed to the model as they are. A model that does not support a parameter may ignore it or return an error.

## Images (vision)

For models with vision, send images as part of `content`:

```json
{
  "role": "user",
  "content": [
    {"type": "text", "text": "What is the bug in this screenshot?"},
    {"type": "image_url", "image_url": {"url": "https://example.com/error.png"}}
  ]
}
```

The URL can also be `data:image/png;base64,...`.

## Response

```json
{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "model": "anthropic/claude-sonnet-5.5",
  "choices": [
    {
      "index": 0,
      "message": {"role": "assistant", "content": "let can be reassigned, const cannot..."},
      "finish_reason": "stop"
    }
  ],
  "usage": {"prompt_tokens": 32, "completion_tokens": 58, "total_tokens": 90}
}
```

## Behaviour notes

- `tool_choice` without `tools` is dropped, so the model does not reject the request.
- Null characters (`\u0000`) in text are removed before forwarding, because some models reject them.
- A very small `max_tokens` is raised to the minimum the model accepts.

Source: https://docs.vikey.ai/en/api/chat-completions/
