# Quickstart

> Get a key, make a first call, and continue the same conversation on a different model, in three steps.

You need an AlphaNeural account with a balance above zero: calls are refused with `402` while it is zero. [Add funds](https://app.alphaneural.io/profile/me?tab=wallet-management) from your wallet first if you have not already.

## 1. Get a key

Create a key on the [API Keys page](https://app.alphaneural.io/profile/me?tab=api-keys) (Profile, then API Keys) and export it:

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

Keys live on the [API Keys page](https://app.alphaneural.io/profile/me?tab=api-keys). To run the examples from a terminal as they are written, export your key first:

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

The Python and TypeScript examples use the official OpenAI SDK (`pip install openai`, `npm install openai`). Nothing else is needed.

## 2. Make a call

The base URL is `https://backend.alfnrl.io/v1` and the model can be any id from the [catalogue](https://app.alphaneural.io/models). This asks a small, cheap model to remember something:

curl:

```bash
curl -i https://backend.alfnrl.io/v1/chat/completions \
  -H "Authorization: Bearer $ALPHANEURAL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openrouter/openai/gpt-4o-mini",
    "messages": [{"role": "user", "content": "My name is Ada. Please remember it."}]
  }'
```

Python:

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://backend.alfnrl.io/v1",
    api_key=os.environ["ALPHANEURAL_API_KEY"],
)

# No thread id yet, so the server starts a thread and returns its id.
raw = client.chat.completions.with_raw_response.create(
    model="openrouter/openai/gpt-4o-mini",
    messages=[{"role": "user", "content": "My name is Ada. Please remember it."}],
)
thread_id = raw.headers["x-thread-id"]
print(thread_id)
print(raw.parse().choices[0].message.content)
```

TypeScript:

```typescript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://backend.alfnrl.io/v1",
  apiKey: process.env.ALPHANEURAL_API_KEY,
});

// No thread id yet, so the server starts a thread and returns its id.
const { data, response } = await client.chat.completions
  .create({
    model: "openrouter/openai/gpt-4o-mini",
    messages: [{ role: "user", content: "My name is Ada. Please remember it." }],
  })
  .withResponse();

const threadId = response.headers.get("x-thread-id");
if (!threadId) throw new Error("expected an X-Thread-Id header");
console.log(threadId, data.choices[0].message.content);
```

The body is a standard OpenAI chat completion. The response also carries an `X-Thread-Id` header: the server started a thread for this conversation, and that is its id.

## 3. Continue on a different model

Send the id back with the next message, and name a different model:

curl:

```bash
# THREAD_ID is the X-Thread-Id header from the first response.
curl https://backend.alfnrl.io/v1/chat/completions \
  -H "Authorization: Bearer $ALPHANEURAL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Thread-Id: $THREAD_ID" \
  -d '{
    "model": "openrouter/anthropic/claude-haiku-4.5",
    "messages": [{"role": "user", "content": "What is my name?"}]
  }'
```

Python:

```python
# Same script, continued. Only the new turn is sent: the thread supplies
# the rest, and it is now answered by a different model.
reply = client.chat.completions.create(
    model="openrouter/anthropic/claude-haiku-4.5",
    messages=[{"role": "user", "content": "What is my name?"}],
    extra_headers={"X-Thread-Id": thread_id},
)
print(reply.choices[0].message.content)
```

TypeScript:

```typescript
// Same script, continued. Only the new turn is sent: the thread supplies
// the rest, and it is now answered by a different model.
const reply = await client.chat.completions.create(
  {
    model: "openrouter/anthropic/claude-haiku-4.5",
    messages: [{ role: "user", content: "What is my name?" }],
  },
  { headers: { "X-Thread-Id": threadId } },
);
console.log(reply.choices[0].message.content);
```

The second model should tell you your name is Ada. It never saw the first request: the server rebuilt the conversation from the thread and sent it along with your new message.

> **With a thread, send only the new message**
>
>
> Every message in `messages` is added to the thread before the model is called. If you resend the whole transcript, the thread records all of it a second time. The server supplies the history; you supply the next turn.
>

## Where to go next

- [Threads and memory](https://app.alphaneural.io/docs/threads): how a thread is chosen, what the model sees, and how to read a thread back.
- [Routing](https://app.alphaneural.io/docs/routing): let a cheap model try first, and escalate only when its answer fails a check.
- [Billing](https://app.alphaneural.io/docs/billing): how prices work and where to check what you spent.
