# Quickstart

## 1. Get a key

Open [Settings → API](/settings?p=api) and click "Create key". The key starts with `ut_live_` and is shown once: put it in a secret manager or an environment variable.

```bash
export UNITOOL_API_KEY="ut_live_..."
```

Keys are available after the first payment. Requests spend tokens from your balance, so treat the key like a password and keep it out of frontend code.

## 2. First request

The base URL is `https://api.unitool.ai/v1`. Take a model id from the [catalog](/developers/models) or from `GET /v1/models`.

```bash
curl https://api.unitool.ai/v1/chat/completions \
  -H "Authorization: Bearer $UNITOOL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hi! What can you do?"}]
  }'
```

The answer is a regular Chat Completions object. `usage.cost_tokens` says how many balance tokens the request cost.

## 3. With the OpenAI SDK

Change `base_url` and the key, nothing else.

```python
import os
from openai import OpenAI

client = OpenAI(base_url="https://api.unitool.ai/v1", api_key=os.environ["UNITOOL_API_KEY"])
reply = client.chat.completions.create(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hi! What can you do?"}],
)
print(reply.choices[0].message.content)
print(reply.usage.model_extra["cost_tokens"])  # price in balance tokens
```

```js
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.unitool.ai/v1", apiKey: process.env.UNITOOL_API_KEY });
const reply = await client.chat.completions.create({
  model: "claude-sonnet-5-5",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hi! What can you do?" }],
});
console.log(reply.choices[0].message.content);
```

## 4. Streaming

With `stream: true` the answer arrives in SSE chunks, as with OpenAI. The chunk with `finish_reason` carries `usage`, then `data: [DONE]` follows.

```python
stream = client.chat.completions.create(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Write a haiku about APIs"}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
```

```js
const stream = await client.chat.completions.create({
  model: "claude-sonnet-5-5",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Write a haiku about APIs" }],
  stream: true,
});
for await (const chunk of stream) process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
```

## 5. Next steps

- Set `max_tokens`. While a request runs, the balance holds what the longest possible answer would cost: without `max_tokens` that is the model's limit. Details in [Billing](/developers/billing).
- Check the balance: `GET /v1/balance`. The price of any past request: `GET /v1/requests/{id}`, the id comes in the `x-request-id` header.
- Images, video and audio: [Media generations](/developers/generations).
