# Quickstart

Three steps of setup, then one request.

1. Create an account at https://openmayhem.ai/signup and add credit on the
   dashboard credit page. Credit is spent per request.
2. Create an API key under dashboard → API keys. The secret
   (`sk-om-v1-...`) is shown once and never again.
3. Pick a model id from `GET https://api.openmayhem.ai/v1/models` or the live catalog page,
   which shows prices and how many providers are online.

## First request

```bash
curl https://api.openmayhem.ai/v1/chat/completions \
  -H "Authorization: Bearer $OPENMAYHEM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "prism-ml/ternary-bonsai-27b",
    "messages": [{"role": "user", "content": "Hello!"}],
    "max_tokens": 2000
  }'
```

Or with the OpenAI SDK, changing only base URL and key:

```python
from openai import OpenAI
client = OpenAI(base_url="https://api.openmayhem.ai/v1", api_key=OPENMAYHEM_API_KEY)
reply = client.chat.completions.create(
    model="prism-ml/ternary-bonsai-27b",
    messages=[{"role": "user", "content": "Hello!"}],
    max_tokens=2000,
)
```

The response is OpenAI-shaped, with two additions: the exact cost in USD in
`usage.cost`, and `openmayhem` carrying the `request_id` plus the
identity of the signed receipt the charge settled against.

Reasoning models spend tokens thinking before they answer. Give them a
generous `max_tokens` (2000 or more) or the reply can arrive empty with
`finish_reason: "length"`; you are still charged for the thinking done.

## Use it with agents

OpenMayhem is not limited to Studio. Coding agents and automation tools can
use the same live models through the OpenAI-compatible API. For an agent that
accepts the standard OpenAI environment variables:

```bash
export OPENAI_API_KEY="$OPENMAYHEM_API_KEY"
export OPENAI_BASE_URL="https://api.openmayhem.ai/v1"
```

Keep the key in an environment variable, never in a project file. In an
agent or application built with the OpenAI JavaScript client:

```javascript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
  baseURL: "https://api.openmayhem.ai/v1",
});

const stream = await client.chat.completions.create({
  model: "Qwen/Qwen3.8-27B",
  messages: [{ role: "user", content: "Inspect this project and propose the next change." }],
  max_tokens: 8000,
  stream: true,
});

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

Choose the current model id, context, price and availability from
https://openmayhem.ai/models before starting a task. Tools, images, streaming
and structured output work when the selected model lists them.

For trust, context, quantization, provider, throughput, wait, hedging and
retail-cost controls, see https://openmayhem.ai/docs/routing.
