---
title: "Create Key"
method: POST
path: "/v1/keys"
tags: ["keys"]
---

# Create Key

`POST /v1/keys`

Create a new API key.

Requires master key authentication.

If user_id is provided, the key will be associated with that user (creates user if it doesn't exist).
If user_id is not provided, the key is associated with the shared "default" user, which is created
on first use. Keys without an explicit owner therefore share one identity, and so share budget,
usage, and files.

## Request body

- CreateKeyRequest — Request model for creating a new API key.
  - `allowed_models` string[], nullable — Model allow-list: null = any model, [] = deny all, or canonical instance:model entries (with instance:* / instance:prefix* wildcards).
  - `exclude_from_budget` boolean — When true, requests on this key are logged with cost but never reserved, reconciled into the user's spend, or gated by budget.
  - `expires_at` string, date-time, nullable — Optional expiration timestamp
  - `key_name` string, nullable — Optional name for the key
  - `metadata` object — Optional metadata
  - `reject_user_mismatch` boolean, nullable — Per-key override of the deployment-wide reject_user_mismatch setting: null (default) inherits it, true always rejects a request naming a different 'user', false always accepts it. Spend binds to this key's own user either way.
  - `user_id` string, nullable — Optional user ID to associate with this key

## Response `200`

Successful Response

- CreateKeyResponse — Response model for creating a new API key.
  - `allowed_models` string[], nullable, required
  - `created_at` string, required
  - `exclude_from_budget` boolean, required
  - `expires_at` string, nullable, required
  - `id` string, required
  - `is_active` boolean, required
  - `key` string, required
  - `key_name` string, nullable, required
  - `key_prefix` string, nullable, required
  - `metadata` object, required
  - `reject_user_mismatch` boolean, nullable, required
  - `user_id` string, nullable, required

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/mozilla-ai/apis/otari.md) · [All operations](https://skmtc.net/mozilla-ai/apis/otari/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/mozilla-ai/otari/revisions/9efeac9dd037/schema)
