# Quickstart

Make your first Claudech request in a few minutes.

## 1. Get an API key

Sign in and open [API keys](https://claudech.com/api-keys) in the dashboard. Click **Create key**, give it a name, and copy the key that starts with `sk-`. The full key is shown once; Claudech only stores a hash of it.

Store it as an environment variable rather than pasting it into source code:

```bash
export CLAUDECH_API_KEY="sk-..."
```

> **Warning**
>
> New accounts must verify their email address before the API accepts requests. Check your inbox for the verification link or resend it from [Settings](https://claudech.com/settings).

## 2. Pick the right base URL

The same `sk-...` key works everywhere, but the **base URL depends on your tool**:

| Tool / SDK | Base URL | Example endpoint |
| --- | --- | --- |
| OpenAI SDK, Cursor, most “OpenAI-compatible” apps | `https://api.claudech.com/v1` | `POST /v1/chat/completions` |
| Anthropic SDK, **Claude Code** | `https://api.claudech.com` | `POST /v1/messages` (appended by the client) |

For **Claude Code**, set `ANTHROPIC_BASE_URL=https://api.claudech.com` — **not** `https://api.claudech.com/v1/chat/completions`. See [Claude Code setup](https://claudech.com/docs/integrations/claude-code) and [Cursor setup](https://claudech.com/docs/integrations/cursor).

## 3. Send a chat completion

**curl**

```bash
curl https://api.claudech.com/v1/chat/completions \
  -H "Authorization: Bearer $CLAUDECH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-opus-5-5",
    "messages": [
      { "role": "system", "content": "You are a concise assistant." },
      { "role": "user", "content": "Explain what a mutex is in two sentences." }
    ]
  }'
```

**PowerShell**

```powershell
# Windows PowerShell 5.1: `curl` is Invoke-WebRequest (not curl). Use Invoke-RestMethod or curl.exe.
# If replies show mojibake (e.g. Iâ€™m instead of I'm), set UTF-8 once per session:
$OutputEncoding = [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()

$headers = @{ Authorization = "Bearer $env:CLAUDECH_API_KEY"; "Content-Type" = "application/json; charset=utf-8" }
$body = @{
  model    = "claude-opus-5-5"
  messages = @(
    @{ role = "system"; content = "You are a concise assistant." },
    @{ role = "user";   content = "Explain what a mutex is in two sentences." }
  )
} | ConvertTo-Json -Depth 5 -Compress

$r = Invoke-RestMethod -Method Post -Uri "https://api.claudech.com/v1/chat/completions" -Headers $headers -Body $body
$r.choices[0].message.content
```

**JavaScript**

```javascript
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: process.env.CLAUDECH_API_KEY,
  baseURL: 'https://api.claudech.com/v1',
});

const completion = await client.chat.completions.create({
  model: 'claude-opus-5-5',
  messages: [
    { role: 'system', content: 'You are a concise assistant.' },
    { role: 'user', content: 'Explain what a mutex is in two sentences.' },
  ],
});

console.log(completion.choices[0].message.content);
console.log(`Cost: ${completion.usage.claud_tokens_debited} Claudech tokens`);
```

**Python**

```python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["CLAUDECH_API_KEY"],
    base_url="https://api.claudech.com/v1",
)

completion = client.chat.completions.create(
    model="claude-opus-5-5",
    messages=[
        {"role": "system", "content": "You are a concise assistant."},
        {"role": "user", "content": "Explain what a mutex is in two sentences."},
    ],
)

print(completion.choices[0].message.content)
print("Cost:", completion.usage.model_extra["claud_tokens_debited"], "Claudech tokens")
```

A successful response looks like this:

```json
{
  "id": "chatcmpl-01J9X3Q5K7M2N8P4R6T0V2W4Y6",
  "object": "chat.completion",
  "created": 1789467600,
  "model": "claude-opus-5-5",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "A mutex is a lock that lets only one thread at a time enter a critical section of code. Other threads that try to acquire it wait until the holder releases it, which prevents concurrent modification of shared state."
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 31,
    "completion_tokens": 47,
    "total_tokens": 78,
    "prompt_tokens_details": { "cached_tokens": 0 },
    "completion_tokens_details": { "reasoning_tokens": 0 },
    "claud_tokens_debited": "83",
    "claud_cost_usd": "0.000164"
  },
  "system_fingerprint": "fp_claud"
}
```

The `usage` object includes two Claudech-specific fields: `claud_tokens_debited` (what the request cost from your balance) and `claud_cost_usd` (the same amount in dollars). The response headers carry the same information as `x-claud-tokens-debited` and your remaining balance as `x-claud-balance`.

## 4. Stream the response

Set `"stream": true` to receive tokens as they are generated. The OpenAI SDKs handle the event stream for you:

**curl**

```bash
curl https://api.claudech.com/v1/chat/completions \
  -H "Authorization: Bearer $CLAUDECH_API_KEY" \
  -H "Content-Type: application/json" \
  -N \
  -d '{
    "model": "claude-opus-5-5",
    "stream": true,
    "messages": [{ "role": "user", "content": "Write a haiku about compilers." }]
  }'
```

**JavaScript**

```javascript
const stream = await client.chat.completions.create({
  model: 'claude-opus-5-5',
  stream: true,
  messages: [{ role: 'user', content: 'Write a haiku about compilers.' }],
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
}
```

**Python**

```python
stream = client.chat.completions.create(
    model="claude-opus-5-5",
    stream=True,
    messages=[{"role": "user", "content": "Write a haiku about compilers."}],
)

for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
```

See [Streaming](https://claudech.com/docs/streaming) for the exact chunk format, including the final usage and billing events.

## 5. Check your balance and usage

```bash
curl https://api.claudech.com/v1/billing/balance \
  -H "Authorization: Bearer $CLAUDECH_API_KEY"
```

```json
{
  "object": "balance",
  "available_tokens": "25998200",
  "purchased_tokens": "20000000",
  "subscription_tokens": "5998200",
  "reserved_tokens": "0",
  "approx_value_usd": "52.00",
  "token_rate": { "micro_usd_per_token": 0.5, "tokens_per_usd": 2000000 }
}
```

The [Usage](https://claudech.com/usage) page in the dashboard shows the same data with charts and a per-request log, and `GET /v1/usage` exposes it programmatically.

## Where to go next

- [Models](https://claudech.com/docs/models): choose the right model for the job.
- [Tool calling & JSON](https://claudech.com/docs/tools): get structured output or let the model call your functions.
- [Rate limits](https://claudech.com/docs/rate-limits) and [Errors](https://claudech.com/docs/errors): build a robust client.
- [Chat completions reference](https://claudech.com/docs/api/chat-completions): every request parameter.

---

Source: https://claudech.com/docs/quickstart
