> ## Documentation Index
> Fetch the complete documentation index at: https://docs.budecosystem.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Calling models

> Create a key, find the base URL and call deployments with cURL or the OpenAI SDK.

Every deployment, router and agent is reached through the Bud Gateway at one base URL, using the OpenAI API format. The base URL for your installation appears in every **Use this model** snippet.

## Create a project API key

**Who:** someone who can manage credentials for the project

**Where:** API Keys → Projects → Create New Key

| Field | What to enter | Rules and defaults |
| - | - | - |
| **Credential Name** | A label for the key, such as the application that will use it. | Required ("Please input name!"). |
| **Project** | The project the key belongs to. The key reaches only that project's deployments, routers and agents. | Required ("Please select project!"). |
| **Set Expiry** | How long the key stays valid. | Required. *30 days* or *60 days*. |
| **Set Max Budget** | The most this key may spend. | Required. A whole number of 1 or more ("Please enter a valid number"). |

1. Fill in the four fields. **Create** stays disabled until all are set.
2. Click **Create**. To see the key later, click its row and use the eye icon; the copy icon copies it.
3. The **⋮** menu on a key opens **Edit Key** ("Update credentials here"), where you change the expiry and the budget, or deletes the key (**Delete Credential**).
4. To rotate a key, create a new one, switch your application to it, then delete the old one.

> [!NOTE]
>
> Client users create their own keys in the customer portal ([The customer portal](https://docs.budecosystem.com/product-guide/customer-dashboard/introduction.md)). Treat a key like a password: keep it in a secret store, never in client-side code or a repository.

## Make a request

Send the key as a bearer token. The `model` is the **deployment name**, the **router name** or, for an adapter, the **adapter deployment name**. Requests up to 100 MB are accepted.

| Header | Value |
| - | - |
| `Authorization` | `Bearer <project API key>`. Required on every request. The `x-api-key` header is not accepted. |
| `Content-Type` | `application/json` for JSON requests. File and audio uploads use `multipart/form-data`. |
| `x-model-name` | Only for calls that carry no `model` in the body, such as retrieving or cancelling a response. Set it to the deployment or agent name. |

### Chat completions

```bash theme={null}
# Request
curl $BUD_BASE_URL/v1/chat/completions \
  -H "Authorization: Bearer $BUD_API_KEY" -H "Content-Type: application/json" \
  -d '{"model": "support-llm", "max_tokens": 256,
       "messages": [{"role": "system", "content": "You are a support agent."},
                    {"role": "user", "content": "Summarise our refund policy"}]}'

# Response (abbreviated)
{"id": "chatcmpl-...", "object": "chat.completion", "model": "support-llm",
 "choices": [{"index": 0, "finish_reason": "stop",
              "message": {"role": "assistant", "content": "Refunds are available within 30 days..."}}],
 "usage": {"prompt_tokens": 31, "completion_tokens": 58, "total_tokens": 89}}
```

### Streaming

Set `"stream": true`. The reply is a server-sent event stream: one `data:` line per chunk, ending with `data: [DONE]`. Add `"stream_options": {"include_usage": true}` to receive a final chunk with the token usage.

```bash theme={null}
# Chat, streamed
curl -N $BUD_BASE_URL/v1/chat/completions \
  -H "Authorization: Bearer $BUD_API_KEY" -H "Content-Type: application/json" \
  -d '{"model": "support-llm", "stream": true, "stream_options": {"include_usage": true},
       "messages": [{"role": "user", "content": "Summarise our refund policy"}]}'

# Stream (abbreviated)
data: {"object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Refunds"}}]}
data: {"object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: {"object":"chat.completion.chunk","choices":[],"usage":{"prompt_tokens":31,"completion_tokens":58,"total_tokens":89}}
data: [DONE]
```

### The OpenAI SDK

```python theme={null}
# Python, with the standard OpenAI SDK
from openai import OpenAI
client = OpenAI(base_url=f"{BUD_BASE_URL}/v1", api_key=BUD_API_KEY)

stream = client.chat.completions.create(model="support-llm", stream=True,
    messages=[{"role": "user", "content": "Summarise our refund policy"}])
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")

vectors = client.embeddings.create(model="docs-embedder", input=["refund policy"])
```

### Embeddings

```bash theme={null}
curl $BUD_BASE_URL/v1/embeddings \
  -H "Authorization: Bearer $BUD_API_KEY" -H "Content-Type: application/json" \
  -d '{"model": "docs-embedder", "input": ["refund policy", "returns"]}'

# Response (abbreviated)
{"object": "list", "model": "docs-embedder",
 "data": [{"object": "embedding", "index": 0, "embedding": [0.0123, -0.0456, ...]},
          {"object": "embedding", "index": 1, "embedding": [0.0098, -0.0312, ...]}],
 "usage": {"prompt_tokens": 6, "total_tokens": 6}}
```

**Anthropic format.** `/v1/messages` accepts Anthropic Messages requests. Send the key as `Authorization: Bearer`; an `x-api-key` header is not accepted.

## Endpoints

A deployment answers only the endpoints its model supports. Calling another one returns 400 (*Provider ... does not support capability ...*). **Use this model** shows only the endpoints that apply.

| Endpoint | Use it for |
| - | - |
| `POST /v1/chat/completions` | Chat and tool calling, streamed or not. |
| `POST /v1/completions` | Plain text completion. |
| `POST /v1/messages` | Anthropic Messages format. |
| `POST /v1/responses` | Responses API, and calling agents (below). |
| `POST /v1/embeddings` | Vectors for search and retrieval. |
| `POST /v1/classify` | Classification models. |
| `POST /v1/moderations` | Content moderation. |
| `POST /v1/audio/transcriptions`, `/v1/audio/translations`, `/v1/audio/speech` | Speech to text, translation to English, text to speech. |
| `POST /v1/images/generations`, `/edits`, `/variations` | Image models. |
| `POST /v1/documents` | Document processing and OCR. |
| `POST /v1/decisions` | Decision models: typed questions answered with probabilities. |
| `/v1/realtime/sessions` | Realtime voice, over a WebSocket. |
| `GET /v1/models` | The models, adapters, guardrails and routers your key can reach. Filter with `?kind=model\|adapter\|guardrail\|router` or `?capability=chat` (or `embedding`, `responses` and so on). Agents are not listed: call them through `/v1/responses`. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.