> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.joytokens.ai/llms.txt.

# Quickstart

> Connect to JoyToken with one request

Choose the protocol used by your application. You only need the Base URL for that protocol.

## Required Values

| Item    | Value                      |
| ------- | -------------------------- |
| API key | `JOY_TOKEN_API_KEY=sk-xxx` |
| Model   | `auto` (not configurable)  |

## Choose a Protocol

#### OpenAI

Base URL: `https://api.joytokens.ai/openai/v1`

```bash
export JOY_TOKEN_API_KEY="sk-xxx"
export JOY_TOKEN_OPENAI_BASE_URL="https://api.joytokens.ai/openai/v1"
```

### Responses API with cURL

```bash
curl -sS -X POST "$JOY_TOKEN_OPENAI_BASE_URL/responses" \
  -H "Authorization: Bearer $JOY_TOKEN_API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Request-ID: quickstart-responses-001" \
  -d '{
    "model": "auto",
    "input": "Reply with exactly: pong",
    "max_output_tokens": 1024,
    "stream": false
  }'
```

### Responses API with the OpenAI SDK

```ts
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.JOY_TOKEN_API_KEY,
  baseURL: process.env.JOY_TOKEN_OPENAI_BASE_URL,
});

const response = await client.responses.create({
  model: "auto",
  input: "Reply with exactly: pong",
  max_output_tokens: 1024,
});

console.log(response.output_text);
```

### Chat Completions with cURL

```bash
curl -sS -X POST "$JOY_TOKEN_OPENAI_BASE_URL/chat/completions" \
  -H "Authorization: Bearer $JOY_TOKEN_API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Request-ID: quickstart-001" \
  -d '{
    "model": "auto",
    "messages": [
      { "role": "user", "content": "Reply with exactly: pong" }
    ],
    "temperature": 0.7,
    "max_tokens": 1024,
    "stream": false
  }'
```

### Chat Completions with the OpenAI SDK

```ts
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.JOY_TOKEN_API_KEY,
  baseURL: process.env.JOY_TOKEN_OPENAI_BASE_URL,
});

const response = await client.chat.completions.create({
  model: "auto",
  messages: [{ role: "user", content: "Reply with exactly: pong" }],
  max_tokens: 1024,
});

console.log(response.choices[0]?.message?.content);
```

#### Anthropic

Base URL: `https://api.joytokens.ai/anthropic/v1`

```bash
export JOY_TOKEN_API_KEY="sk-xxx"
export JOY_TOKEN_ANTHROPIC_BASE_URL="https://api.joytokens.ai/anthropic/v1"
```

### cURL

```bash
curl -sS -X POST "$JOY_TOKEN_ANTHROPIC_BASE_URL/messages" \
  -H "x-api-key: $JOY_TOKEN_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "auto",
    "messages": [
      { "role": "user", "content": "Reply with exactly: pong" }
    ],
    "temperature": 0.7,
    "max_tokens": 1024,
    "stream": false
  }'
```

### Anthropic SDK

The official SDK appends `/v1/messages`, so remove the trailing `/v1` when passing the JoyToken Base URL.

```ts
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  apiKey: process.env.JOY_TOKEN_API_KEY,
  baseURL: process.env.JOY_TOKEN_ANTHROPIC_BASE_URL?.replace(/\/v1$/, ""),
});

const message = await client.messages.create({
  model: "auto",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Reply with exactly: pong" }],
});

console.log(message.content);
```

## Check the Integration

| Place             | Expected result                               |
| ----------------- | --------------------------------------------- |
| Program output    | Response contains `pong`                      |
| Response metadata | `metadata.model` and `metadata.billing`       |
| JoyToken Console  | Logs and usage are attributed to this API key |

Keep API keys in server-side environment variables, secret managers, or CI/CD secrets. Do not put them in browsers, mobile apps, public repositories, or logs.