> ## Documentation Index
> Fetch the complete documentation index at: https://arize-ax.mintlify.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# API Keys

> Manage API keys programmatically using the Arize TypeScript SDK.

<Note>
  The `api_keys` functions are currently in **ALPHA**. The API may change without notice. A one-time warning is emitted on first use.
</Note>

## List API Keys

```typescript theme={null}
import { listApiKeys } from "@arizeai/ax-client";

const { data: apiKeys, pagination } = await listApiKeys({
  keyType: "user",          // "user" or "service" (optional)
  status: "active",         // "active" or "revoked" (optional)
  spaceId: "your_space_id", // filter service keys by space (optional)
  userId: "your_user_id",   // filter by key creator (optional)
  limit: 10,
});
```

## Create an API Key

```typescript theme={null}
import { createApiKey } from "@arizeai/ax-client";

const apiKey = await createApiKey({
  name: "CI pipeline key",
  description: "Key for CI/CD pipeline",
  keyType: "user",
});
// Store apiKey.key securely — it is only returned once
```

### Create a Service Key

Service keys require a `spaceId` and optionally accept `roles`.

```typescript theme={null}
import { createApiKey } from "@arizeai/ax-client";

const serviceKey = await createApiKey({
  name: "service-key",
  keyType: "service",
  spaceId: "your_space_id",
  expiresAt: "2026-12-31T00:00:00Z",
});
```

## Revoke an API Key

```typescript theme={null}
import { revokeApiKey } from "@arizeai/ax-client";

await revokeApiKey({ apiKeyId: "your_api_key_id" });
```

## Refresh an API Key

Atomically revokes the existing key and issues a replacement with the same metadata (name, description, and key type). There is no window where neither key is valid.

```typescript theme={null}
import { refreshApiKey } from "@arizeai/ax-client";

const refreshed = await refreshApiKey({ apiKeyId: "your_api_key_id" });
// Store refreshed.key securely — it is only returned once
```

### With a New Expiration Date

```typescript theme={null}
import { refreshApiKey } from "@arizeai/ax-client";

const refreshed = await refreshApiKey({
  apiKeyId: "your_api_key_id",
  expiresAt: "2027-12-31T00:00:00Z",
  gracePeriodSeconds: 3600,  // optional: old key remains valid for 1 hour
});
```
