# Call a model

> Make your first request to a model with an API key.

## Three steps to your first response

Want to try a model before writing code? Open **Playground** in the console. It needs no key and is billed from your credits like any call. The steps below are for calling from your own code.

### 1. Add credits

Open **Wallet** and add credits. Requests are billed from this prepaid balance, so a call with no credits is refused with [`insufficient_credits`](/reference/errors/#insufficient_credits). See [Wallet](/account/wallet/#credits) for how to add credits and turn on auto top-up.

If a console screen shows **Inference** marked **Locked**, press **Unlock** to ask for access. Shardio emails you when the request is decided.

### 2. Create a key

Open **API keys** and press **New key**. Give it a name you will recognise later, such as the machine or agent that will use it. You can set a spend cap now or leave it blank for no cap.

The key's secret is shown once, already filled into sample code. Copy it then: Shardio keeps only a fingerprint of it and cannot show it again. A key looks like `tsk_live_…`. If you lose one, revoke it and create another.

### 3. Make a call

Pick a model on the **Models** screen and copy its model id from the model's page. Then send a request to the base URL with your key as a bearer token:

```bash
export SHARDIO_API_KEY="tsk_live_…"

curl https://api.shardio.ai/v1/chat/completions \
  -H "Authorization: Bearer $SHARDIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "<model-id>", "messages": [{"role": "user", "content": "Hello"}]}'
```

Any OpenAI SDK works by changing its base URL:

```python
import os
from openai import OpenAI

client = OpenAI(base_url="https://api.shardio.ai/v1", api_key=os.environ["SHARDIO_API_KEY"])
res = client.chat.completions.create(
    model="<model-id>",
    messages=[{"role": "user", "content": "Hello"}],
)
print(res.choices[0].message.content)
```

The request appears on the **Activity** screen with its tokens, cost and timing.

### Ask a decision instead

Decision models answer typed questions with probabilities. They use the same key and credits, and bill input tokens only:

```bash
curl https://api.shardio.ai/v1/systemone \
  -H "Authorization: Bearer $SHARDIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "<decision-model-id>", "state": "I was billed twice, fix it today", "questions": {"urgent": {"type": "noul", "instructions": "Does this need a reply today?"}}}'
```

[Playground decisions](/use/playground-decisions/) shows how to write questions and read answers.

### If the call is refused

| Code | What it means | Fix |
|---|---|---|
| [`invalid_api_key`](/reference/errors/#invalid_api_key) | The key is wrong, revoked or missing. | Check the `Authorization: Bearer` header, or create a new key. |
| [`insufficient_credits`](/reference/errors/#insufficient_credits) | Your balance is empty. | Add credits in the Wallet. |
| [`hold_exceeds_balance`](/reference/errors/#hold_exceeds_balance) | Your balance cannot cover the request's largest possible cost. | Add credits, or ask for fewer output tokens. |
| [`key_budget_exhausted`](/reference/errors/#key_budget_exhausted) | The key reached its spend cap. | Raise the cap in API keys, wait for it to reset, or use another key. |
| [`temporarily_unavailable`](/reference/errors/#temporarily_unavailable) | The model is listed but cannot take requests right now. | Try again later or choose another model. |

Nothing is billed for a refused request. Every code is in the [error reference](/reference/errors/), and every route in the [API reference](/reference/api/).
