[Works with](https://autarcho.com/works-with/)

# Use the OpenAI SDK with Autarcho

The official SDKs take a base URL. Give it this endpoint and the rest of your code does not move.

[Open the chat](https://chat.autarcho.com) [Make a key first](https://autarcho.com/start/)

## The change

Set `base_url` and `api_key`. Nothing else changes.

```
from openai import OpenAI

client = OpenAI(
    base_url="https://api.autarcho.com/v1",
    api_key="ak_...",
)

stream = client.chat.completions.create(
    model="lfm2-1.2b-extract@1.0",
    messages=[{"role": "user", "content": "Summarise this in one line."}],
    stream=True,
)

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

A key is `ak_` followed by 64 hex characters, made on your own machine; the [start page](https://autarcho.com/start/) covers making one and adding credit. Model ids come from [the catalogue](https://autarcho.com/models/).

## What works

- Streaming, tool calls and JSON output, with the same shapes the SDK already parses.
- A reasoning model returns its scratchpad in `reasoning_content`, separate from `content`.
- `max_price_per_token_micro_usdc` as an extra body field refuses a request priced above it before any credit is held.

## What to watch

- `stop`, `seed`, `logprobs` and `n` above 1 are refused with an error rather than ignored.
- `usage.cost_micro_usdc` is the amount charged. Read it rather than multiplying tokens by a price, because input is billed too.
- A model that is not loaded anywhere has to be downloaded first; stream so the wait is visible.

The full list of what is refused, what is charged and what a retry costs is on [the API reference](https://autarcho.com/docs/api/).

[What a request costs](https://autarcho.com/pricing/) [Other clients](https://autarcho.com/works-with/)
