> ## Documentation Index
> Fetch the complete documentation index at: https://arize-ax.mintlify.site/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 **BETA**. The API may change without notice. A one-time warning is emitted on first use. The `createApiKey` and `refreshApiKey` functions are in **ALPHA**.
</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",    // filter service keys by space (optional)
  userId: "your_user",      // 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 an `organizations` array. Each organization needs an `orgId` and at least one space binding (each with a `spaceId` and an optional `role`). An optional `accountRole` sets the bot user's account-level role (defaults to `member`).

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

const serviceKey = await createApiKey({
  name: "service-key",
  keyType: "SERVICE",
  organizations: [
    {
      orgId: "T3JnMTIz",
      spaces: [
        { spaceId: "U3BhY2UxMjM", role: { name: "MEMBER" } },
        { spaceId: "U3BhY2U0NTY", role: { name: "READ_ONLY" } },
      ],
    },
  ],
  accountRole: { name: "MEMBER" },  // optional
  expiresAt: "2026-12-31T00:00:00Z",  // optional
});
```

## Revoke an API Key

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

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

## 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" });
// 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",
  expiresAt: "2027-12-31T00:00:00Z",
  gracePeriodSeconds: 3600,  // optional: old key remains valid for 1 hour
});
```
