---
title: Create Session
url: https://docs.kaltura.com/docs/conversational-agents/agentic-avatars-sdk/control-api-create-session
---

## Create Session

Create a new avatar session.

### Endpoint

```
POST /v1/avatar-session
```

### Authentication

**Header:** `Authorization`

```
Authorization: KS your-kaltura-session-here
```

:::danger Security
Never expose your Kaltura Session in client-side code. Always call this endpoint from your backend server.
:::

### Request Body

```json
{
  "visualConfig": {
    "id": "string"
  },
  "voiceConfig": {
    "id": "string",
    "modelId": "string",
    "language": "string"
  }
}
```

#### Parameters

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `visualConfig` | object | Yes | Avatar visual configuration |
| `visualConfig.id` | string | Yes | ID of the visual to use |
| `voiceConfig` | object | No | Voice configuration for TTS |
| `voiceConfig.id` | string | No | ID of the voice to use |
| `voiceConfig.modelId` | string | No | TTS model ID (e.g., `eleven_flash_v2_5`) |
| `voiceConfig.language` | string | No | TTS language code (e.g., `en`, `es`, `ja`) |

### Response

#### Success (200)

```json
{
  "success": true,
  "sessionId": "string",
  "token": "string"
}
```

| Field | Type | Description |
|-------|------|-------------|
| `success` | boolean | Always `true` on success |
| `sessionId` | string | Unique session identifier |
| `token` | string | JWT token for session authentication |

#### Error Responses

**401 Unauthorized**

```json
{
  "success": false,
  "error": "Invalid Kaltura Session"
}
```

**403 Forbidden**

```json
{
  "success": false,
  "error": "Kaltura Session not authorized"
}
```

**500 Server Error**

```json
{
  "success": false,
  "error": "Internal server error"
}
```

### Examples

#### cURL

```bash
curl -X POST https://api.avatar.us.kaltura.ai/v1/avatar-session/create \
  -H "Authorization: KS your-kaltura-session" \
  -H "Content-Type: application/json" \
  -d '{
    "clientId": "kaltura-avatar-sdk",
    "visualConfig": {
      "id": "visual-123"
    },
    "voiceConfig": {
      "id": "voice-456",
      "modelId": "eleven_flash_v2_5",
      "language": "en"
    }
  }'
```

#### JavaScript (fetch)

```javascript
const response = await fetch('https://api.avatar.us.kaltura.ai/v1/avatar-session/create', {
  method: 'POST',
  headers: {
    Authorization: `KS ${process.env.AVATAR_KS}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    clientId: 'kaltura-avatar-sdk',
    visualConfig: {
      id: 'visual-123',
    },
    voiceConfig: {
      id: 'voice-456',
      modelId: 'eleven_flash_v2_5',
      language: 'en',
    },
  }),
});

const data = await response.json();
console.log('Session ID:', data.sessionId);
console.log('Token:', data.token);
```

#### Node.js (axios)

```javascript
const axios = require('axios');

const response = await axios.post(
  'https://api.avatar.us.kaltura.ai/v1/avatar-session/create',
  {
    clientId: 'kaltura-avatar-sdk',
    visualConfig: {
      id: 'visual-123',
    },
    voiceConfig: {
      id: 'voice-456',
      modelId: 'eleven_flash_v2_5',
      language: 'en',
    },
  },
  {
    headers: {
      Authorization: `KS ${process.env.AVATAR_KS}`,
      'Content-Type': 'application/json',
    },
  }
);

const { sessionId, token } = response.data;
```

#### Python (requests)

```python
import requests
import os

response = requests.post(
    'https://api.avatar.us.kaltura.ai/v1/avatar-session/create',
    headers={
        'Authorization': f'KS {os.environ.get("AVATAR_KS")}',
        'Content-Type': 'application/json'
    },
    json={
        'clientId': 'kaltura-avatar-sdk',
        'visualConfig': {
            'id': 'visual-123'
        },
        'voiceConfig': {
            'id': 'voice-456',
            'modelId': 'eleven_flash_v2_5',
            'language': 'en'
        }
    }
)

data = response.json()
session_id = data['sessionId']
token = data['token']
```

### Usage Notes

#### Session Lifecycle

After creating a session:

1. **Initialize client** - Call init-client to get WebRTC config
2. **Use the session** - Call other endpoints to control the avatar
3. **Keep alive** - Send keep-alive every 10 seconds
4. **End session** - Call end-session when done

#### Token Usage

The returned JWT token must be used for all subsequent API calls for this session:

```javascript
// Use the token in Authorization header
fetch(`https://api.avatar.us.kaltura.ai/v1/avatar-session/${sessionId}/say-text`, {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${token}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ text: 'Hello!' }),
});
```

#### Voice Configuration

The `voiceConfig` is optional. If not provided, the default voice will be used.

**Language:** Specify a TTS language code (e.g., `en`, `es`, `ja`) to control the voice language. See TTS Languages for the full list of 33 supported languages.

**Model ID:** The `modelId` field specifies which TTS engine to use (e.g., `eleven_flash_v2_5`).

#### Error Handling

Always check for errors:

```javascript
const response = await fetch(url, options);
if (!response.ok) {
  const error = await response.json();
  console.error('Failed to create session:', error.error);
  throw new Error(error.error);
}
const data = await response.json();
```

### Next Steps

After creating a session:

1. **Initialize Client** - Get WebRTC configuration
2. **Say Text** - Make the avatar speak
3. **End Session** - Clean up when done
