# AIOZ Stream — API Keys

SDK package: @aiozstream/nodejs-client

## Setup

```typescript
import StreamClient from '@aiozstream/nodejs-client'

const client = new StreamClient({
  publicKey: process.env.AIOZ_PUBLIC_KEY,
  secretKey: process.env.AIOZ_SECRET_KEY
})
```

---

## Create API Key

POST https://api.aiozstream.network/api/api_keys

```typescript
const result = await client.apiKey.create({
  apiKeyName: 'my-api-key',
  ttl: 100000000,       // seconds, max 2147483647
  type: 'full_access'   // 'full_access' | 'only_upload'
})
console.log(result.data.apiKey.publicKey)
console.log(result.data.apiKey.secret) // save immediately — not shown again
```

Response fields:
- id, name, public_key, ttl, secret, truncated_secret
- created_at, updated_at, expired_at
- type: 'full_access' | 'only_upload'

Note: Record the secret immediately — it will not be accessible again.

---

## List API Keys

GET https://api.aiozstream.network/api/api_keys

```typescript
const result = await client.apiKey.list({
  search: 'name',
  offset: 0,
  limit: 25,
  sortBy: 'created_at',  // 'created_at' | 'name'
  orderBy: 'asc'         // 'asc' | 'desc'
})
console.log(result.data.apiKeys)
console.log(result.data.total)
```

---

## Delete API Key

DELETE https://api.aiozstream.network/api/api_keys/{id}

```typescript
await client.apiKey.delete('api_key_id')
```

---

## Update API Key (Rename)

PATCH https://api.aiozstream.network/api/api_keys/{id}

```typescript
await client.apiKey.update('api_key_id', {
  apiKeyName: 'new-name'
})
```
