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

# API Keys

> Create and manage API keys

After creating a protection policy, open the **API Keys** menu. This page is used to create and manage API keys.

## Create a Key

![Create API key](/_fern-files/_img/d45401b9649e29a55da83e4fb7bce9e5fe70285fee0ad1e31c3b8386d5b906d8.webp)

Click **Create New Key** in the top-right corner to open the creation dialog, then fill in the following as needed:

![Create API key dialog](/_fern-files/_img/9cfef331aea7b6e4622d1d0c33431907833cdaceb4013ca2e665e89f6264ec9d.webp)

* **Key Name**
* **Expiration Time**: e.g., never expire, 30 days, 90 days, or a custom time
* **Protection Policy**: policies already created under the **Protection Policies** menu are automatically pulled into the dropdown

> **Note**
>
> Each user can have at most 3 active keys at the same time.

## Key List

Filter by parameters or status, and open the row menu «⋮» to manage a key.

Displayed fields: **Key Name, Policy, Level, Usage Quota, Expiration Time, Actions**.

Clicking **Actions** opens a dropdown with "Details" and "Revoke":

* **Details**: view the key's identity information, ID, creation time, key prefix, policy configuration, and more.
* **Revoke**: invalidate the current key; a revoked key can no longer be used to call the API.

![API key list](/_fern-files/_img/363a87df6d8974353a5cb47059b33bed8f81d2ffa3b9d4c91891c9ede673d5b0.webp)![Create API key](/_fern-files/_img/99a2853eb67c68c8113ab1a0c39c459e73408e4f04203e311931b1a62e1b5ddf.webp)

## Playground for Online Testing

The Playground is a built-in online testing tool that lets you chat with models directly without writing any code, ideal for quickly verifying whether a key works and reviewing usage logs.

* **Left Panel**: Verify the API Key; review the selected policy's tier, product, industry pack, IP whitelist, quota, and model blacklist; configure temperature, maximum output tokens, and streaming.
* **Conversation Area**: Enter prompts, upload media, toggle configuration or inspector, and send.
* **Overview Panel**: Request status, request ID, key, policy, tier, model, cost, tokens, and latency details.
* **Routing Panel**: User settings, tier recommendation and scoring, selected model, hit probability, tags, and candidate models.

![Playground overview](/_fern-files/_img/95772b560c6fef24f10ffea686d1e4df63b23a06622bc2d23a4da34be56ef5f8.webp)![Playground routing details](/_fern-files/_img/95baef489e002d6b4c7ee6e23b86bd2baefe5c399b34be43ad596293db576388.webp)

### Playground Operations

**API Key Verification**: Before using the Playground, the entered key must be verified as valid. When a key is created successfully for the first time and you are redirected from API management, no input is required and the system verifies it automatically. After entering a key, click "Verify API Key"; the verification result is shown above the input box.

![Verify API key](/_fern-files/_img/76f4ae82773232eb2643841eadede372f5a4af89b805dd89e8693866fe4dc24b.webp)

**Generation Parameters - Temperature**: Controls randomness. Lower values are more stable, higher values are more divergent. Defaults to 0.7, applies to the Playground only.

![Generation parameters - temperature](/_fern-files/_img/3b06746f9d4af67dd369f8bba15d3d131b102ae60f5d14f85ed520a6cf71223c.webp)

**Max Output Tokens**: Limits the maximum length of the model's reply for this request. If exceeded, the model cannot output a result. Currently defaults to 4096, applies to the Playground only.

**Streaming Response**: When enabled, content is returned as it is generated, which is better suited for long replies and real-time preview; when disabled, the system waits for the complete response and returns it all at once. Currently enabled by default, applies to the Playground only.

![](/_fern-files/_img/3531ab9d434b97e173b8c0f2de7c222d9f8fb1db530ed9101e35419a90febb29.webp)![](/_fern-files/_img/cfc0a0908d6a1abb1e3ae0b129f7c61525dd309ff4041f55c6d5908d01a14342.webp)![](/_fern-files/_img/4f13ef718ccc591b9f375335e09b12a72adaaf92b4f96a388bfa1fcdaa842a51.webp)![](/_fern-files/_img/e067544982503aa45176559184535e53424e5fc11dd682ece80a7727c3d6d81e.webp)![](/_fern-files/_img/0f7b6e07e490b0f0e9cc77ef382d29d85839db063439a5fe4bb94b72a0e49802.webp)![](/_fern-files/_img/edcd2239d476f46f1d72af64a4b7ee28c45890fdbccbbb2dd1d58d298ac1ebd8.webp)![](/_fern-files/_img/d280310aad82b767aac56f1190031e08610ce8a25ef130ddd6916666036c5a36.webp)![](/_fern-files/_img/b9b8de5ff3b312d6ae5dfbb7e4d085286e38c418e5496c14a885be53f3af98f9.webp)![](/_fern-files/_img/e2f63a9f30d2d9f08630bdeb2e3d9ae1aaa1546eba6005bee76437a17f5033da.webp)![](/_fern-files/_img/9a90e746b661508ed045496fba3a1d2af04bf9bc63c536c4f368301eaad5af20.webp)

## API Call Examples

### Configure the Client

Fill the copied address into your client or code as the `base_url`, then use it together with your key to start making calls.

### Code Examples

TypeScript (OpenAI SDK):

```typescript
import { JoyTokenClient } from "@joytoken/client-sdk-ts";

const joytoken = new JoyTokenClient({
  apiKey,
  openAIBaseUrl: process.env.JOY_TOKEN_OPENAI_BASE_URL,
  timeoutMs: 60_000,
});
```

**Non-streaming:**

```typescript
const completion = await joytoken.chat.completions.create({
  model: "auto",
  messages: [{ role: "user", content: "Reply with exactly: pong" }],
});
console.log(completion.choices[0]?.message?.content);
```

**Streaming:**

```typescript
for await (const chunk of joytoken.chat.completions.stream({
  model: "auto",
  messages: [{ role: "user", content: "Write one short paragraph." }],
})) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
```

**Claude native format:**

```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
  }'
```

### Supported API Endpoints

<table>
  <thead>
    <tr>
      <th>
        Endpoint
      </th>

      <th>
        Method & Path
      </th>

      <th>
        Description
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        Chat Completions
      </td>

      <td>
        `POST /openai/v1/chat/completions`
      </td>

      <td>
        Chat generation with streaming support
      </td>
    </tr>

    <tr>
      <td>
        Responses
      </td>

      <td>
        `POST /openai/v1/responses`
      </td>

      <td>
        Generation in OpenAI Responses format
      </td>
    </tr>

    <tr>
      <td>
        Image Generations
      </td>

      <td>
        `POST /openai/v1/images/generations`
      </td>

      <td>
        Text-to-image generation
      </td>
    </tr>

    <tr>
      <td>
        Anthropic Messages
      </td>

      <td>
        `POST /anthropic/v1/messages`
      </td>

      <td>
        Generation in Anthropic Messages format
      </td>
    </tr>

    <tr>
      <td>
        List Models
      </td>

      <td>
        `GET /api/v1/models`
      </td>

      <td>
        Query the model catalog
      </td>
    </tr>

    <tr>
      <td>
        Model Filter Metadata
      </td>

      <td>
        `GET /api/v1/models/meta`
      </td>

      <td>
        Query model filter options
      </td>
    </tr>

    <tr>
      <td>
        Pricing
      </td>

      <td>
        `GET /api/v1/pricing`
      </td>

      <td>
        Query tier exchange rates
      </td>
    </tr>
  </tbody>
</table>