> Index: https://quebragalho.dev/en/docs/llms.txt

# First API call

Chat completions in the OpenAI format. If your code already talks to OpenAI, changing the base URL and the API key is the whole migration.

## Your first call

### 1. Create a key

Under [API keys](https://app.quebragalho.dev/api-keys), in the dashboard. Keep it in a terminal variable; the key starts with `qg-sk-`.

```bash
export QUEBRAGALHO_API_KEY=qg-sk-YOUR_KEY
```

### 2. Change the base URL

Point the official OpenAI SDK at our base URL. No other line changes.

```text
https://api.quebragalho.dev/v1
```

### 3. Run it

**cURL**

```bash
curl https://api.quebragalho.dev/v1/chat/completions \
  -H "Authorization: Bearer $QUEBRAGALHO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-6.2-astra",
    "messages": [{"role": "user", "content": "explain RAG in 3 lines"}]
  }'
```

**Python**

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.quebragalho.dev/v1",
    api_key=os.environ["QUEBRAGALHO_API_KEY"],
)

resp = client.chat.completions.create(
    model="gpt-6.2-astra",
    messages=[{"role": "user", "content": "explain RAG in 3 lines"}],
)
print(resp.choices[0].message.content)
```

**Node.js**

```ts
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.quebragalho.dev/v1",
  apiKey: process.env.QUEBRAGALHO_API_KEY,
});

const resp = await client.chat.completions.create({
  model: "gpt-6.2-astra",
  messages: [{ role: "user", content: "explain RAG in 3 lines" }],
});
console.log(resp.choices[0].message.content);
```

Your balance is charged per token, when the response ends. No account yet? [Create one](https://app.quebragalho.dev/register) and get your key right away.

## One key per project

The key goes in the `Authorization: Bearer` header. Create one per project: if one leaks, you revoke just that one.

- **Shown once.** We only store the hash. Lost it? Create another.
- **To rotate,** create the new one, switch it in the project and revoke the old one.
- **Never in git** or in the front end. Use an environment variable.

[Manage API keys](https://app.quebragalho.dev/api-keys)

## Next steps

- [Use it in your agent](https://quebragalho.dev/en/docs/integracoes.md): QGCLI, Claude Code, Codex, Copilot and more, each with its own step-by-step guide.
- [Real-time responses](https://quebragalho.dev/en/docs/api/chat-completions.md#streaming): SSE streaming, with a heartbeat so the connection stays open.
- [Pay less on long conversations](https://quebragalho.dev/en/docs/api/chat-completions.md#conversas): One ID per conversation keeps the model's cache warm.

Read it in the browser: https://quebragalho.dev/en/docs/quickstart
