# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
This site has an agentic ask interface you may use to query the documentation dynamically by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.ojin.ai/index.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

---

# Welcome

Build AI Agents That Feel Human. In Minutes.

<figure><img src="https://716616036-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FS2Pj5IbDX90dps067L35%2Fuploads%2Fgit-blob-c1622ca33076f8f2a73fc27b60a5f64e72a17dfa%2Fhero.avif?alt=media" alt="" height="331" width="200"><figcaption><p>Live in real time. Speech in, synchronized video out.</p></figcaption></figure>

***

## Get started in 2 minutes

The fastest way to deploy a conversational AI agent with a lifelike avatar:

**1. Get your API key** → [Create one here](/getting-started/authentication)

**2. Create an agent** in the [dashboard](https://ojin.ai/dashboard). Pick a face, voice, and personality.

**3. Embed on your site:**

{% tabs %}
{% tab title="Plain HTML" %}

```html
<script src="https://cdn.jsdelivr.net/npm/@ojin/agent@latest/dist/ojin-agent.js"></script>
<ojin-agent
  agent-id="your-agent-id"
  core-api-endpoint="https://api.ojin.ai"
></ojin-agent>
```

{% endtab %}

{% tab title="React" %}
Vite or Create React App. Load the script once, then drop in the tag.

Vite uses the project-root `index.html`. Create React App uses `public/index.html`.

```html
<!-- Vite: index.html. Create React App: public/index.html -->
<script src="https://cdn.jsdelivr.net/npm/@ojin/agent@latest/dist/ojin-agent.js"></script>
```

```tsx
declare module "react" {
  namespace JSX {
    interface IntrinsicElements {
      "ojin-agent": React.DetailedHTMLProps<
        React.HTMLAttributes<HTMLElement>,
        HTMLElement
      > & {
        "agent-id"?: string;
        "core-api-endpoint"?: string;
      };
    }
  }
}

export function AgentEmbed() {
  return (
    <ojin-agent
      agent-id="your-agent-id"
      core-api-endpoint="https://api.ojin.ai"
    ></ojin-agent>
  );
}
```

{% endtab %}

{% tab title="Next.js" %}
App Router. Load the script on the client only. The widget uses `window` at mount time:

```tsx
import Script from "next/script";

declare module "react" {
  namespace JSX {
    interface IntrinsicElements {
      "ojin-agent": React.DetailedHTMLProps<
        React.HTMLAttributes<HTMLElement>,
        HTMLElement
      > & {
        "agent-id"?: string;
        "core-api-endpoint"?: string;
      };
    }
  }
}

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body>
        {children}
        <Script
          src="https://cdn.jsdelivr.net/npm/@ojin/agent@latest/dist/ojin-agent.js"
          strategy="afterInteractive"
        />
        <ojin-agent
          agent-id="your-agent-id"
          core-api-endpoint="https://api.ojin.ai"
        />
      </body>
    </html>
  );
}
```

{% endtab %}
{% endtabs %}

That's it. Your users get a live conversational agent with video, audio, and a real-time avatar. [Full Human Agent docs →](/apps/overview)

***

## What Ojin offers

### Apps: deploy in minutes

#### Human Agent

A complete conversational AI agent with a realistic visual avatar. Speech in, speech out, with synchronized lip movements and expressions. Two modes:

* **Ojin Agent:** Ojin handles everything (STT, LLM, TTS, avatar). You configure the personality.
* **Third-Party Agent:** bring your own speech-to-speech provider (ElevenLabs Agents, OpenAI Realtime; Hume on request). Ojin adds the face.

[Get started →](/apps/overview)

### Models: build custom pipelines

Drive Ojin's real-time face models from your own stack. Both are powered by the same [Python SDK](/models/build-with-python-sdk) and [Pipecat](/models/introduction/integrations) integration. Pick the model with its `config_id`.

#### ojin/human-presence

Our **flagship** face model: a fully expressive, generative presence with rich expressions and natural movement (including the hands) that goes beyond lip-sync.

[Learn more →](/models/human-presence)

#### ojin/human-portrait

A **cost-effective**, real-time lipsync model. Transforms a single reference image into a natural animated persona with audio-synchronized lip movements and expressions. Streams at 25 fps, square, at 1024x1024.

[Learn more →](/models/human-portrait)

***

## Core features

* **Human Agent:** end-to-end conversational AI with a lifelike visual avatar. One widget embed, no pipeline assembly.
* **Real-time streaming:** WebSocket and WebRTC transport built for live, conversational latency.
* **One-shot personas:** create a lifelike persona from a single reference image. No training, ready immediately.
* **Python SDK and Pipecat:** drive the face models from [`ojin-client`](/models/build-with-python-sdk), or drop [`pipecat-ojin`](/models/introduction/integrations) into a Pipecat pipeline. Raw WebSocket and REST when you need them.
* **Auto-scale:** capacity scales with demand, so you never manage GPUs or pre-warm anything.
* **Cost-effective:** competitive per-minute pricing with no commitments. 200 free credits to start.

***

## Use cases

* **Customer Support:** deploy lifelike agents for personalized 24/7 support
* **Sales:** greet, qualify, and convert leads with conversational avatars
* **Education:** build interactive tutors with natural speech and expressions
* **Onboarding and Training:** conversational AI for employee learning
* **Brand Ambassador:** always-on, always-on-brand digital representative
* **Healthcare:** empathetic virtual health assistants

***

## LLM-Ready Docs

{% hint style="info" %}
This documentation is optimized for LLM access:

* **MCP Server:** [`docs.ojin.ai/~gitbook/mcp`](https://docs.ojin.ai/~gitbook/mcp)
* [**llms.txt**](https://docs.ojin.ai/llms.txt)**:** structured index
* [**llms-full.txt**](https://docs.ojin.ai/llms-full.txt)**:** full content
* Append `.md` to any page URL for raw markdown

**Note:** `llms.txt` and `llms-full.txt` are auto-generated from the published sitemap.
{% endhint %}


# Quickstart

Get up and running with Ojin in minutes.

This guide walks you through both paths, deploying a full conversational agent with the no-code Human Agent app, or driving a real-time face model from your own pipeline with the Python SDK.

## Choose Your Path

Ojin offers two ways to build with real-time AI, start with whichever fits:

### Deploy a Human Agent, no code (fastest)

Deploy an end-to-end conversational AI agent with a visual avatar. Ojin handles the entire pipeline, or bring your own speech-to-speech provider. No pipeline assembly required. **No API key needed**: you build the agent in the dashboard and the widget talks to Ojin on its own.

1. [Create & configure your agent](/apps/overview/configure) in the dashboard
2. [Embed the widget](/apps/overview/widget-integration) on your site. One HTML tag, done

### Build with the SDK. Your own pipeline

Use Ojin's real-time face models for the visual avatar layer in your own conversational pipeline. You control the full stack, STT, LLM, TTS, and the [Python SDK](/models/build-with-python-sdk) or [Pipecat](/models/introduction/integrations) turns your TTS audio into a synchronized talking avatar. Pick [`ojin/human-presence`](/models/human-presence) (flagship) or [`ojin/human-portrait`](/models/human-portrait) (cost-effective) with its `config_id`.

1. [Get your API key from the Ojin dashboard](/getting-started/authentication). This path calls Ojin from your own backend, so it needs one
2. [Build with the Python SDK](/models/build-with-python-sdk), install, authenticate, and stream your first avatar
3. Or drop the avatar into a [Pipecat](/models/introduction/integrations) voice agent

{% hint style="warning" %}
Never hardcode your API key directly in your application code or commit it to version control.
{% endhint %}

## Troubleshooting

Run into a snag? Check the [Troubleshooting guide](/guides/troubleshooting) or [reach out to support](/getting-started/support).

## Next Steps

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Build with the Python SDK</strong></td><td>Install, authenticate, and stream your first avatar.</td><td><a href="/models/build-with-python-sdk">Python SDK</a></td></tr><tr><td><strong>Human Agent</strong></td><td>Learn more about the full agent product.</td><td><a href="/apps/overview">Human Agent</a></td></tr></tbody></table>


# Get your API key

API keys authenticate server-side calls to the REST API and to the realtime WebSocket. The public widget endpoints under `/v1/public/*` need no key, and dashboard-only areas (API keys, billing, account) are reached with your dashboard login rather than a key. This guide explains how to create, manage, and securely use API keys in your applications.

## Creating an API Key

1. **Sign in** to your [Ojin Dashboard](https://ojin.ai)
2. Navigate to the **API Keys** section
3. Click **Create API Key**
4. Enter a descriptive name for your key (e.g., "Development", "Production")
5. Click **Create**
6. **Important**: Copy and store your API key securely. It will only be shown once.

{% hint style="warning" %}
An API key grants unscoped access to everything in your organization that the API exposes: agents, sessions, assets, model configurations and realtime inference. Never expose them in client-side code, public repositories, or share them with unauthorized individuals.
{% endhint %}

## API Key Best Practices

* **Separate keys** for development and production environments
* **Use environment variables** to store API keys without exposing them publicly
* **Treat every key as a full credential.** There are no per-key scopes today: every key carries the same organization-wide access
* **Rotate keys** periodically for enhanced security
* **Revoke compromised keys** immediately in your dashboard
* **Use secret management services** in production environments
* **Monitor usage** to detect unusual patterns that might indicate a leak


# REST API

Use the REST API to manage persistent Ojin resources such as model configurations, assets, and Human Agents.

The raw OpenAPI specification for this API is also available at [openapi.gitbook.com/o/V9IIQ3Cw10PlDcbzN32h/spec/ojin-rest-api.json](https://openapi.gitbook.com/o/V9IIQ3Cw10PlDcbzN32h/spec/ojin-rest-api.json).

{% hint style="info" %}
This page covers the HTTP REST API. It is separate from Ojin's realtime model APIs, which use WebSockets for streaming media. For example, for `ojin/human-portrait`, see [Realtime API Reference](/models/introduction/api).
{% endhint %}

## Authentication

Authenticated REST endpoints require an API key in the `X-API-Key` header.

```bash
curl https://api.ojin.ai/v1/model-configs \
  -H "X-API-Key: $OJIN_API_KEY"
```

For API key setup guidance, see [Get your API key](/getting-started/authentication).

## Caching

Responses declare `Cache-Control: private, no-store` by default, so neither clients nor intermediaries should store them. A few endpoints are deliberately cacheable and say so in their own `Cache-Control` response header. Read the emitted header rather than assuming a fixed policy or a fixed window.

## Model Configurations

Use model configurations to create and manage reusable settings for Ojin models.

`model_configurations` is variant-specific. To determine the correct object shape, first fetch the target model variant and read its `configuration_schema`, then build your `model_configurations` payload to match that JSON Schema.

## List Model Configurations

> Retrieves a list of Model Configurations. By default returns only organization-owned configurations. Use source='template' to retrieve template configurations instead. Supports pagination and filtering by model variant.

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Model Configurations","description":"Operations related to user-defined configurations of model variants for API clients and product integrations."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"parameters":{"ModelVariantIdQueryParameter":{"name":"model_variant_id","in":"query","required":false,"description":"Filter model configurations by the model_variant_id.","schema":{"type":"string"}},"ModelVariantTagQueryParameter":{"name":"model_variant_tag","in":"query","required":false,"description":"Filter model configurations whose model variant contains this tag (e.g. \"_agent-tts\").","schema":{"type":"string"}},"SourceQueryParameter":{"name":"source","in":"query","required":false,"description":"Filter items by ownership source. Use 'org' for items owned by the user's organization, 'template' for items from the template organization. Defaults to 'org'.","schema":{"type":"string","enum":["org","template"],"default":"org"}},"LimitQueryParameter":{"name":"limit","in":"query","required":false,"description":"Number of items to return per page.","schema":{"type":"integer","default":20,"minimum":1,"maximum":100}},"OffsetQueryParameter":{"name":"offset","in":"query","required":false,"description":"Number of items to skip for pagination.","schema":{"type":"integer","default":0,"minimum":0}}},"schemas":{"ModelConfig":{"type":"object","description":"Represents a specific configuration of a ModelVariant.","properties":{"model_config_id":{"type":"string","format":"uuid","readOnly":true,"description":"Server-generated unique ID."},"organization_id":{"type":"string","readOnly":true,"description":"Owning organization ID (from external IdP)."},"model_id":{"type":"string","readOnly":true,"description":"ID of the parent Model, derived from the Model Variant."},"model_variant_id":{"type":"string","description":"ID of the ModelVariant being configured. NOT NULL."},"created_by":{"type":"string","readOnly":true,"description":"Creator's user ID (from external IdP), or `api_key:<id>` when created via an API key."},"title":{"type":"string","description":"Title for the configuration. NOT NULL, unique per organization_id."},"model_configurations":{"type":"object","additionalProperties":true,"description":"Parameters for the model variant, adhering to its schema. NOT NULL, defaults to '{}'.","default":{}},"created_at":{"type":"string","format":"date-time","readOnly":true,"description":"Timestamp of creation. Defaults to CURRENT_TIMESTAMP."},"updated_at":{"type":"string","format":"date-time","readOnly":true,"description":"Timestamp of last update. Auto-updates."}},"required":["model_config_id","organization_id","model_id","model_variant_id","created_by","title","model_configurations","created_at","updated_at"]},"Pagination":{"type":"object","properties":{"limit":{"type":"integer","description":"The number of items returned in the current page."},"offset":{"type":"integer","description":"The number of items skipped before starting the current page."},"total_items":{"type":"integer","description":"The total number of items available that match the query."}},"required":["limit","offset","total_items"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"BadRequestError":{"description":"Invalid request payload or parameters.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"ForbiddenError":{"description":"Authenticated principal does not have permission.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/model-configs":{"get":{"tags":["Model Configurations"],"summary":"List Model Configurations","description":"Retrieves a list of Model Configurations. By default returns only organization-owned configurations. Use source='template' to retrieve template configurations instead. Supports pagination and filtering by model variant.","operationId":"listModelConfigs","parameters":[{"$ref":"#/components/parameters/ModelVariantIdQueryParameter"},{"$ref":"#/components/parameters/ModelVariantTagQueryParameter"},{"$ref":"#/components/parameters/SourceQueryParameter"},{"$ref":"#/components/parameters/LimitQueryParameter"},{"$ref":"#/components/parameters/OffsetQueryParameter"}],"responses":{"200":{"description":"A paginated list of model configurations.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/ModelConfig"}},"pagination":{"$ref":"#/components/schemas/Pagination"}}}}}},"400":{"$ref":"#/components/responses/BadRequestError"},"401":{"$ref":"#/components/responses/UnauthorizedError"},"403":{"$ref":"#/components/responses/ForbiddenError"}}}}}}
```

## POST /model-configs

> Create a new Model Configuration

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Model Configurations","description":"Operations related to user-defined configurations of model variants for API clients and product integrations."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"schemas":{"ModelConfigCreationRequest":{"type":"object","description":"Payload for creating a new Model Configuration.","properties":{"title":{"type":"string"},"model_variant_id":{"type":"string"},"model_configurations":{"type":"object","additionalProperties":true,"default":{}}},"required":["title","model_variant_id"]},"ModelConfig":{"type":"object","description":"Represents a specific configuration of a ModelVariant.","properties":{"model_config_id":{"type":"string","format":"uuid","readOnly":true,"description":"Server-generated unique ID."},"organization_id":{"type":"string","readOnly":true,"description":"Owning organization ID (from external IdP)."},"model_id":{"type":"string","readOnly":true,"description":"ID of the parent Model, derived from the Model Variant."},"model_variant_id":{"type":"string","description":"ID of the ModelVariant being configured. NOT NULL."},"created_by":{"type":"string","readOnly":true,"description":"Creator's user ID (from external IdP), or `api_key:<id>` when created via an API key."},"title":{"type":"string","description":"Title for the configuration. NOT NULL, unique per organization_id."},"model_configurations":{"type":"object","additionalProperties":true,"description":"Parameters for the model variant, adhering to its schema. NOT NULL, defaults to '{}'.","default":{}},"created_at":{"type":"string","format":"date-time","readOnly":true,"description":"Timestamp of creation. Defaults to CURRENT_TIMESTAMP."},"updated_at":{"type":"string","format":"date-time","readOnly":true,"description":"Timestamp of last update. Auto-updates."}},"required":["model_config_id","organization_id","model_id","model_variant_id","created_by","title","model_configurations","created_at","updated_at"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"BadRequestError":{"description":"Invalid request payload or parameters.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"ForbiddenError":{"description":"Authenticated principal does not have permission.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/model-configs":{"post":{"tags":["Model Configurations"],"summary":"Create a new Model Configuration","operationId":"createModelConfig","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ModelConfigCreationRequest"}}}},"responses":{"201":{"description":"Model Configuration created.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ModelConfig"}}}},"400":{"$ref":"#/components/responses/BadRequestError"},"401":{"$ref":"#/components/responses/UnauthorizedError"},"403":{"$ref":"#/components/responses/ForbiddenError"},"404":{"description":"Referenced ModelVariant not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## GET /model-configs/{model\_config\_id}

> Retrieve a specific Model Configuration

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Model Configurations","description":"Operations related to user-defined configurations of model variants for API clients and product integrations."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"parameters":{"ModelConfigIdPathParameter":{"name":"model_config_id","in":"path","required":true,"description":"The unique identifier (UUID) of the Model Configuration.","schema":{"type":"string","format":"uuid"}}},"schemas":{"ModelConfig":{"type":"object","description":"Represents a specific configuration of a ModelVariant.","properties":{"model_config_id":{"type":"string","format":"uuid","readOnly":true,"description":"Server-generated unique ID."},"organization_id":{"type":"string","readOnly":true,"description":"Owning organization ID (from external IdP)."},"model_id":{"type":"string","readOnly":true,"description":"ID of the parent Model, derived from the Model Variant."},"model_variant_id":{"type":"string","description":"ID of the ModelVariant being configured. NOT NULL."},"created_by":{"type":"string","readOnly":true,"description":"Creator's user ID (from external IdP), or `api_key:<id>` when created via an API key."},"title":{"type":"string","description":"Title for the configuration. NOT NULL, unique per organization_id."},"model_configurations":{"type":"object","additionalProperties":true,"description":"Parameters for the model variant, adhering to its schema. NOT NULL, defaults to '{}'.","default":{}},"created_at":{"type":"string","format":"date-time","readOnly":true,"description":"Timestamp of creation. Defaults to CURRENT_TIMESTAMP."},"updated_at":{"type":"string","format":"date-time","readOnly":true,"description":"Timestamp of last update. Auto-updates."}},"required":["model_config_id","organization_id","model_id","model_variant_id","created_by","title","model_configurations","created_at","updated_at"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"ForbiddenError":{"description":"Authenticated principal does not have permission.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"NotFoundError":{"description":"The requested resource was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/model-configs/{model_config_id}":{"get":{"tags":["Model Configurations"],"summary":"Retrieve a specific Model Configuration","operationId":"getModelConfigById","parameters":[{"$ref":"#/components/parameters/ModelConfigIdPathParameter"}],"responses":{"200":{"description":"Model Configuration details.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ModelConfig"}}}},"401":{"$ref":"#/components/responses/UnauthorizedError"},"403":{"$ref":"#/components/responses/ForbiddenError"},"404":{"$ref":"#/components/responses/NotFoundError"}}}}}}
```

## PUT /model-configs/{model\_config\_id}

> Update an existing Model Configuration

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Model Configurations","description":"Operations related to user-defined configurations of model variants for API clients and product integrations."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"parameters":{"ModelConfigIdPathParameter":{"name":"model_config_id","in":"path","required":true,"description":"The unique identifier (UUID) of the Model Configuration.","schema":{"type":"string","format":"uuid"}}},"schemas":{"ModelConfigUpdateRequest":{"type":"object","description":"Payload for updating a Model Configuration (title and parameters only).","properties":{"title":{"type":"string"},"model_configurations":{"type":"object","additionalProperties":true}},"required":["title","model_configurations"]},"ModelConfig":{"type":"object","description":"Represents a specific configuration of a ModelVariant.","properties":{"model_config_id":{"type":"string","format":"uuid","readOnly":true,"description":"Server-generated unique ID."},"organization_id":{"type":"string","readOnly":true,"description":"Owning organization ID (from external IdP)."},"model_id":{"type":"string","readOnly":true,"description":"ID of the parent Model, derived from the Model Variant."},"model_variant_id":{"type":"string","description":"ID of the ModelVariant being configured. NOT NULL."},"created_by":{"type":"string","readOnly":true,"description":"Creator's user ID (from external IdP), or `api_key:<id>` when created via an API key."},"title":{"type":"string","description":"Title for the configuration. NOT NULL, unique per organization_id."},"model_configurations":{"type":"object","additionalProperties":true,"description":"Parameters for the model variant, adhering to its schema. NOT NULL, defaults to '{}'.","default":{}},"created_at":{"type":"string","format":"date-time","readOnly":true,"description":"Timestamp of creation. Defaults to CURRENT_TIMESTAMP."},"updated_at":{"type":"string","format":"date-time","readOnly":true,"description":"Timestamp of last update. Auto-updates."}},"required":["model_config_id","organization_id","model_id","model_variant_id","created_by","title","model_configurations","created_at","updated_at"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"BadRequestError":{"description":"Invalid request payload or parameters.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"ForbiddenError":{"description":"Authenticated principal does not have permission.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"NotFoundError":{"description":"The requested resource was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/model-configs/{model_config_id}":{"put":{"tags":["Model Configurations"],"summary":"Update an existing Model Configuration","operationId":"updateModelConfig","parameters":[{"$ref":"#/components/parameters/ModelConfigIdPathParameter"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ModelConfigUpdateRequest"}}}},"responses":{"200":{"description":"Model Configuration updated.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ModelConfig"}}}},"400":{"$ref":"#/components/responses/BadRequestError"},"401":{"$ref":"#/components/responses/UnauthorizedError"},"403":{"$ref":"#/components/responses/ForbiddenError"},"404":{"$ref":"#/components/responses/NotFoundError"}}}}}}
```

## DELETE /model-configs/{model\_config\_id}

> Delete a Model Configuration

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Model Configurations","description":"Operations related to user-defined configurations of model variants for API clients and product integrations."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"parameters":{"ModelConfigIdPathParameter":{"name":"model_config_id","in":"path","required":true,"description":"The unique identifier (UUID) of the Model Configuration.","schema":{"type":"string","format":"uuid"}},"ReferencedByQueryParameter":{"name":"referenced_by","in":"query","required":false,"description":"Delete reference to the agent configuration.","schema":{"type":"string","format":"uuid"}}},"responses":{"NoContentSuccess":{"description":"Operation successful, no content to return."},"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"ForbiddenError":{"description":"Authenticated principal does not have permission.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"NotFoundError":{"description":"The requested resource was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"schemas":{"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}}},"paths":{"/model-configs/{model_config_id}":{"delete":{"tags":["Model Configurations"],"summary":"Delete a Model Configuration","operationId":"deleteModelConfig","parameters":[{"$ref":"#/components/parameters/ModelConfigIdPathParameter"},{"$ref":"#/components/parameters/ReferencedByQueryParameter"}],"responses":{"204":{"$ref":"#/components/responses/NoContentSuccess"},"401":{"$ref":"#/components/responses/UnauthorizedError"},"403":{"$ref":"#/components/responses/ForbiddenError"},"404":{"$ref":"#/components/responses/NotFoundError"},"409":{"description":"Conflict - Cannot delete, referenced by AgentConfig.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## Model Variants

Use model variant endpoints to discover public variants and retrieve the `configuration_schema` that defines the expected shape of `model_configurations`.

## List all Model Variants

> List all Model Variants.\
> Public callers, including API-key-authenticated callers, only receive variants with status="public",\
> ignoring other status filters.

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Model Variants","description":"Operations related to specific variants of models."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"parameters":{"ModelIdQueryParameter":{"name":"model_id","in":"query","required":false,"description":"Filter model variants by parent model_id.","schema":{"type":"string"}},"StatusQueryParameter":{"name":"status","in":"query","required":false,"description":"Filter by status.","schema":{"type":"string"}},"TagsQueryParameter":{"name":"tags","in":"query","required":false,"description":"Filter model variants by a comma-separated list of tags (AND logic).","style":"form","explode":false,"schema":{"type":"array","items":{"type":"string"}}},"LimitQueryParameter":{"name":"limit","in":"query","required":false,"description":"Number of items to return per page.","schema":{"type":"integer","default":20,"minimum":1,"maximum":100}},"OffsetQueryParameter":{"name":"offset","in":"query","required":false,"description":"Number of items to skip for pagination.","schema":{"type":"integer","default":0,"minimum":0}}},"schemas":{"ModelVariant":{"type":"object","description":"Represents a specific variant of a Model.","properties":{"model_variant_id":{"type":"string","description":"Client-provided unique identifier (e.g., \"ojin/oris-v1/standard\")."},"model_id":{"type":"string","description":"Identifier of the parent Model. NOT NULL."},"title":{"type":"string","description":"Display name for the variant. NOT NULL, unique per model_id."},"description":{"type":"object","additionalProperties":{"type":"string"},"description":"UI display texts. NOT NULL, defaults to '{}'."},"preview_media_url":{"type":"string","format":"url","nullable":true,"description":"URL for a preview media."},"configuration_schema":{"type":"object","description":"JSON schema for ModelConfig.model_configurations. NOT NULL, defaults to '{}'.","additionalProperties":true},"tags":{"type":"array","items":{"type":"string"},"description":"List of descriptive tags. NOT NULL, defaults to '[]'."},"status":{"type":"string","description":"Status (e.g., 'available', 'deprecated'). NOT NULL. List managed in code."},"created_at":{"type":"string","format":"date-time","description":"Timestamp of creation. Server-generated. Defaults to CURRENT_TIMESTAMP.","readOnly":true},"updated_at":{"type":"string","format":"date-time","description":"Timestamp of last update. Server-generated. Auto-updates.","readOnly":true}},"required":["model_variant_id","model_id","title","description","configuration_schema","tags","status","created_at","updated_at"]},"Pagination":{"type":"object","properties":{"limit":{"type":"integer","description":"The number of items returned in the current page."},"offset":{"type":"integer","description":"The number of items skipped before starting the current page."},"total_items":{"type":"integer","description":"The total number of items available that match the query."}},"required":["limit","offset","total_items"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"BadRequestError":{"description":"Invalid request payload or parameters.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"ForbiddenError":{"description":"Authenticated principal does not have permission.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/model-variants":{"get":{"tags":["Model Variants"],"summary":"List all Model Variants","description":"List all Model Variants.\nPublic callers, including API-key-authenticated callers, only receive variants with status=\"public\",\nignoring other status filters.","operationId":"listModelVariants","parameters":[{"$ref":"#/components/parameters/ModelIdQueryParameter"},{"$ref":"#/components/parameters/StatusQueryParameter"},{"$ref":"#/components/parameters/TagsQueryParameter"},{"$ref":"#/components/parameters/LimitQueryParameter"},{"$ref":"#/components/parameters/OffsetQueryParameter"}],"responses":{"200":{"description":"A paginated list of model variants.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/ModelVariant"}},"pagination":{"$ref":"#/components/schemas/Pagination"}}}}}},"400":{"$ref":"#/components/responses/BadRequestError"},"401":{"$ref":"#/components/responses/UnauthorizedError"},"403":{"$ref":"#/components/responses/ForbiddenError"}}}}}}
```

## Retrieve a specific Model Variant

> Retrieve a specific Model Variant by ID.\
> Public callers, including API-key-authenticated callers, can retrieve the variant only if status="public".\
> Otherwise returns 404.

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Model Variants","description":"Operations related to specific variants of models."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"parameters":{"ModelVariantIdPathParameter":{"name":"model_variant_id","in":"path","required":true,"description":"The unique identifier of the model variant.","schema":{"type":"string"}}},"schemas":{"ModelVariant":{"type":"object","description":"Represents a specific variant of a Model.","properties":{"model_variant_id":{"type":"string","description":"Client-provided unique identifier (e.g., \"ojin/oris-v1/standard\")."},"model_id":{"type":"string","description":"Identifier of the parent Model. NOT NULL."},"title":{"type":"string","description":"Display name for the variant. NOT NULL, unique per model_id."},"description":{"type":"object","additionalProperties":{"type":"string"},"description":"UI display texts. NOT NULL, defaults to '{}'."},"preview_media_url":{"type":"string","format":"url","nullable":true,"description":"URL for a preview media."},"configuration_schema":{"type":"object","description":"JSON schema for ModelConfig.model_configurations. NOT NULL, defaults to '{}'.","additionalProperties":true},"tags":{"type":"array","items":{"type":"string"},"description":"List of descriptive tags. NOT NULL, defaults to '[]'."},"status":{"type":"string","description":"Status (e.g., 'available', 'deprecated'). NOT NULL. List managed in code."},"created_at":{"type":"string","format":"date-time","description":"Timestamp of creation. Server-generated. Defaults to CURRENT_TIMESTAMP.","readOnly":true},"updated_at":{"type":"string","format":"date-time","description":"Timestamp of last update. Server-generated. Auto-updates.","readOnly":true}},"required":["model_variant_id","model_id","title","description","configuration_schema","tags","status","created_at","updated_at"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"ForbiddenError":{"description":"Authenticated principal does not have permission.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"NotFoundError":{"description":"The requested resource was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/model-variants/{model_variant_id}":{"get":{"tags":["Model Variants"],"summary":"Retrieve a specific Model Variant","description":"Retrieve a specific Model Variant by ID.\nPublic callers, including API-key-authenticated callers, can retrieve the variant only if status=\"public\".\nOtherwise returns 404.","operationId":"getModelVariantById","parameters":[{"$ref":"#/components/parameters/ModelVariantIdPathParameter"}],"responses":{"200":{"description":"Model Variant details.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ModelVariant"}}}},"401":{"$ref":"#/components/responses/UnauthorizedError"},"403":{"$ref":"#/components/responses/ForbiddenError"},"404":{"$ref":"#/components/responses/NotFoundError"}}}}}}
```

## Assets

Use asset endpoints to upload, register, retrieve, and delete media used by your Ojin integrations.

## Initiate a Multipart Asset Upload

> Starts the multipart asset upload process by creating a multipart upload session in S3.\
> The Core API generates a unique \`asset\_id\` and receives an \`upload\_id\` from S3.\
> Both IDs must be used in subsequent part signing and finalization requests.\
> No Asset record is created in the database at this stage.

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Assets","description":"Operations related to managing digital assets (images, videos, etc.)."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"schemas":{"AssetInitiateUploadRequest":{"type":"object","description":"Payload to initiate a multipart asset upload.","properties":{"name":{"type":"string","description":"Original filename of the asset."},"category":{"type":"string","description":"Category for the asset (e.g., 'video', 'image')."},"content_type":{"type":"string","nullable":true,"description":"Client-declared MIME type of the file."},"size_bytes":{"type":"integer","format":"int64","nullable":true,"description":"Client-declared file size in bytes."}},"required":["name","category"]},"AssetInitiateUploadResponse":{"type":"object","description":"Response from initiating a multipart asset upload.","properties":{"asset_id":{"type":"string","format":"uuid","description":"A unique ID generated by Core API for this asset transaction."},"upload_id":{"type":"string","description":"The multipart upload ID from S3, used to identify this multipart upload session."},"s3_key":{"type":"string","description":"The S3 key for this asset."}},"required":["asset_id","upload_id"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"BadRequestError":{"description":"Invalid request payload or parameters.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"ForbiddenError":{"description":"Authenticated principal does not have permission.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/assets/initiate-upload":{"post":{"tags":["Assets"],"summary":"Initiate a Multipart Asset Upload","description":"Starts the multipart asset upload process by creating a multipart upload session in S3.\nThe Core API generates a unique `asset_id` and receives an `upload_id` from S3.\nBoth IDs must be used in subsequent part signing and finalization requests.\nNo Asset record is created in the database at this stage.","operationId":"initiateAssetUpload","requestBody":{"description":"Initial metadata for the asset to be uploaded.","required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AssetInitiateUploadRequest"}}}},"responses":{"200":{"description":"Multipart upload initiated successfully. Returns asset_id and upload_id.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AssetInitiateUploadResponse"}}}},"400":{"$ref":"#/components/responses/BadRequestError"},"401":{"$ref":"#/components/responses/UnauthorizedError"},"403":{"$ref":"#/components/responses/ForbiddenError"}}}}}}
```

## Get Pre-signed URL for Upload Part

> Generates a pre-signed URL for uploading a specific part of a multipart upload.\
> This endpoint will be called multiple times, once for each part of the file.\
> Parts must be numbered sequentially starting from 1, and each part (except the last)\
> must be at least 5MB in size (S3 requirement).

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Assets","description":"Operations related to managing digital assets (images, videos, etc.)."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"schemas":{"AssetSignPartRequest":{"type":"object","description":"Payload to get a pre-signed URL for uploading a specific part of a multipart upload.","properties":{"s3_key":{"type":"string","description":"The S3 key for this asset."},"asset_id":{"type":"string","format":"uuid","description":"The asset ID from the initiate upload response."},"upload_id":{"type":"string","description":"The multipart upload ID from the initiate upload response."},"part_number":{"type":"integer","minimum":1,"maximum":10000,"description":"The part number for this upload part (1-10000)."}},"required":["asset_id","upload_id","part_number"]},"AssetSignPartResponse":{"type":"object","description":"Response containing the pre-signed URL for uploading a specific part.","properties":{"upload_url":{"type":"string","format":"url","description":"The pre-signed S3 URL to PUT this specific part to."},"part_number":{"type":"integer","description":"The part number this URL is for."}},"required":["upload_url","part_number"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"BadRequestError":{"description":"Invalid request payload or parameters.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"ForbiddenError":{"description":"Authenticated principal does not have permission.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/assets/sign-part":{"post":{"tags":["Assets"],"summary":"Get Pre-signed URL for Upload Part","description":"Generates a pre-signed URL for uploading a specific part of a multipart upload.\nThis endpoint will be called multiple times, once for each part of the file.\nParts must be numbered sequentially starting from 1, and each part (except the last)\nmust be at least 5MB in size (S3 requirement).","operationId":"signAssetUploadPart","requestBody":{"description":"Details for the part to be signed.","required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AssetSignPartRequest"}}}},"responses":{"200":{"description":"Pre-signed URL generated successfully for the specified part.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AssetSignPartResponse"}}}},"400":{"$ref":"#/components/responses/BadRequestError"},"401":{"$ref":"#/components/responses/UnauthorizedError"},"403":{"$ref":"#/components/responses/ForbiddenError"},"404":{"description":"Multipart upload session not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## Finalize Multipart Upload and Create Asset Record

> Completes a multipart upload by combining all uploaded parts and creates the Asset\
> metadata record in the Core API. The client must provide all part numbers and their\
> corresponding ETags from the S3 upload responses. The Core API will complete the\
> multipart upload in S3 and verify the final object before creating the database record.

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Assets","description":"Operations related to managing digital assets (images, videos, etc.)."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"schemas":{"AssetFinalizationRequest":{"type":"object","description":"Payload to finalize a multipart asset upload and create the asset metadata record in DB.","properties":{"asset_id":{"type":"string","format":"uuid","description":"The unique ID received from the 'initiate-upload' step."},"upload_id":{"type":"string","description":"The multipart upload ID from the 'initiate-upload' step."},"name":{"type":"string","description":"The original filename (must be consistent with initiate request)."},"category":{"type":"string","description":"The asset category (must be consistent with initiate request)."},"content_type":{"type":"string","description":"Final confirmed MIME type of the asset."},"size_bytes":{"type":"integer","format":"int64","description":"Final confirmed size of the asset in bytes."},"parts":{"type":"array","items":{"$ref":"#/components/schemas/AssetUploadPart"},"description":"List of all uploaded parts with their ETags, in order.","minItems":1}},"required":["asset_id","upload_id","name","category","content_type","size_bytes","parts"]},"AssetUploadPart":{"type":"object","description":"Information about a completed upload part.","properties":{"part_number":{"type":"integer","minimum":1,"maximum":10000,"description":"The part number that was uploaded."},"etag":{"type":"string","description":"The ETag returned by S3 after successfully uploading this part."}},"required":["part_number","etag"]},"Asset":{"type":"object","description":"Represents a digital asset managed by the Core API.","properties":{"asset_id":{"type":"string","format":"uuid","description":"Unique identifier for the Asset, generated during upload initiation.","readOnly":true},"organization_id":{"type":"string","description":"ID of the Organisation (from external IdP) that owns this Asset. Server-set.","readOnly":true},"created_by":{"type":"string","description":"User ID of the creator (from external IdP), or `api_key:<id>` when created via an API key. Server-set.","readOnly":true},"name":{"type":"string","description":"The original file name of the Asset. NOT NULL."},"category":{"type":"string","description":"Primary category of the Asset (e.g., 'video', 'image', 'weight'). NOT NULL. List of values managed in code."},"content_type":{"type":"string","description":"The MIME type of the asset. NOT NULL."},"size_bytes":{"type":"integer","format":"int64","description":"The size of the asset in bytes. NOT NULL."},"etag":{"type":"string","description":"The ETag of the S3 object, used for integrity checking. NOT NULL."},"created_at":{"type":"string","format":"date-time","description":"Timestamp of when this Asset record was created (finalized). Server-generated. Defaults to CURRENT_TIMESTAMP.","readOnly":true},"updated_at":{"type":"string","format":"date-time","description":"Timestamp of the last update to this Asset record. Server-generated. Auto-updates on modification.","readOnly":true},"asset_url":{"type":"string","format":"uri","readOnly":true,"description":"A temporary, pre-signed URL to download the asset's content. This URL will expire."}},"required":["asset_id","organization_id","created_by","name","category","content_type","size_bytes","etag","created_at","updated_at"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"BadRequestError":{"description":"Invalid request payload or parameters.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"ForbiddenError":{"description":"Authenticated principal does not have permission.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"ConflictError":{"description":"Conflict with the current state of the resource.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/assets":{"post":{"tags":["Assets"],"summary":"Finalize Multipart Upload and Create Asset Record","description":"Completes a multipart upload by combining all uploaded parts and creates the Asset\nmetadata record in the Core API. The client must provide all part numbers and their\ncorresponding ETags from the S3 upload responses. The Core API will complete the\nmultipart upload in S3 and verify the final object before creating the database record.","operationId":"createAssetRecord","requestBody":{"description":"Finalization details for the multipart asset upload.","required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AssetFinalizationRequest"}}}},"responses":{"201":{"description":"Multipart upload completed successfully and Asset record created in DB.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Asset"}}}},"400":{"$ref":"#/components/responses/BadRequestError"},"401":{"$ref":"#/components/responses/UnauthorizedError"},"403":{"$ref":"#/components/responses/ForbiddenError"},"404":{"description":"Multipart upload session not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"409":{"$ref":"#/components/responses/ConflictError"}}}}}}
```

## List Assets

> Retrieves a list of Asset metadata. By default returns only organization-owned assets. Use source='template' to retrieve template assets instead. Supports pagination and filtering by category and name.

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Assets","description":"Operations related to managing digital assets (images, videos, etc.)."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"parameters":{"SourceQueryParameter":{"name":"source","in":"query","required":false,"description":"Filter items by ownership source. Use 'org' for items owned by the user's organization, 'template' for items from the template organization. Defaults to 'org'.","schema":{"type":"string","enum":["org","template"],"default":"org"}},"AssetCategoryQueryParameter":{"name":"category","in":"query","required":false,"description":"Filter assets by category.","schema":{"type":"string"}},"AssetNameQueryParameter":{"name":"name","in":"query","required":false,"description":"Filter assets by name (e.g., for partial match - specific behavior TBD by implementation).","schema":{"type":"string"}},"LimitQueryParameter":{"name":"limit","in":"query","required":false,"description":"Number of items to return per page.","schema":{"type":"integer","default":20,"minimum":1,"maximum":100}},"OffsetQueryParameter":{"name":"offset","in":"query","required":false,"description":"Number of items to skip for pagination.","schema":{"type":"integer","default":0,"minimum":0}}},"schemas":{"Asset":{"type":"object","description":"Represents a digital asset managed by the Core API.","properties":{"asset_id":{"type":"string","format":"uuid","description":"Unique identifier for the Asset, generated during upload initiation.","readOnly":true},"organization_id":{"type":"string","description":"ID of the Organisation (from external IdP) that owns this Asset. Server-set.","readOnly":true},"created_by":{"type":"string","description":"User ID of the creator (from external IdP), or `api_key:<id>` when created via an API key. Server-set.","readOnly":true},"name":{"type":"string","description":"The original file name of the Asset. NOT NULL."},"category":{"type":"string","description":"Primary category of the Asset (e.g., 'video', 'image', 'weight'). NOT NULL. List of values managed in code."},"content_type":{"type":"string","description":"The MIME type of the asset. NOT NULL."},"size_bytes":{"type":"integer","format":"int64","description":"The size of the asset in bytes. NOT NULL."},"etag":{"type":"string","description":"The ETag of the S3 object, used for integrity checking. NOT NULL."},"created_at":{"type":"string","format":"date-time","description":"Timestamp of when this Asset record was created (finalized). Server-generated. Defaults to CURRENT_TIMESTAMP.","readOnly":true},"updated_at":{"type":"string","format":"date-time","description":"Timestamp of the last update to this Asset record. Server-generated. Auto-updates on modification.","readOnly":true},"asset_url":{"type":"string","format":"uri","readOnly":true,"description":"A temporary, pre-signed URL to download the asset's content. This URL will expire."}},"required":["asset_id","organization_id","created_by","name","category","content_type","size_bytes","etag","created_at","updated_at"]},"Pagination":{"type":"object","properties":{"limit":{"type":"integer","description":"The number of items returned in the current page."},"offset":{"type":"integer","description":"The number of items skipped before starting the current page."},"total_items":{"type":"integer","description":"The total number of items available that match the query."}},"required":["limit","offset","total_items"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"BadRequestError":{"description":"Invalid request payload or parameters.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"ForbiddenError":{"description":"Authenticated principal does not have permission.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/assets":{"get":{"tags":["Assets"],"summary":"List Assets","description":"Retrieves a list of Asset metadata. By default returns only organization-owned assets. Use source='template' to retrieve template assets instead. Supports pagination and filtering by category and name.","operationId":"listAssets","parameters":[{"$ref":"#/components/parameters/SourceQueryParameter"},{"$ref":"#/components/parameters/AssetCategoryQueryParameter"},{"$ref":"#/components/parameters/AssetNameQueryParameter"},{"$ref":"#/components/parameters/LimitQueryParameter"},{"$ref":"#/components/parameters/OffsetQueryParameter"}],"responses":{"200":{"description":"A paginated list of Asset metadata.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Asset"}},"pagination":{"$ref":"#/components/schemas/Pagination"}}}}}},"400":{"$ref":"#/components/responses/BadRequestError"},"401":{"$ref":"#/components/responses/UnauthorizedError"},"403":{"$ref":"#/components/responses/ForbiddenError"}}}}}}
```

## Retrieve Asset Metadata and Download URL

> Retrieves metadata for a specific Asset, including a pre-signed URL for downloading the content. The user can access an asset if it belongs to their organization or to the shared template organization.

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Assets","description":"Operations related to managing digital assets (images, videos, etc.)."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"parameters":{"AssetIdPathParameter":{"name":"asset_id","in":"path","required":true,"description":"The unique identifier (UUID) of the Asset.","schema":{"type":"string","format":"uuid"}}},"schemas":{"Asset":{"type":"object","description":"Represents a digital asset managed by the Core API.","properties":{"asset_id":{"type":"string","format":"uuid","description":"Unique identifier for the Asset, generated during upload initiation.","readOnly":true},"organization_id":{"type":"string","description":"ID of the Organisation (from external IdP) that owns this Asset. Server-set.","readOnly":true},"created_by":{"type":"string","description":"User ID of the creator (from external IdP), or `api_key:<id>` when created via an API key. Server-set.","readOnly":true},"name":{"type":"string","description":"The original file name of the Asset. NOT NULL."},"category":{"type":"string","description":"Primary category of the Asset (e.g., 'video', 'image', 'weight'). NOT NULL. List of values managed in code."},"content_type":{"type":"string","description":"The MIME type of the asset. NOT NULL."},"size_bytes":{"type":"integer","format":"int64","description":"The size of the asset in bytes. NOT NULL."},"etag":{"type":"string","description":"The ETag of the S3 object, used for integrity checking. NOT NULL."},"created_at":{"type":"string","format":"date-time","description":"Timestamp of when this Asset record was created (finalized). Server-generated. Defaults to CURRENT_TIMESTAMP.","readOnly":true},"updated_at":{"type":"string","format":"date-time","description":"Timestamp of the last update to this Asset record. Server-generated. Auto-updates on modification.","readOnly":true},"asset_url":{"type":"string","format":"uri","readOnly":true,"description":"A temporary, pre-signed URL to download the asset's content. This URL will expire."}},"required":["asset_id","organization_id","created_by","name","category","content_type","size_bytes","etag","created_at","updated_at"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"ForbiddenError":{"description":"Authenticated principal does not have permission.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"NotFoundError":{"description":"The requested resource was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/assets/{asset_id}/download":{"get":{"tags":["Assets"],"summary":"Retrieve Asset Metadata and Download URL","description":"Retrieves metadata for a specific Asset, including a pre-signed URL for downloading the content. The user can access an asset if it belongs to their organization or to the shared template organization.","operationId":"getAssetDownloadById","parameters":[{"$ref":"#/components/parameters/AssetIdPathParameter"}],"responses":{"200":{"description":"Successfully retrieved Asset metadata, including a download URL.","content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/Asset"},{"type":"object","properties":{"asset_url":{"type":"string","format":"uri","readOnly":true,"description":"A temporary, pre-signed URL to download the asset's content. This URL will expire."}}}]}}}},"401":{"$ref":"#/components/responses/UnauthorizedError"},"403":{"$ref":"#/components/responses/ForbiddenError"},"404":{"$ref":"#/components/responses/NotFoundError"}}}}}}
```

## Retrieve Asset Metadata

> Retrieves metadata for a specific Asset, including a temporary pre-signed \`asset\_url\` for download. The user can access an asset if it belongs to their organization or to the shared template organization.

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Assets","description":"Operations related to managing digital assets (images, videos, etc.)."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"parameters":{"AssetIdPathParameter":{"name":"asset_id","in":"path","required":true,"description":"The unique identifier (UUID) of the Asset.","schema":{"type":"string","format":"uuid"}}},"schemas":{"Asset":{"type":"object","description":"Represents a digital asset managed by the Core API.","properties":{"asset_id":{"type":"string","format":"uuid","description":"Unique identifier for the Asset, generated during upload initiation.","readOnly":true},"organization_id":{"type":"string","description":"ID of the Organisation (from external IdP) that owns this Asset. Server-set.","readOnly":true},"created_by":{"type":"string","description":"User ID of the creator (from external IdP), or `api_key:<id>` when created via an API key. Server-set.","readOnly":true},"name":{"type":"string","description":"The original file name of the Asset. NOT NULL."},"category":{"type":"string","description":"Primary category of the Asset (e.g., 'video', 'image', 'weight'). NOT NULL. List of values managed in code."},"content_type":{"type":"string","description":"The MIME type of the asset. NOT NULL."},"size_bytes":{"type":"integer","format":"int64","description":"The size of the asset in bytes. NOT NULL."},"etag":{"type":"string","description":"The ETag of the S3 object, used for integrity checking. NOT NULL."},"created_at":{"type":"string","format":"date-time","description":"Timestamp of when this Asset record was created (finalized). Server-generated. Defaults to CURRENT_TIMESTAMP.","readOnly":true},"updated_at":{"type":"string","format":"date-time","description":"Timestamp of the last update to this Asset record. Server-generated. Auto-updates on modification.","readOnly":true},"asset_url":{"type":"string","format":"uri","readOnly":true,"description":"A temporary, pre-signed URL to download the asset's content. This URL will expire."}},"required":["asset_id","organization_id","created_by","name","category","content_type","size_bytes","etag","created_at","updated_at"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"ForbiddenError":{"description":"Authenticated principal does not have permission.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"NotFoundError":{"description":"The requested resource was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/assets/{asset_id}":{"get":{"tags":["Assets"],"summary":"Retrieve Asset Metadata","description":"Retrieves metadata for a specific Asset, including a temporary pre-signed `asset_url` for download. The user can access an asset if it belongs to their organization or to the shared template organization.","operationId":"getAssetById","parameters":[{"$ref":"#/components/parameters/AssetIdPathParameter"}],"responses":{"200":{"description":"Successfully retrieved Asset metadata.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Asset"}}}},"401":{"$ref":"#/components/responses/UnauthorizedError"},"403":{"$ref":"#/components/responses/ForbiddenError"},"404":{"$ref":"#/components/responses/NotFoundError"}}}}}}
```

## Delete an Asset

> Permanently deletes an Asset's metadata from the DB and its corresponding object from S3 (hard delete). This operation is restricted to assets owned by the user's organization and cannot be used on shared template assets.

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Assets","description":"Operations related to managing digital assets (images, videos, etc.)."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"parameters":{"AssetIdPathParameter":{"name":"asset_id","in":"path","required":true,"description":"The unique identifier (UUID) of the Asset.","schema":{"type":"string","format":"uuid"}}},"responses":{"NoContentSuccess":{"description":"Operation successful, no content to return."},"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"ForbiddenError":{"description":"Authenticated principal does not have permission.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"NotFoundError":{"description":"The requested resource was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"schemas":{"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}}},"paths":{"/assets/{asset_id}":{"delete":{"tags":["Assets"],"summary":"Delete an Asset","description":"Permanently deletes an Asset's metadata from the DB and its corresponding object from S3 (hard delete). This operation is restricted to assets owned by the user's organization and cannot be used on shared template assets.","operationId":"deleteAsset","parameters":[{"$ref":"#/components/parameters/AssetIdPathParameter"}],"responses":{"204":{"$ref":"#/components/responses/NoContentSuccess"},"401":{"$ref":"#/components/responses/UnauthorizedError"},"403":{"$ref":"#/components/responses/ForbiddenError"},"404":{"$ref":"#/components/responses/NotFoundError"}}}}}}
```

{% hint style="warning" %}
The idle video generator endpoint still references the deprecated `ojin/oris-1.0` model name. The underlying service uses the current Human Portrait model. This endpoint path will be updated in a future release.
{% endhint %}

## Generate idle video from image asset

> Triggers background generation of an idle video from a source image asset\
> using the ojin/oris-1.0 idle video generator.\
> \
> The job runs asynchronously and returns a \`job\_id\` for status tracking.\
> \
> On completion, the generated video is saved as a new Asset in the organization.\
> The \`result.asset\_id\` field in the job object will contain the new asset ID.

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Assets","description":"Operations related to managing digital assets (images, videos, etc.)."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"schemas":{"IdleVideoGenerationRequest":{"type":"object","description":"Request payload to trigger idle video generation.","properties":{"source_asset_id":{"type":"string","format":"uuid","description":"The ID of the source image asset to use for generating the idle video."},"reference_template":{"type":"string","description":"The reference motion template to use (e.g., 'v1', 'v2', 'v3').","enum":["v1","v2","v3"]},"model_variant_id":{"type":"string","maxLength":128,"description":"Model variant the generated idle video is intended for (e.g. 'ojin/oris-portrait'). Used only to label the background job so the Recent Generations list names the right model. Optional; callers without a model context omit it and the job uses a default label."},"target_model_config_id":{"type":"string","format":"uuid","description":"Model config to assign the generated video to as its active idle preview once the job completes. When set, core-api writes model_configurations.preview server-side on completion, so the assignment lands even if the browser closed, navigated away, or refreshed mid-generation. Must be a config owned by the caller's organization. Optional; omit to only create the video without assigning it."}},"required":["source_asset_id"]},"IdleVideoGenerationResponse":{"type":"object","description":"Response from triggering idle video generation.","properties":{"job_id":{"type":"string","format":"uuid","description":"Identifier of the background job created for this generation request."}},"required":["job_id"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"BadRequestError":{"description":"Invalid request payload or parameters.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"ForbiddenError":{"description":"Authenticated principal does not have permission.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/assets/generate/ojin/oris-1.0-idle-video-generator":{"post":{"tags":["Assets"],"summary":"Generate idle video from image asset","description":"Triggers background generation of an idle video from a source image asset\nusing the ojin/oris-1.0 idle video generator.\n\nThe job runs asynchronously and returns a `job_id` for status tracking.\n\nOn completion, the generated video is saved as a new Asset in the organization.\nThe `result.asset_id` field in the job object will contain the new asset ID.","operationId":"generateIdleVideo","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/IdleVideoGenerationRequest"}}}},"responses":{"202":{"description":"Job accepted and queued for processing.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/IdleVideoGenerationResponse"}}}},"400":{"$ref":"#/components/responses/BadRequestError"},"401":{"$ref":"#/components/responses/UnauthorizedError"},"403":{"$ref":"#/components/responses/ForbiddenError"},"404":{"description":"Source asset not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## Agents

Use the agent endpoints to create and manage Human Agents: their configuration, publication status, third-party voice providers, and call history. These manage the persistent agent definition; to start a live session with a published agent, see the [Session API Reference](/apps/overview/api-reference).

## GET /agents

> List Agents (org-scoped)

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Agents","description":"Operations related to Agents (Agent Service v1) — configuration, providers, and call history."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"parameters":{"LimitQueryParameter":{"name":"limit","in":"query","required":false,"description":"Number of items to return per page.","schema":{"type":"integer","default":20,"minimum":1,"maximum":100}},"OffsetQueryParameter":{"name":"offset","in":"query","required":false,"description":"Number of items to skip for pagination.","schema":{"type":"integer","default":0,"minimum":0}}},"schemas":{"AgentBase":{"type":"object","description":"Basic representation of an Agent for list views.","properties":{"agent_id":{"type":"string","format":"uuid","readOnly":true},"organization_id":{"type":"string","format":"uuid","readOnly":true},"created_by":{"type":"string","readOnly":true,"description":"Creator's user ID (from external IdP), or `api_key:<id>` when the resource was created via an API key."},"title":{"type":"string","maxLength":255},"description":{"type":"string","maxLength":1000,"nullable":true},"mode":{"$ref":"#/components/schemas/AgentMode"},"status":{"$ref":"#/components/schemas/AgentStatus"},"face_id":{"type":"string","format":"uuid","nullable":true},"created_at":{"type":"string","format":"date-time","readOnly":true},"updated_at":{"type":"string","format":"date-time","readOnly":true}},"required":["agent_id","organization_id","created_by","title","mode","status","face_id","created_at","updated_at"]},"AgentMode":{"type":"string","enum":["ojin","third_party"],"description":"The operating mode of an agent. Ojin mode uses the built-in pipeline; third_party mode delegates to an external STS provider."},"AgentStatus":{"type":"string","enum":["published","unpublished"],"description":"The publication status of an agent. Published agents are available for connections; unpublished agents are not."},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/agents":{"get":{"tags":["Agents"],"summary":"List Agents (org-scoped)","operationId":"listAgents","parameters":[{"$ref":"#/components/parameters/LimitQueryParameter"},{"$ref":"#/components/parameters/OffsetQueryParameter"}],"responses":{"200":{"description":"Paginated list of Agents.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/AgentBase"}},"pagination":{"type":"object","properties":{"limit":{"type":"integer"},"offset":{"type":"integer"},"total_items":{"type":"integer"}},"required":["limit","offset","total_items"]}},"required":["data","pagination"]}}}},"401":{"$ref":"#/components/responses/UnauthorizedError"}}}}}}
```

## Create a new Agent

> Creates an Agent, optionally seeded from a preset. On creation the response includes \`auth\_secret\` (one-shot) when \`auth\_enabled\` is true.

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Agents","description":"Operations related to Agents (Agent Service v1) — configuration, providers, and call history."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"schemas":{"CreateAgentRequest":{"type":"object","description":"Payload for creating a new Agent, optionally from a preset.","properties":{"title":{"type":"string","maxLength":255},"mode":{"$ref":"#/components/schemas/AgentMode"},"preset_id":{"type":"string","format":"uuid","description":"Optional preset to seed the new agent from."}},"required":["title"]},"AgentMode":{"type":"string","enum":["ojin","third_party"],"description":"The operating mode of an agent. Ojin mode uses the built-in pipeline; third_party mode delegates to an external STS provider."},"AgentDetail":{"allOf":[{"$ref":"#/components/schemas/AgentBase"},{"type":"object","description":"Full Agent detail including configuration, STS credentials flags, LLM tool wiring.","properties":{"language":{"$ref":"#/components/schemas/AgentLanguage"},"system_prompt":{"type":"string","maxLength":10000,"nullable":true},"tts_provider":{"type":"string"},"voice_id":{"type":"string","maxLength":255,"nullable":true},"behaviour":{"allOf":[{"$ref":"#/components/schemas/AgentBehaviour"}],"nullable":true},"advanced":{"allOf":[{"$ref":"#/components/schemas/AgentAdvanced"}],"nullable":true},"sts_provider":{"type":"string","maxLength":100,"nullable":true},"sts_config_id":{"type":"string","maxLength":255,"nullable":true},"sts_api_key_set":{"type":"boolean","description":"True when an encrypted STS API key is persisted for this agent. The raw key is never returned."},"provider_config":{"type":"object","additionalProperties":true,"nullable":true},"preview_url":{"type":"string","maxLength":2048,"nullable":true,"description":"A direct URL or a bare asset-ID UUID. The public agent endpoint resolves UUIDs to signed S3 URLs before returning them to clients."},"starts_conversation":{"type":"boolean"},"session_limit_seconds":{"type":"integer","minimum":1,"maximum":86400},"max_concurrency":{"oneOf":[{"type":"integer","enum":[-1]},{"type":"integer","minimum":1,"maximum":100}],"description":"Maximum concurrent sessions. -1 means unbounded (no limit); valid positive values are 1–100."},"auth_enabled":{"type":"boolean"},"auth_secret_set":{"type":"boolean","description":"True when an auth secret is persisted."},"auth_secret":{"type":"string","nullable":true,"description":"Plaintext auth secret. Only returned to the creator immediately after\nagent creation (one-shot). Subsequent reads return null; use auth_secret_set\nto detect whether a secret is configured."},"allowed_hostnames":{"type":"array","nullable":true,"items":{"type":"string","maxLength":255}},"tools":{"type":"array","description":"Per-tool function-calling definitions with delivery + enabled flag.","items":{"$ref":"#/components/schemas/AgentTool"}}},"required":["language","tts_provider","sts_api_key_set","starts_conversation","session_limit_seconds","max_concurrency","auth_enabled","auth_secret_set","tools"]}]},"AgentBase":{"type":"object","description":"Basic representation of an Agent for list views.","properties":{"agent_id":{"type":"string","format":"uuid","readOnly":true},"organization_id":{"type":"string","format":"uuid","readOnly":true},"created_by":{"type":"string","readOnly":true,"description":"Creator's user ID (from external IdP), or `api_key:<id>` when the resource was created via an API key."},"title":{"type":"string","maxLength":255},"description":{"type":"string","maxLength":1000,"nullable":true},"mode":{"$ref":"#/components/schemas/AgentMode"},"status":{"$ref":"#/components/schemas/AgentStatus"},"face_id":{"type":"string","format":"uuid","nullable":true},"created_at":{"type":"string","format":"date-time","readOnly":true},"updated_at":{"type":"string","format":"date-time","readOnly":true}},"required":["agent_id","organization_id","created_by","title","mode","status","face_id","created_at","updated_at"]},"AgentStatus":{"type":"string","enum":["published","unpublished"],"description":"The publication status of an agent. Published agents are available for connections; unpublished agents are not."},"AgentLanguage":{"type":"string","enum":["en","de","fr","es","ar","ja"],"description":"Spoken language code for the agent. Drives Deepgram STT language,\nElevenLabs voice filtering in the dashboard, and an LLM\nsystem-prompt suffix that pins the response language.\n"},"AgentBehaviour":{"type":"object","description":"Conversational behaviour knobs applied to an Agent.","properties":{"greeting":{"type":"string","maxLength":2000,"nullable":true},"greeting_reference":{"type":"string","maxLength":2000,"nullable":true},"greeting_mode":{"type":"string","enum":["verbatim","composed"],"nullable":true},"nudge_message":{"type":"string","maxLength":2000,"nullable":true},"nudge_reference":{"type":"string","maxLength":2000,"nullable":true},"nudge_mode":{"type":"string","enum":["verbatim","composed"],"nullable":true},"farewell_message":{"type":"string","maxLength":2000,"nullable":true},"farewell_reference":{"type":"string","maxLength":2000,"nullable":true},"farewell_mode":{"type":"string","enum":["verbatim","composed"],"nullable":true},"max_conversation_duration_seconds":{"type":"integer","minimum":1,"maximum":86400,"nullable":true},"inactivity_nudge_seconds":{"type":"integer","minimum":1,"maximum":3600,"nullable":true},"allow_interruption":{"type":"boolean","nullable":true}}},"AgentAdvanced":{"type":"object","description":"Advanced configuration for an Agent (video pipeline + LLM tuning).","properties":{"max_video_source_dimension":{"type":"integer","minimum":1,"nullable":true},"llm_max_tokens":{"type":"integer","minimum":64,"maximum":4096,"nullable":true,"description":"Maximum completion tokens the managed (Ojin-mode) LLM may generate per spoken reply. Raise it if answers get cut off mid-sentence; lower it to keep replies short. Defaults to 384 when unset."}}},"AgentTool":{"type":"object","additionalProperties":false,"description":"A function-calling tool exposed by the agent to the LLM, with per-tool delivery and enabled flag.","properties":{"tool_id":{"type":"string","format":"uuid","readOnly":true},"enabled":{"type":"boolean","default":true,"description":"When false, the tool is hidden from the LLM but its delivery config is preserved."},"type":{"type":"string","enum":["function"],"default":"function"},"function":{"$ref":"#/components/schemas/ToolFunction"},"delivery":{"$ref":"#/components/schemas/ToolDelivery"}},"required":["tool_id","enabled","type","function","delivery"]},"ToolFunction":{"type":"object","additionalProperties":false,"description":"OpenAI / Anthropic tool function definition.","properties":{"name":{"type":"string","maxLength":64,"pattern":"^[a-zA-Z0-9_-]+$","description":"Function name. Must match the LLM tool-name regex."},"description":{"type":"string","maxLength":1024,"nullable":true},"parameters":{"type":"object","additionalProperties":true,"nullable":true,"description":"JSON Schema for the function's parameters (opaque pass-through)."}},"required":["name"]},"ToolDelivery":{"oneOf":[{"$ref":"#/components/schemas/ClientToolDelivery"},{"$ref":"#/components/schemas/WebhookToolDelivery"}],"discriminator":{"propertyName":"mode","mapping":{"client":"#/components/schemas/ClientToolDelivery","webhook":"#/components/schemas/WebhookToolDelivery"}}},"ClientToolDelivery":{"type":"object","additionalProperties":false,"description":"Tool calls are delivered to the in-browser widget as an `ojinToolCall` CustomEvent.","properties":{"mode":{"type":"string","enum":["client"]}},"required":["mode"]},"WebhookToolDelivery":{"type":"object","additionalProperties":false,"description":"Tool calls are POSTed to an external webhook URL.","properties":{"mode":{"type":"string","enum":["webhook"]},"url":{"type":"string","format":"uri","maxLength":2048},"wait_for_response":{"type":"boolean","default":false,"description":"When true, the LLM waits for the webhook's response and incorporates it\ninto the conversation. When false, the webhook is fired-and-forgotten and\nthe LLM receives a neutral acknowledgement immediately."}},"required":["mode","url"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"BadRequestError":{"description":"Invalid request payload or parameters.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/agents":{"post":{"tags":["Agents"],"summary":"Create a new Agent","description":"Creates an Agent, optionally seeded from a preset. On creation the response includes `auth_secret` (one-shot) when `auth_enabled` is true.","operationId":"createAgent","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateAgentRequest"}}}},"responses":{"201":{"description":"Agent created.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AgentDetail"}}}},"400":{"$ref":"#/components/responses/BadRequestError"},"401":{"$ref":"#/components/responses/UnauthorizedError"}}}}}}
```

## GET /agents/{agent\_id}

> Retrieve an Agent

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Agents","description":"Operations related to Agents (Agent Service v1) — configuration, providers, and call history."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"parameters":{"AgentIdPathParameter":{"name":"agent_id","in":"path","required":true,"description":"The unique identifier (UUID) of the Agent.","schema":{"type":"string","format":"uuid"}}},"schemas":{"AgentDetail":{"allOf":[{"$ref":"#/components/schemas/AgentBase"},{"type":"object","description":"Full Agent detail including configuration, STS credentials flags, LLM tool wiring.","properties":{"language":{"$ref":"#/components/schemas/AgentLanguage"},"system_prompt":{"type":"string","maxLength":10000,"nullable":true},"tts_provider":{"type":"string"},"voice_id":{"type":"string","maxLength":255,"nullable":true},"behaviour":{"allOf":[{"$ref":"#/components/schemas/AgentBehaviour"}],"nullable":true},"advanced":{"allOf":[{"$ref":"#/components/schemas/AgentAdvanced"}],"nullable":true},"sts_provider":{"type":"string","maxLength":100,"nullable":true},"sts_config_id":{"type":"string","maxLength":255,"nullable":true},"sts_api_key_set":{"type":"boolean","description":"True when an encrypted STS API key is persisted for this agent. The raw key is never returned."},"provider_config":{"type":"object","additionalProperties":true,"nullable":true},"preview_url":{"type":"string","maxLength":2048,"nullable":true,"description":"A direct URL or a bare asset-ID UUID. The public agent endpoint resolves UUIDs to signed S3 URLs before returning them to clients."},"starts_conversation":{"type":"boolean"},"session_limit_seconds":{"type":"integer","minimum":1,"maximum":86400},"max_concurrency":{"oneOf":[{"type":"integer","enum":[-1]},{"type":"integer","minimum":1,"maximum":100}],"description":"Maximum concurrent sessions. -1 means unbounded (no limit); valid positive values are 1–100."},"auth_enabled":{"type":"boolean"},"auth_secret_set":{"type":"boolean","description":"True when an auth secret is persisted."},"auth_secret":{"type":"string","nullable":true,"description":"Plaintext auth secret. Only returned to the creator immediately after\nagent creation (one-shot). Subsequent reads return null; use auth_secret_set\nto detect whether a secret is configured."},"allowed_hostnames":{"type":"array","nullable":true,"items":{"type":"string","maxLength":255}},"tools":{"type":"array","description":"Per-tool function-calling definitions with delivery + enabled flag.","items":{"$ref":"#/components/schemas/AgentTool"}}},"required":["language","tts_provider","sts_api_key_set","starts_conversation","session_limit_seconds","max_concurrency","auth_enabled","auth_secret_set","tools"]}]},"AgentBase":{"type":"object","description":"Basic representation of an Agent for list views.","properties":{"agent_id":{"type":"string","format":"uuid","readOnly":true},"organization_id":{"type":"string","format":"uuid","readOnly":true},"created_by":{"type":"string","readOnly":true,"description":"Creator's user ID (from external IdP), or `api_key:<id>` when the resource was created via an API key."},"title":{"type":"string","maxLength":255},"description":{"type":"string","maxLength":1000,"nullable":true},"mode":{"$ref":"#/components/schemas/AgentMode"},"status":{"$ref":"#/components/schemas/AgentStatus"},"face_id":{"type":"string","format":"uuid","nullable":true},"created_at":{"type":"string","format":"date-time","readOnly":true},"updated_at":{"type":"string","format":"date-time","readOnly":true}},"required":["agent_id","organization_id","created_by","title","mode","status","face_id","created_at","updated_at"]},"AgentMode":{"type":"string","enum":["ojin","third_party"],"description":"The operating mode of an agent. Ojin mode uses the built-in pipeline; third_party mode delegates to an external STS provider."},"AgentStatus":{"type":"string","enum":["published","unpublished"],"description":"The publication status of an agent. Published agents are available for connections; unpublished agents are not."},"AgentLanguage":{"type":"string","enum":["en","de","fr","es","ar","ja"],"description":"Spoken language code for the agent. Drives Deepgram STT language,\nElevenLabs voice filtering in the dashboard, and an LLM\nsystem-prompt suffix that pins the response language.\n"},"AgentBehaviour":{"type":"object","description":"Conversational behaviour knobs applied to an Agent.","properties":{"greeting":{"type":"string","maxLength":2000,"nullable":true},"greeting_reference":{"type":"string","maxLength":2000,"nullable":true},"greeting_mode":{"type":"string","enum":["verbatim","composed"],"nullable":true},"nudge_message":{"type":"string","maxLength":2000,"nullable":true},"nudge_reference":{"type":"string","maxLength":2000,"nullable":true},"nudge_mode":{"type":"string","enum":["verbatim","composed"],"nullable":true},"farewell_message":{"type":"string","maxLength":2000,"nullable":true},"farewell_reference":{"type":"string","maxLength":2000,"nullable":true},"farewell_mode":{"type":"string","enum":["verbatim","composed"],"nullable":true},"max_conversation_duration_seconds":{"type":"integer","minimum":1,"maximum":86400,"nullable":true},"inactivity_nudge_seconds":{"type":"integer","minimum":1,"maximum":3600,"nullable":true},"allow_interruption":{"type":"boolean","nullable":true}}},"AgentAdvanced":{"type":"object","description":"Advanced configuration for an Agent (video pipeline + LLM tuning).","properties":{"max_video_source_dimension":{"type":"integer","minimum":1,"nullable":true},"llm_max_tokens":{"type":"integer","minimum":64,"maximum":4096,"nullable":true,"description":"Maximum completion tokens the managed (Ojin-mode) LLM may generate per spoken reply. Raise it if answers get cut off mid-sentence; lower it to keep replies short. Defaults to 384 when unset."}}},"AgentTool":{"type":"object","additionalProperties":false,"description":"A function-calling tool exposed by the agent to the LLM, with per-tool delivery and enabled flag.","properties":{"tool_id":{"type":"string","format":"uuid","readOnly":true},"enabled":{"type":"boolean","default":true,"description":"When false, the tool is hidden from the LLM but its delivery config is preserved."},"type":{"type":"string","enum":["function"],"default":"function"},"function":{"$ref":"#/components/schemas/ToolFunction"},"delivery":{"$ref":"#/components/schemas/ToolDelivery"}},"required":["tool_id","enabled","type","function","delivery"]},"ToolFunction":{"type":"object","additionalProperties":false,"description":"OpenAI / Anthropic tool function definition.","properties":{"name":{"type":"string","maxLength":64,"pattern":"^[a-zA-Z0-9_-]+$","description":"Function name. Must match the LLM tool-name regex."},"description":{"type":"string","maxLength":1024,"nullable":true},"parameters":{"type":"object","additionalProperties":true,"nullable":true,"description":"JSON Schema for the function's parameters (opaque pass-through)."}},"required":["name"]},"ToolDelivery":{"oneOf":[{"$ref":"#/components/schemas/ClientToolDelivery"},{"$ref":"#/components/schemas/WebhookToolDelivery"}],"discriminator":{"propertyName":"mode","mapping":{"client":"#/components/schemas/ClientToolDelivery","webhook":"#/components/schemas/WebhookToolDelivery"}}},"ClientToolDelivery":{"type":"object","additionalProperties":false,"description":"Tool calls are delivered to the in-browser widget as an `ojinToolCall` CustomEvent.","properties":{"mode":{"type":"string","enum":["client"]}},"required":["mode"]},"WebhookToolDelivery":{"type":"object","additionalProperties":false,"description":"Tool calls are POSTed to an external webhook URL.","properties":{"mode":{"type":"string","enum":["webhook"]},"url":{"type":"string","format":"uri","maxLength":2048},"wait_for_response":{"type":"boolean","default":false,"description":"When true, the LLM waits for the webhook's response and incorporates it\ninto the conversation. When false, the webhook is fired-and-forgotten and\nthe LLM receives a neutral acknowledgement immediately."}},"required":["mode","url"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"NotFoundError":{"description":"The requested resource was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/agents/{agent_id}":{"get":{"tags":["Agents"],"summary":"Retrieve an Agent","operationId":"getAgent","parameters":[{"$ref":"#/components/parameters/AgentIdPathParameter"}],"responses":{"200":{"description":"Agent detail.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AgentDetail"}}}},"401":{"$ref":"#/components/responses/UnauthorizedError"},"404":{"$ref":"#/components/responses/NotFoundError"}}}}}}
```

## PATCH /agents/{agent\_id}

> Update an Agent (partial)

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Agents","description":"Operations related to Agents (Agent Service v1) — configuration, providers, and call history."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"parameters":{"AgentIdPathParameter":{"name":"agent_id","in":"path","required":true,"description":"The unique identifier (UUID) of the Agent.","schema":{"type":"string","format":"uuid"}}},"schemas":{"UpdateAgentRequest":{"type":"object","description":"Payload for updating an Agent (partial update — all fields optional).","properties":{"title":{"type":"string","maxLength":255},"description":{"type":"string","maxLength":1000,"nullable":true},"mode":{"$ref":"#/components/schemas/AgentMode"},"face_id":{"type":"string","format":"uuid","nullable":true},"language":{"$ref":"#/components/schemas/AgentLanguage"},"system_prompt":{"type":"string","maxLength":10000,"nullable":true},"tts_provider":{"type":"string","enum":["elevenlabs","ojin"]},"voice_id":{"type":"string","maxLength":255,"nullable":true},"behaviour":{"$ref":"#/components/schemas/AgentBehaviour"},"advanced":{"$ref":"#/components/schemas/AgentAdvanced"},"sts_provider":{"type":"string","maxLength":100,"nullable":true},"sts_api_key":{"type":"string","maxLength":1000,"nullable":true,"writeOnly":true},"sts_config_id":{"type":"string","maxLength":255,"nullable":true},"provider_config":{"type":"object","additionalProperties":true,"nullable":true},"preview_url":{"type":"string","maxLength":2048,"nullable":true,"description":"A direct URL or a bare asset-ID UUID. The public agent endpoint resolves UUIDs to signed S3 URLs before returning them to clients."},"session_limit_seconds":{"type":"integer","minimum":1,"maximum":86400},"max_concurrency":{"oneOf":[{"type":"integer","enum":[-1]},{"type":"integer","minimum":1,"maximum":100}],"description":"Maximum concurrent sessions. -1 means unbounded (no limit); valid positive values are 1–100."},"starts_conversation":{"type":"boolean"},"auth_enabled":{"type":"boolean"},"allowed_hostnames":{"type":"array","items":{"type":"string","maxLength":255}},"tools":{"type":"array","description":"Replace the agent's tools with this array (full-replace semantics).\nOmit to leave tools unchanged. UPSERTs by `function.name`; tools not\npresent in the array are deleted from the agent.","items":{"$ref":"#/components/schemas/AgentToolInput"}}}},"AgentMode":{"type":"string","enum":["ojin","third_party"],"description":"The operating mode of an agent. Ojin mode uses the built-in pipeline; third_party mode delegates to an external STS provider."},"AgentLanguage":{"type":"string","enum":["en","de","fr","es","ar","ja"],"description":"Spoken language code for the agent. Drives Deepgram STT language,\nElevenLabs voice filtering in the dashboard, and an LLM\nsystem-prompt suffix that pins the response language.\n"},"AgentBehaviour":{"type":"object","description":"Conversational behaviour knobs applied to an Agent.","properties":{"greeting":{"type":"string","maxLength":2000,"nullable":true},"greeting_reference":{"type":"string","maxLength":2000,"nullable":true},"greeting_mode":{"type":"string","enum":["verbatim","composed"],"nullable":true},"nudge_message":{"type":"string","maxLength":2000,"nullable":true},"nudge_reference":{"type":"string","maxLength":2000,"nullable":true},"nudge_mode":{"type":"string","enum":["verbatim","composed"],"nullable":true},"farewell_message":{"type":"string","maxLength":2000,"nullable":true},"farewell_reference":{"type":"string","maxLength":2000,"nullable":true},"farewell_mode":{"type":"string","enum":["verbatim","composed"],"nullable":true},"max_conversation_duration_seconds":{"type":"integer","minimum":1,"maximum":86400,"nullable":true},"inactivity_nudge_seconds":{"type":"integer","minimum":1,"maximum":3600,"nullable":true},"allow_interruption":{"type":"boolean","nullable":true}}},"AgentAdvanced":{"type":"object","description":"Advanced configuration for an Agent (video pipeline + LLM tuning).","properties":{"max_video_source_dimension":{"type":"integer","minimum":1,"nullable":true},"llm_max_tokens":{"type":"integer","minimum":64,"maximum":4096,"nullable":true,"description":"Maximum completion tokens the managed (Ojin-mode) LLM may generate per spoken reply. Raise it if answers get cut off mid-sentence; lower it to keep replies short. Defaults to 384 when unset."}}},"AgentToolInput":{"type":"object","additionalProperties":false,"description":"Input shape for an agent tool. `tool_id` is optional — when present and\nmatched (by `function.name`) the existing row is updated in place; when\nabsent or unmatched a new tool is created. `enabled` defaults to true\nand `type` defaults to \"function\" server-side when omitted.","properties":{"tool_id":{"type":"string","format":"uuid"},"enabled":{"type":"boolean"},"type":{"type":"string","enum":["function"]},"function":{"$ref":"#/components/schemas/ToolFunction"},"delivery":{"$ref":"#/components/schemas/ToolDelivery"}},"required":["function","delivery"]},"ToolFunction":{"type":"object","additionalProperties":false,"description":"OpenAI / Anthropic tool function definition.","properties":{"name":{"type":"string","maxLength":64,"pattern":"^[a-zA-Z0-9_-]+$","description":"Function name. Must match the LLM tool-name regex."},"description":{"type":"string","maxLength":1024,"nullable":true},"parameters":{"type":"object","additionalProperties":true,"nullable":true,"description":"JSON Schema for the function's parameters (opaque pass-through)."}},"required":["name"]},"ToolDelivery":{"oneOf":[{"$ref":"#/components/schemas/ClientToolDelivery"},{"$ref":"#/components/schemas/WebhookToolDelivery"}],"discriminator":{"propertyName":"mode","mapping":{"client":"#/components/schemas/ClientToolDelivery","webhook":"#/components/schemas/WebhookToolDelivery"}}},"ClientToolDelivery":{"type":"object","additionalProperties":false,"description":"Tool calls are delivered to the in-browser widget as an `ojinToolCall` CustomEvent.","properties":{"mode":{"type":"string","enum":["client"]}},"required":["mode"]},"WebhookToolDelivery":{"type":"object","additionalProperties":false,"description":"Tool calls are POSTed to an external webhook URL.","properties":{"mode":{"type":"string","enum":["webhook"]},"url":{"type":"string","format":"uri","maxLength":2048},"wait_for_response":{"type":"boolean","default":false,"description":"When true, the LLM waits for the webhook's response and incorporates it\ninto the conversation. When false, the webhook is fired-and-forgotten and\nthe LLM receives a neutral acknowledgement immediately."}},"required":["mode","url"]},"AgentDetail":{"allOf":[{"$ref":"#/components/schemas/AgentBase"},{"type":"object","description":"Full Agent detail including configuration, STS credentials flags, LLM tool wiring.","properties":{"language":{"$ref":"#/components/schemas/AgentLanguage"},"system_prompt":{"type":"string","maxLength":10000,"nullable":true},"tts_provider":{"type":"string"},"voice_id":{"type":"string","maxLength":255,"nullable":true},"behaviour":{"allOf":[{"$ref":"#/components/schemas/AgentBehaviour"}],"nullable":true},"advanced":{"allOf":[{"$ref":"#/components/schemas/AgentAdvanced"}],"nullable":true},"sts_provider":{"type":"string","maxLength":100,"nullable":true},"sts_config_id":{"type":"string","maxLength":255,"nullable":true},"sts_api_key_set":{"type":"boolean","description":"True when an encrypted STS API key is persisted for this agent. The raw key is never returned."},"provider_config":{"type":"object","additionalProperties":true,"nullable":true},"preview_url":{"type":"string","maxLength":2048,"nullable":true,"description":"A direct URL or a bare asset-ID UUID. The public agent endpoint resolves UUIDs to signed S3 URLs before returning them to clients."},"starts_conversation":{"type":"boolean"},"session_limit_seconds":{"type":"integer","minimum":1,"maximum":86400},"max_concurrency":{"oneOf":[{"type":"integer","enum":[-1]},{"type":"integer","minimum":1,"maximum":100}],"description":"Maximum concurrent sessions. -1 means unbounded (no limit); valid positive values are 1–100."},"auth_enabled":{"type":"boolean"},"auth_secret_set":{"type":"boolean","description":"True when an auth secret is persisted."},"auth_secret":{"type":"string","nullable":true,"description":"Plaintext auth secret. Only returned to the creator immediately after\nagent creation (one-shot). Subsequent reads return null; use auth_secret_set\nto detect whether a secret is configured."},"allowed_hostnames":{"type":"array","nullable":true,"items":{"type":"string","maxLength":255}},"tools":{"type":"array","description":"Per-tool function-calling definitions with delivery + enabled flag.","items":{"$ref":"#/components/schemas/AgentTool"}}},"required":["language","tts_provider","sts_api_key_set","starts_conversation","session_limit_seconds","max_concurrency","auth_enabled","auth_secret_set","tools"]}]},"AgentBase":{"type":"object","description":"Basic representation of an Agent for list views.","properties":{"agent_id":{"type":"string","format":"uuid","readOnly":true},"organization_id":{"type":"string","format":"uuid","readOnly":true},"created_by":{"type":"string","readOnly":true,"description":"Creator's user ID (from external IdP), or `api_key:<id>` when the resource was created via an API key."},"title":{"type":"string","maxLength":255},"description":{"type":"string","maxLength":1000,"nullable":true},"mode":{"$ref":"#/components/schemas/AgentMode"},"status":{"$ref":"#/components/schemas/AgentStatus"},"face_id":{"type":"string","format":"uuid","nullable":true},"created_at":{"type":"string","format":"date-time","readOnly":true},"updated_at":{"type":"string","format":"date-time","readOnly":true}},"required":["agent_id","organization_id","created_by","title","mode","status","face_id","created_at","updated_at"]},"AgentStatus":{"type":"string","enum":["published","unpublished"],"description":"The publication status of an agent. Published agents are available for connections; unpublished agents are not."},"AgentTool":{"type":"object","additionalProperties":false,"description":"A function-calling tool exposed by the agent to the LLM, with per-tool delivery and enabled flag.","properties":{"tool_id":{"type":"string","format":"uuid","readOnly":true},"enabled":{"type":"boolean","default":true,"description":"When false, the tool is hidden from the LLM but its delivery config is preserved."},"type":{"type":"string","enum":["function"],"default":"function"},"function":{"$ref":"#/components/schemas/ToolFunction"},"delivery":{"$ref":"#/components/schemas/ToolDelivery"}},"required":["tool_id","enabled","type","function","delivery"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"BadRequestError":{"description":"Invalid request payload or parameters.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"NotFoundError":{"description":"The requested resource was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/agents/{agent_id}":{"patch":{"tags":["Agents"],"summary":"Update an Agent (partial)","operationId":"updateAgent","parameters":[{"$ref":"#/components/parameters/AgentIdPathParameter"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateAgentRequest"}}}},"responses":{"200":{"description":"Agent updated.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AgentDetail"}}}},"400":{"$ref":"#/components/responses/BadRequestError"},"401":{"$ref":"#/components/responses/UnauthorizedError"},"404":{"$ref":"#/components/responses/NotFoundError"}}}}}}
```

## Delete an Agent

> Deletes an Agent. Fails with 409 if there are active sessions for the agent.

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Agents","description":"Operations related to Agents (Agent Service v1) — configuration, providers, and call history."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"parameters":{"AgentIdPathParameter":{"name":"agent_id","in":"path","required":true,"description":"The unique identifier (UUID) of the Agent.","schema":{"type":"string","format":"uuid"}}},"responses":{"NoContentSuccess":{"description":"Operation successful, no content to return."},"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"NotFoundError":{"description":"The requested resource was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"ConflictError":{"description":"Conflict with the current state of the resource.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"schemas":{"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}}},"paths":{"/agents/{agent_id}":{"delete":{"tags":["Agents"],"summary":"Delete an Agent","description":"Deletes an Agent. Fails with 409 if there are active sessions for the agent.","operationId":"deleteAgent","parameters":[{"$ref":"#/components/parameters/AgentIdPathParameter"}],"responses":{"204":{"$ref":"#/components/responses/NoContentSuccess"},"401":{"$ref":"#/components/responses/UnauthorizedError"},"404":{"$ref":"#/components/responses/NotFoundError"},"409":{"$ref":"#/components/responses/ConflictError"}}}}}}
```

## PATCH /agents/{agent\_id}/status

> Publish or unpublish an Agent

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Agents","description":"Operations related to Agents (Agent Service v1) — configuration, providers, and call history."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"parameters":{"AgentIdPathParameter":{"name":"agent_id","in":"path","required":true,"description":"The unique identifier (UUID) of the Agent.","schema":{"type":"string","format":"uuid"}}},"schemas":{"UpdateAgentStatusRequest":{"type":"object","description":"Payload for toggling Agent publication status.","properties":{"status":{"$ref":"#/components/schemas/AgentStatus"}},"required":["status"]},"AgentStatus":{"type":"string","enum":["published","unpublished"],"description":"The publication status of an agent. Published agents are available for connections; unpublished agents are not."},"AgentDetail":{"allOf":[{"$ref":"#/components/schemas/AgentBase"},{"type":"object","description":"Full Agent detail including configuration, STS credentials flags, LLM tool wiring.","properties":{"language":{"$ref":"#/components/schemas/AgentLanguage"},"system_prompt":{"type":"string","maxLength":10000,"nullable":true},"tts_provider":{"type":"string"},"voice_id":{"type":"string","maxLength":255,"nullable":true},"behaviour":{"allOf":[{"$ref":"#/components/schemas/AgentBehaviour"}],"nullable":true},"advanced":{"allOf":[{"$ref":"#/components/schemas/AgentAdvanced"}],"nullable":true},"sts_provider":{"type":"string","maxLength":100,"nullable":true},"sts_config_id":{"type":"string","maxLength":255,"nullable":true},"sts_api_key_set":{"type":"boolean","description":"True when an encrypted STS API key is persisted for this agent. The raw key is never returned."},"provider_config":{"type":"object","additionalProperties":true,"nullable":true},"preview_url":{"type":"string","maxLength":2048,"nullable":true,"description":"A direct URL or a bare asset-ID UUID. The public agent endpoint resolves UUIDs to signed S3 URLs before returning them to clients."},"starts_conversation":{"type":"boolean"},"session_limit_seconds":{"type":"integer","minimum":1,"maximum":86400},"max_concurrency":{"oneOf":[{"type":"integer","enum":[-1]},{"type":"integer","minimum":1,"maximum":100}],"description":"Maximum concurrent sessions. -1 means unbounded (no limit); valid positive values are 1–100."},"auth_enabled":{"type":"boolean"},"auth_secret_set":{"type":"boolean","description":"True when an auth secret is persisted."},"auth_secret":{"type":"string","nullable":true,"description":"Plaintext auth secret. Only returned to the creator immediately after\nagent creation (one-shot). Subsequent reads return null; use auth_secret_set\nto detect whether a secret is configured."},"allowed_hostnames":{"type":"array","nullable":true,"items":{"type":"string","maxLength":255}},"tools":{"type":"array","description":"Per-tool function-calling definitions with delivery + enabled flag.","items":{"$ref":"#/components/schemas/AgentTool"}}},"required":["language","tts_provider","sts_api_key_set","starts_conversation","session_limit_seconds","max_concurrency","auth_enabled","auth_secret_set","tools"]}]},"AgentBase":{"type":"object","description":"Basic representation of an Agent for list views.","properties":{"agent_id":{"type":"string","format":"uuid","readOnly":true},"organization_id":{"type":"string","format":"uuid","readOnly":true},"created_by":{"type":"string","readOnly":true,"description":"Creator's user ID (from external IdP), or `api_key:<id>` when the resource was created via an API key."},"title":{"type":"string","maxLength":255},"description":{"type":"string","maxLength":1000,"nullable":true},"mode":{"$ref":"#/components/schemas/AgentMode"},"status":{"$ref":"#/components/schemas/AgentStatus"},"face_id":{"type":"string","format":"uuid","nullable":true},"created_at":{"type":"string","format":"date-time","readOnly":true},"updated_at":{"type":"string","format":"date-time","readOnly":true}},"required":["agent_id","organization_id","created_by","title","mode","status","face_id","created_at","updated_at"]},"AgentMode":{"type":"string","enum":["ojin","third_party"],"description":"The operating mode of an agent. Ojin mode uses the built-in pipeline; third_party mode delegates to an external STS provider."},"AgentLanguage":{"type":"string","enum":["en","de","fr","es","ar","ja"],"description":"Spoken language code for the agent. Drives Deepgram STT language,\nElevenLabs voice filtering in the dashboard, and an LLM\nsystem-prompt suffix that pins the response language.\n"},"AgentBehaviour":{"type":"object","description":"Conversational behaviour knobs applied to an Agent.","properties":{"greeting":{"type":"string","maxLength":2000,"nullable":true},"greeting_reference":{"type":"string","maxLength":2000,"nullable":true},"greeting_mode":{"type":"string","enum":["verbatim","composed"],"nullable":true},"nudge_message":{"type":"string","maxLength":2000,"nullable":true},"nudge_reference":{"type":"string","maxLength":2000,"nullable":true},"nudge_mode":{"type":"string","enum":["verbatim","composed"],"nullable":true},"farewell_message":{"type":"string","maxLength":2000,"nullable":true},"farewell_reference":{"type":"string","maxLength":2000,"nullable":true},"farewell_mode":{"type":"string","enum":["verbatim","composed"],"nullable":true},"max_conversation_duration_seconds":{"type":"integer","minimum":1,"maximum":86400,"nullable":true},"inactivity_nudge_seconds":{"type":"integer","minimum":1,"maximum":3600,"nullable":true},"allow_interruption":{"type":"boolean","nullable":true}}},"AgentAdvanced":{"type":"object","description":"Advanced configuration for an Agent (video pipeline + LLM tuning).","properties":{"max_video_source_dimension":{"type":"integer","minimum":1,"nullable":true},"llm_max_tokens":{"type":"integer","minimum":64,"maximum":4096,"nullable":true,"description":"Maximum completion tokens the managed (Ojin-mode) LLM may generate per spoken reply. Raise it if answers get cut off mid-sentence; lower it to keep replies short. Defaults to 384 when unset."}}},"AgentTool":{"type":"object","additionalProperties":false,"description":"A function-calling tool exposed by the agent to the LLM, with per-tool delivery and enabled flag.","properties":{"tool_id":{"type":"string","format":"uuid","readOnly":true},"enabled":{"type":"boolean","default":true,"description":"When false, the tool is hidden from the LLM but its delivery config is preserved."},"type":{"type":"string","enum":["function"],"default":"function"},"function":{"$ref":"#/components/schemas/ToolFunction"},"delivery":{"$ref":"#/components/schemas/ToolDelivery"}},"required":["tool_id","enabled","type","function","delivery"]},"ToolFunction":{"type":"object","additionalProperties":false,"description":"OpenAI / Anthropic tool function definition.","properties":{"name":{"type":"string","maxLength":64,"pattern":"^[a-zA-Z0-9_-]+$","description":"Function name. Must match the LLM tool-name regex."},"description":{"type":"string","maxLength":1024,"nullable":true},"parameters":{"type":"object","additionalProperties":true,"nullable":true,"description":"JSON Schema for the function's parameters (opaque pass-through)."}},"required":["name"]},"ToolDelivery":{"oneOf":[{"$ref":"#/components/schemas/ClientToolDelivery"},{"$ref":"#/components/schemas/WebhookToolDelivery"}],"discriminator":{"propertyName":"mode","mapping":{"client":"#/components/schemas/ClientToolDelivery","webhook":"#/components/schemas/WebhookToolDelivery"}}},"ClientToolDelivery":{"type":"object","additionalProperties":false,"description":"Tool calls are delivered to the in-browser widget as an `ojinToolCall` CustomEvent.","properties":{"mode":{"type":"string","enum":["client"]}},"required":["mode"]},"WebhookToolDelivery":{"type":"object","additionalProperties":false,"description":"Tool calls are POSTed to an external webhook URL.","properties":{"mode":{"type":"string","enum":["webhook"]},"url":{"type":"string","format":"uri","maxLength":2048},"wait_for_response":{"type":"boolean","default":false,"description":"When true, the LLM waits for the webhook's response and incorporates it\ninto the conversation. When false, the webhook is fired-and-forgotten and\nthe LLM receives a neutral acknowledgement immediately."}},"required":["mode","url"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"BadRequestError":{"description":"Invalid request payload or parameters.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"NotFoundError":{"description":"The requested resource was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/agents/{agent_id}/status":{"patch":{"tags":["Agents"],"summary":"Publish or unpublish an Agent","operationId":"updateAgentStatus","parameters":[{"$ref":"#/components/parameters/AgentIdPathParameter"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateAgentStatusRequest"}}}},"responses":{"200":{"description":"Agent status updated.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AgentDetail"}}}},"400":{"$ref":"#/components/responses/BadRequestError"},"401":{"$ref":"#/components/responses/UnauthorizedError"},"404":{"$ref":"#/components/responses/NotFoundError"}}}}}}
```

## GET /agents/{agent\_id}/calls

> List call history for an Agent

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Agents","description":"Operations related to Agents (Agent Service v1) — configuration, providers, and call history."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"parameters":{"AgentIdPathParameter":{"name":"agent_id","in":"path","required":true,"description":"The unique identifier (UUID) of the Agent.","schema":{"type":"string","format":"uuid"}},"LimitQueryParameter":{"name":"limit","in":"query","required":false,"description":"Number of items to return per page.","schema":{"type":"integer","default":20,"minimum":1,"maximum":100}},"OffsetQueryParameter":{"name":"offset","in":"query","required":false,"description":"Number of items to skip for pagination.","schema":{"type":"integer","default":0,"minimum":0}}},"schemas":{"CallRecord":{"type":"object","description":"A single historical call for an Agent (one call = one agent session).","properties":{"call_id":{"type":"string","format":"uuid"},"agent_id":{"type":"string","format":"uuid"},"organization_id":{"type":"string","format":"uuid"},"session_id":{"type":"string","format":"uuid","nullable":true},"applied_session_limit_seconds":{"type":"integer"},"client_user_ref":{"type":"string","nullable":true},"started_at":{"type":"string","format":"date-time"},"ended_at":{"type":"string","format":"date-time","nullable":true},"status":{"type":"string","description":"e.g. 'active', 'completed', 'failed'"},"termination_reason":{"type":"string","nullable":true},"failure_reason":{"type":"string","nullable":true},"participant_count":{"type":"integer"},"metadata":{"type":"object","additionalProperties":true,"nullable":true}},"required":["call_id","agent_id","organization_id","applied_session_limit_seconds","started_at","status","participant_count"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"NotFoundError":{"description":"The requested resource was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/agents/{agent_id}/calls":{"get":{"tags":["Agents"],"summary":"List call history for an Agent","operationId":"listAgentCalls","parameters":[{"$ref":"#/components/parameters/AgentIdPathParameter"},{"$ref":"#/components/parameters/LimitQueryParameter"},{"$ref":"#/components/parameters/OffsetQueryParameter"},{"name":"started_after","in":"query","required":false,"description":"ISO-8601 date/datetime lower bound on `started_at`.","schema":{"type":"string","format":"date-time"}},{"name":"started_before","in":"query","required":false,"description":"ISO-8601 date/datetime upper bound on `started_at`.","schema":{"type":"string","format":"date-time"}}],"responses":{"200":{"description":"Paginated call history.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/CallRecord"}},"pagination":{"type":"object","properties":{"limit":{"type":"integer"},"offset":{"type":"integer"},"total_items":{"type":"integer"}},"required":["limit","offset","total_items"]}},"required":["data","pagination"]}}}},"401":{"$ref":"#/components/responses/UnauthorizedError"},"404":{"$ref":"#/components/responses/NotFoundError"}}}}}}
```

## List STS providers

> Lists available STS (speech-to-speech) providers and the fields each expects.

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Agents","description":"Operations related to Agents (Agent Service v1) — configuration, providers, and call history."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"schemas":{"AgentProvider":{"type":"object","description":"STS provider descriptor (returned by GET /agents/providers).","properties":{"slug":{"type":"string"},"label":{"type":"string"},"required_persisted":{"type":"array","items":{"type":"string"},"description":"Provider-specific fields that must be persisted in provider_config."},"optional_persisted":{"type":"array","items":{"type":"string"},"description":"Provider-specific fields that may be persisted in provider_config."},"session_fields":{"type":"array","items":{"type":"string"},"description":"Provider-specific fields that must be supplied per-session."},"status":{"type":"string"}},"required":["slug","label","required_persisted","optional_persisted","session_fields","status"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/agents/providers":{"get":{"tags":["Agents"],"summary":"List STS providers","description":"Lists available STS (speech-to-speech) providers and the fields each expects.","operationId":"listAgentProviders","responses":{"200":{"description":"Provider catalogue.","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/AgentProvider"}}}}},"401":{"$ref":"#/components/responses/UnauthorizedError"}}}}}}
```

## Verify third-party provider credentials for an Agent

> Makes a live API call to the agent's configured STS provider using the stored\
> API key and config ID. Returns whether the credentials are valid and any error\
> detail. Does not modify the agent.

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Agents","description":"Operations related to Agents (Agent Service v1) — configuration, providers, and call history."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[{"APIKeyAuth":[]}],"components":{"securitySchemes":{"APIKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authenticated access to the Ojin REST API."}},"parameters":{"AgentIdPathParameter":{"name":"agent_id","in":"path","required":true,"description":"The unique identifier (UUID) of the Agent.","schema":{"type":"string","format":"uuid"}}},"schemas":{"VerifyProviderResult":{"type":"object","description":"Result of a live credential verification check against a third-party STS provider.","properties":{"valid":{"type":"boolean"},"provider":{"type":"string"},"error":{"type":"string","description":"Human-readable reason when valid is false."}},"required":["valid","provider"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"BadRequestError":{"description":"Invalid request payload or parameters.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"UnauthorizedError":{"description":"Authentication token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"NotFoundError":{"description":"The requested resource was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"BadGatewayError":{"description":"Upstream service (e.g. WebRTC room provider, agent orchestrator) returned an error or was unreachable.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/agents/{agent_id}/verify-provider":{"post":{"tags":["Agents"],"summary":"Verify third-party provider credentials for an Agent","description":"Makes a live API call to the agent's configured STS provider using the stored\nAPI key and config ID. Returns whether the credentials are valid and any error\ndetail. Does not modify the agent.","operationId":"verifyAgentProvider","parameters":[{"$ref":"#/components/parameters/AgentIdPathParameter"}],"responses":{"200":{"description":"Verification result (may be valid or invalid).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/VerifyProviderResult"}}}},"400":{"$ref":"#/components/responses/BadRequestError"},"401":{"$ref":"#/components/responses/UnauthorizedError"},"404":{"$ref":"#/components/responses/NotFoundError"},"502":{"$ref":"#/components/responses/BadGatewayError"}}}}}}
```

## Public Widget Endpoints

These unauthenticated endpoints are intended for browser clients such as the Ojin widget.

## Retrieve a Model Configuration (Public)

> Retrieves a specific Model Configuration by ID. This is the public variant of\
> \`GET /model-configs/{model\_config\_id}\`, designed for use by the Ojin widget\
> embedded on third-party domains. Uses permissive CORS and requires no authentication.\
> Resources are accessed by their UUID.\
> \
> Internal fields (organization\_id, created\_by, model\_id) are stripped from the response. The widget chains through \`\`model\_variant\_id\`\` and calls \`\`GET /public/model-variants/{model\_variant\_id}\`\` for catalog metadata (rendered frame size, etc.).

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Public API","description":"Public endpoints for unauthenticated browser clients such as the Ojin widget. These routes use permissive CORS (origin: '*')\nto allow the widget to be embedded on any third-party domain. No authentication is required."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[],"paths":{"/public/model-configs/{model_config_id}":{"get":{"tags":["Public API"],"summary":"Retrieve a Model Configuration (Public)","description":"Retrieves a specific Model Configuration by ID. This is the public variant of\n`GET /model-configs/{model_config_id}`, designed for use by the Ojin widget\nembedded on third-party domains. Uses permissive CORS and requires no authentication.\nResources are accessed by their UUID.\n\nInternal fields (organization_id, created_by, model_id) are stripped from the response. The widget chains through ``model_variant_id`` and calls ``GET /public/model-variants/{model_variant_id}`` for catalog metadata (rendered frame size, etc.).","operationId":"publicGetModelConfigById","parameters":[{"$ref":"#/components/parameters/ModelConfigIdPathParameter"}],"responses":{"200":{"description":"Model Configuration details (without internal fields).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PublicModelConfig"}}}},"404":{"$ref":"#/components/responses/NotFoundError"}}}}},"components":{"parameters":{"ModelConfigIdPathParameter":{"name":"model_config_id","in":"path","required":true,"description":"The unique identifier (UUID) of the Model Configuration.","schema":{"type":"string","format":"uuid"}}},"schemas":{"PublicModelConfig":{"type":"object","description":"Public variant of ModelConfig for widget embedding.\nStrips internal fields (organization_id, created_by, model_id) — the widget\nchains through ``model_variant_id`` and calls ``GET /public/model-variants/{model_variant_id}``\nwhen it needs the parent ``Model`` reference.","properties":{"model_config_id":{"type":"string","format":"uuid","readOnly":true,"description":"Server-generated unique ID."},"model_variant_id":{"type":"string","description":"ID of the ModelVariant being configured."},"title":{"type":"string","description":"Title for the configuration."},"model_configurations":{"type":"object","additionalProperties":true,"description":"Parameters for the model variant.","default":{}},"created_at":{"type":"string","format":"date-time","readOnly":true,"description":"Timestamp of creation."},"updated_at":{"type":"string","format":"date-time","readOnly":true,"description":"Timestamp of last update."}},"required":["model_config_id","model_variant_id","title","model_configurations","created_at","updated_at"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"NotFoundError":{"description":"The requested resource was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}
```

## Retrieve Asset Metadata with Download URL (Public)

> Retrieves metadata for a specific Asset, including a pre-signed download URL.\
> This is the public variant of \`GET /assets/{asset\_id}/download\`, designed for use by the\
> Ojin widget embedded on third-party domains. Uses permissive CORS and requires\
> no authentication. Resources are accessed by their UUID.\
> \
> Internal fields (organization\_id, created\_by) are stripped from the response.

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"tags":[{"name":"Public API","description":"Public endpoints for unauthenticated browser clients such as the Ojin widget. These routes use permissive CORS (origin: '*')\nto allow the widget to be embedded on any third-party domain. No authentication is required."}],"servers":[{"url":"https://api.ojin.ai/v1","description":"Main backend server, version 1."}],"security":[],"paths":{"/public/assets/{asset_id}":{"get":{"tags":["Public API"],"summary":"Retrieve Asset Metadata with Download URL (Public)","description":"Retrieves metadata for a specific Asset, including a pre-signed download URL.\nThis is the public variant of `GET /assets/{asset_id}/download`, designed for use by the\nOjin widget embedded on third-party domains. Uses permissive CORS and requires\nno authentication. Resources are accessed by their UUID.\n\nInternal fields (organization_id, created_by) are stripped from the response.","operationId":"publicGetAssetById","parameters":[{"$ref":"#/components/parameters/AssetIdPathParameter"}],"responses":{"200":{"description":"Successfully retrieved Asset metadata with download URL (without internal fields).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PublicAsset"}}}},"404":{"$ref":"#/components/responses/NotFoundError"}}}}},"components":{"parameters":{"AssetIdPathParameter":{"name":"asset_id","in":"path","required":true,"description":"The unique identifier (UUID) of the Asset.","schema":{"type":"string","format":"uuid"}}},"schemas":{"PublicAsset":{"type":"object","description":"Public variant of Asset for widget embedding.\nStrips internal fields (organization_id, created_by) and includes a pre-signed download URL.","properties":{"asset_id":{"type":"string","format":"uuid","readOnly":true,"description":"Unique identifier for the Asset."},"name":{"type":"string","description":"The original file name of the Asset."},"category":{"type":"string","description":"Primary category of the Asset (e.g., 'video', 'image', 'weight')."},"content_type":{"type":"string","description":"The MIME type of the asset."},"size_bytes":{"type":"integer","format":"int64","description":"The size of the asset in bytes."},"etag":{"type":"string","description":"The ETag of the S3 object."},"created_at":{"type":"string","format":"date-time","readOnly":true,"description":"Timestamp of creation."},"updated_at":{"type":"string","format":"date-time","readOnly":true,"description":"Timestamp of last update."},"asset_url":{"type":"string","format":"uri","readOnly":true,"description":"A temporary, pre-signed URL to download the asset's content. This URL will expire."}},"required":["asset_id","name","category","content_type","size_bytes","etag","created_at","updated_at","asset_url"]},"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}},"responses":{"NotFoundError":{"description":"The requested resource was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}
```

## Schemas

## The ModelVariant object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"ModelVariant":{"type":"object","description":"Represents a specific variant of a Model.","properties":{"model_variant_id":{"type":"string","description":"Client-provided unique identifier (e.g., \"ojin/oris-v1/standard\")."},"model_id":{"type":"string","description":"Identifier of the parent Model. NOT NULL."},"title":{"type":"string","description":"Display name for the variant. NOT NULL, unique per model_id."},"description":{"type":"object","additionalProperties":{"type":"string"},"description":"UI display texts. NOT NULL, defaults to '{}'."},"preview_media_url":{"type":"string","format":"url","nullable":true,"description":"URL for a preview media."},"configuration_schema":{"type":"object","description":"JSON schema for ModelConfig.model_configurations. NOT NULL, defaults to '{}'.","additionalProperties":true},"tags":{"type":"array","items":{"type":"string"},"description":"List of descriptive tags. NOT NULL, defaults to '[]'."},"status":{"type":"string","description":"Status (e.g., 'available', 'deprecated'). NOT NULL. List managed in code."},"created_at":{"type":"string","format":"date-time","description":"Timestamp of creation. Server-generated. Defaults to CURRENT_TIMESTAMP.","readOnly":true},"updated_at":{"type":"string","format":"date-time","description":"Timestamp of last update. Server-generated. Auto-updates.","readOnly":true}},"required":["model_variant_id","model_id","title","description","configuration_schema","tags","status","created_at","updated_at"]}}}}
```

## The ModelConfig object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"ModelConfig":{"type":"object","description":"Represents a specific configuration of a ModelVariant.","properties":{"model_config_id":{"type":"string","format":"uuid","readOnly":true,"description":"Server-generated unique ID."},"organization_id":{"type":"string","readOnly":true,"description":"Owning organization ID (from external IdP)."},"model_id":{"type":"string","readOnly":true,"description":"ID of the parent Model, derived from the Model Variant."},"model_variant_id":{"type":"string","description":"ID of the ModelVariant being configured. NOT NULL."},"created_by":{"type":"string","readOnly":true,"description":"Creator's user ID (from external IdP), or `api_key:<id>` when created via an API key."},"title":{"type":"string","description":"Title for the configuration. NOT NULL, unique per organization_id."},"model_configurations":{"type":"object","additionalProperties":true,"description":"Parameters for the model variant, adhering to its schema. NOT NULL, defaults to '{}'.","default":{}},"created_at":{"type":"string","format":"date-time","readOnly":true,"description":"Timestamp of creation. Defaults to CURRENT_TIMESTAMP."},"updated_at":{"type":"string","format":"date-time","readOnly":true,"description":"Timestamp of last update. Auto-updates."}},"required":["model_config_id","organization_id","model_id","model_variant_id","created_by","title","model_configurations","created_at","updated_at"]}}}}
```

## The ModelConfigCreationRequest object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"ModelConfigCreationRequest":{"type":"object","description":"Payload for creating a new Model Configuration.","properties":{"title":{"type":"string"},"model_variant_id":{"type":"string"},"model_configurations":{"type":"object","additionalProperties":true,"default":{}}},"required":["title","model_variant_id"]}}}}
```

## The ModelConfigUpdateRequest object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"ModelConfigUpdateRequest":{"type":"object","description":"Payload for updating a Model Configuration (title and parameters only).","properties":{"title":{"type":"string"},"model_configurations":{"type":"object","additionalProperties":true}},"required":["title","model_configurations"]}}}}
```

## The Pagination object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"Pagination":{"type":"object","properties":{"limit":{"type":"integer","description":"The number of items returned in the current page."},"offset":{"type":"integer","description":"The number of items skipped before starting the current page."},"total_items":{"type":"integer","description":"The total number of items available that match the query."}},"required":["limit","offset","total_items"]}}}}
```

## The Asset object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"Asset":{"type":"object","description":"Represents a digital asset managed by the Core API.","properties":{"asset_id":{"type":"string","format":"uuid","description":"Unique identifier for the Asset, generated during upload initiation.","readOnly":true},"organization_id":{"type":"string","description":"ID of the Organisation (from external IdP) that owns this Asset. Server-set.","readOnly":true},"created_by":{"type":"string","description":"User ID of the creator (from external IdP), or `api_key:<id>` when created via an API key. Server-set.","readOnly":true},"name":{"type":"string","description":"The original file name of the Asset. NOT NULL."},"category":{"type":"string","description":"Primary category of the Asset (e.g., 'video', 'image', 'weight'). NOT NULL. List of values managed in code."},"content_type":{"type":"string","description":"The MIME type of the asset. NOT NULL."},"size_bytes":{"type":"integer","format":"int64","description":"The size of the asset in bytes. NOT NULL."},"etag":{"type":"string","description":"The ETag of the S3 object, used for integrity checking. NOT NULL."},"created_at":{"type":"string","format":"date-time","description":"Timestamp of when this Asset record was created (finalized). Server-generated. Defaults to CURRENT_TIMESTAMP.","readOnly":true},"updated_at":{"type":"string","format":"date-time","description":"Timestamp of the last update to this Asset record. Server-generated. Auto-updates on modification.","readOnly":true},"asset_url":{"type":"string","format":"uri","readOnly":true,"description":"A temporary, pre-signed URL to download the asset's content. This URL will expire."}},"required":["asset_id","organization_id","created_by","name","category","content_type","size_bytes","etag","created_at","updated_at"]}}}}
```

## The AssetInitiateUploadRequest object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"AssetInitiateUploadRequest":{"type":"object","description":"Payload to initiate a multipart asset upload.","properties":{"name":{"type":"string","description":"Original filename of the asset."},"category":{"type":"string","description":"Category for the asset (e.g., 'video', 'image')."},"content_type":{"type":"string","nullable":true,"description":"Client-declared MIME type of the file."},"size_bytes":{"type":"integer","format":"int64","nullable":true,"description":"Client-declared file size in bytes."}},"required":["name","category"]}}}}
```

## The AssetInitiateUploadResponse object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"AssetInitiateUploadResponse":{"type":"object","description":"Response from initiating a multipart asset upload.","properties":{"asset_id":{"type":"string","format":"uuid","description":"A unique ID generated by Core API for this asset transaction."},"upload_id":{"type":"string","description":"The multipart upload ID from S3, used to identify this multipart upload session."},"s3_key":{"type":"string","description":"The S3 key for this asset."}},"required":["asset_id","upload_id"]}}}}
```

## The AssetSignPartRequest object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"AssetSignPartRequest":{"type":"object","description":"Payload to get a pre-signed URL for uploading a specific part of a multipart upload.","properties":{"s3_key":{"type":"string","description":"The S3 key for this asset."},"asset_id":{"type":"string","format":"uuid","description":"The asset ID from the initiate upload response."},"upload_id":{"type":"string","description":"The multipart upload ID from the initiate upload response."},"part_number":{"type":"integer","minimum":1,"maximum":10000,"description":"The part number for this upload part (1-10000)."}},"required":["asset_id","upload_id","part_number"]}}}}
```

## The AssetSignPartResponse object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"AssetSignPartResponse":{"type":"object","description":"Response containing the pre-signed URL for uploading a specific part.","properties":{"upload_url":{"type":"string","format":"url","description":"The pre-signed S3 URL to PUT this specific part to."},"part_number":{"type":"integer","description":"The part number this URL is for."}},"required":["upload_url","part_number"]}}}}
```

## The AssetFinalizationRequest object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"AssetFinalizationRequest":{"type":"object","description":"Payload to finalize a multipart asset upload and create the asset metadata record in DB.","properties":{"asset_id":{"type":"string","format":"uuid","description":"The unique ID received from the 'initiate-upload' step."},"upload_id":{"type":"string","description":"The multipart upload ID from the 'initiate-upload' step."},"name":{"type":"string","description":"The original filename (must be consistent with initiate request)."},"category":{"type":"string","description":"The asset category (must be consistent with initiate request)."},"content_type":{"type":"string","description":"Final confirmed MIME type of the asset."},"size_bytes":{"type":"integer","format":"int64","description":"Final confirmed size of the asset in bytes."},"parts":{"type":"array","items":{"$ref":"#/components/schemas/AssetUploadPart"},"description":"List of all uploaded parts with their ETags, in order.","minItems":1}},"required":["asset_id","upload_id","name","category","content_type","size_bytes","parts"]},"AssetUploadPart":{"type":"object","description":"Information about a completed upload part.","properties":{"part_number":{"type":"integer","minimum":1,"maximum":10000,"description":"The part number that was uploaded."},"etag":{"type":"string","description":"The ETag returned by S3 after successfully uploading this part."}},"required":["part_number","etag"]}}}}
```

## The AssetUploadPart object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"AssetUploadPart":{"type":"object","description":"Information about a completed upload part.","properties":{"part_number":{"type":"integer","minimum":1,"maximum":10000,"description":"The part number that was uploaded."},"etag":{"type":"string","description":"The ETag returned by S3 after successfully uploading this part."}},"required":["part_number","etag"]}}}}
```

## The IdleVideoGenerationRequest object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"IdleVideoGenerationRequest":{"type":"object","description":"Request payload to trigger idle video generation.","properties":{"source_asset_id":{"type":"string","format":"uuid","description":"The ID of the source image asset to use for generating the idle video."},"reference_template":{"type":"string","description":"The reference motion template to use (e.g., 'v1', 'v2', 'v3').","enum":["v1","v2","v3"]},"model_variant_id":{"type":"string","maxLength":128,"description":"Model variant the generated idle video is intended for (e.g. 'ojin/oris-portrait'). Used only to label the background job so the Recent Generations list names the right model. Optional; callers without a model context omit it and the job uses a default label."},"target_model_config_id":{"type":"string","format":"uuid","description":"Model config to assign the generated video to as its active idle preview once the job completes. When set, core-api writes model_configurations.preview server-side on completion, so the assignment lands even if the browser closed, navigated away, or refreshed mid-generation. Must be a config owned by the caller's organization. Optional; omit to only create the video without assigning it."}},"required":["source_asset_id"]}}}}
```

## The IdleVideoGenerationResponse object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"IdleVideoGenerationResponse":{"type":"object","description":"Response from triggering idle video generation.","properties":{"job_id":{"type":"string","format":"uuid","description":"Identifier of the background job created for this generation request."}},"required":["job_id"]}}}}
```

## The AgentBase object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"AgentBase":{"type":"object","description":"Basic representation of an Agent for list views.","properties":{"agent_id":{"type":"string","format":"uuid","readOnly":true},"organization_id":{"type":"string","format":"uuid","readOnly":true},"created_by":{"type":"string","readOnly":true,"description":"Creator's user ID (from external IdP), or `api_key:<id>` when the resource was created via an API key."},"title":{"type":"string","maxLength":255},"description":{"type":"string","maxLength":1000,"nullable":true},"mode":{"$ref":"#/components/schemas/AgentMode"},"status":{"$ref":"#/components/schemas/AgentStatus"},"face_id":{"type":"string","format":"uuid","nullable":true},"created_at":{"type":"string","format":"date-time","readOnly":true},"updated_at":{"type":"string","format":"date-time","readOnly":true}},"required":["agent_id","organization_id","created_by","title","mode","status","face_id","created_at","updated_at"]},"AgentMode":{"type":"string","enum":["ojin","third_party"],"description":"The operating mode of an agent. Ojin mode uses the built-in pipeline; third_party mode delegates to an external STS provider."},"AgentStatus":{"type":"string","enum":["published","unpublished"],"description":"The publication status of an agent. Published agents are available for connections; unpublished agents are not."}}}}
```

## The AgentDetail object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"AgentDetail":{"allOf":[{"$ref":"#/components/schemas/AgentBase"},{"type":"object","description":"Full Agent detail including configuration, STS credentials flags, LLM tool wiring.","properties":{"language":{"$ref":"#/components/schemas/AgentLanguage"},"system_prompt":{"type":"string","maxLength":10000,"nullable":true},"tts_provider":{"type":"string"},"voice_id":{"type":"string","maxLength":255,"nullable":true},"behaviour":{"allOf":[{"$ref":"#/components/schemas/AgentBehaviour"}],"nullable":true},"advanced":{"allOf":[{"$ref":"#/components/schemas/AgentAdvanced"}],"nullable":true},"sts_provider":{"type":"string","maxLength":100,"nullable":true},"sts_config_id":{"type":"string","maxLength":255,"nullable":true},"sts_api_key_set":{"type":"boolean","description":"True when an encrypted STS API key is persisted for this agent. The raw key is never returned."},"provider_config":{"type":"object","additionalProperties":true,"nullable":true},"preview_url":{"type":"string","maxLength":2048,"nullable":true,"description":"A direct URL or a bare asset-ID UUID. The public agent endpoint resolves UUIDs to signed S3 URLs before returning them to clients."},"starts_conversation":{"type":"boolean"},"session_limit_seconds":{"type":"integer","minimum":1,"maximum":86400},"max_concurrency":{"oneOf":[{"type":"integer","enum":[-1]},{"type":"integer","minimum":1,"maximum":100}],"description":"Maximum concurrent sessions. -1 means unbounded (no limit); valid positive values are 1–100."},"auth_enabled":{"type":"boolean"},"auth_secret_set":{"type":"boolean","description":"True when an auth secret is persisted."},"auth_secret":{"type":"string","nullable":true,"description":"Plaintext auth secret. Only returned to the creator immediately after\nagent creation (one-shot). Subsequent reads return null; use auth_secret_set\nto detect whether a secret is configured."},"allowed_hostnames":{"type":"array","nullable":true,"items":{"type":"string","maxLength":255}},"tools":{"type":"array","description":"Per-tool function-calling definitions with delivery + enabled flag.","items":{"$ref":"#/components/schemas/AgentTool"}}},"required":["language","tts_provider","sts_api_key_set","starts_conversation","session_limit_seconds","max_concurrency","auth_enabled","auth_secret_set","tools"]}]},"AgentBase":{"type":"object","description":"Basic representation of an Agent for list views.","properties":{"agent_id":{"type":"string","format":"uuid","readOnly":true},"organization_id":{"type":"string","format":"uuid","readOnly":true},"created_by":{"type":"string","readOnly":true,"description":"Creator's user ID (from external IdP), or `api_key:<id>` when the resource was created via an API key."},"title":{"type":"string","maxLength":255},"description":{"type":"string","maxLength":1000,"nullable":true},"mode":{"$ref":"#/components/schemas/AgentMode"},"status":{"$ref":"#/components/schemas/AgentStatus"},"face_id":{"type":"string","format":"uuid","nullable":true},"created_at":{"type":"string","format":"date-time","readOnly":true},"updated_at":{"type":"string","format":"date-time","readOnly":true}},"required":["agent_id","organization_id","created_by","title","mode","status","face_id","created_at","updated_at"]},"AgentMode":{"type":"string","enum":["ojin","third_party"],"description":"The operating mode of an agent. Ojin mode uses the built-in pipeline; third_party mode delegates to an external STS provider."},"AgentStatus":{"type":"string","enum":["published","unpublished"],"description":"The publication status of an agent. Published agents are available for connections; unpublished agents are not."},"AgentLanguage":{"type":"string","enum":["en","de","fr","es","ar","ja"],"description":"Spoken language code for the agent. Drives Deepgram STT language,\nElevenLabs voice filtering in the dashboard, and an LLM\nsystem-prompt suffix that pins the response language.\n"},"AgentBehaviour":{"type":"object","description":"Conversational behaviour knobs applied to an Agent.","properties":{"greeting":{"type":"string","maxLength":2000,"nullable":true},"greeting_reference":{"type":"string","maxLength":2000,"nullable":true},"greeting_mode":{"type":"string","enum":["verbatim","composed"],"nullable":true},"nudge_message":{"type":"string","maxLength":2000,"nullable":true},"nudge_reference":{"type":"string","maxLength":2000,"nullable":true},"nudge_mode":{"type":"string","enum":["verbatim","composed"],"nullable":true},"farewell_message":{"type":"string","maxLength":2000,"nullable":true},"farewell_reference":{"type":"string","maxLength":2000,"nullable":true},"farewell_mode":{"type":"string","enum":["verbatim","composed"],"nullable":true},"max_conversation_duration_seconds":{"type":"integer","minimum":1,"maximum":86400,"nullable":true},"inactivity_nudge_seconds":{"type":"integer","minimum":1,"maximum":3600,"nullable":true},"allow_interruption":{"type":"boolean","nullable":true}}},"AgentAdvanced":{"type":"object","description":"Advanced configuration for an Agent (video pipeline + LLM tuning).","properties":{"max_video_source_dimension":{"type":"integer","minimum":1,"nullable":true},"llm_max_tokens":{"type":"integer","minimum":64,"maximum":4096,"nullable":true,"description":"Maximum completion tokens the managed (Ojin-mode) LLM may generate per spoken reply. Raise it if answers get cut off mid-sentence; lower it to keep replies short. Defaults to 384 when unset."}}},"AgentTool":{"type":"object","additionalProperties":false,"description":"A function-calling tool exposed by the agent to the LLM, with per-tool delivery and enabled flag.","properties":{"tool_id":{"type":"string","format":"uuid","readOnly":true},"enabled":{"type":"boolean","default":true,"description":"When false, the tool is hidden from the LLM but its delivery config is preserved."},"type":{"type":"string","enum":["function"],"default":"function"},"function":{"$ref":"#/components/schemas/ToolFunction"},"delivery":{"$ref":"#/components/schemas/ToolDelivery"}},"required":["tool_id","enabled","type","function","delivery"]},"ToolFunction":{"type":"object","additionalProperties":false,"description":"OpenAI / Anthropic tool function definition.","properties":{"name":{"type":"string","maxLength":64,"pattern":"^[a-zA-Z0-9_-]+$","description":"Function name. Must match the LLM tool-name regex."},"description":{"type":"string","maxLength":1024,"nullable":true},"parameters":{"type":"object","additionalProperties":true,"nullable":true,"description":"JSON Schema for the function's parameters (opaque pass-through)."}},"required":["name"]},"ToolDelivery":{"oneOf":[{"$ref":"#/components/schemas/ClientToolDelivery"},{"$ref":"#/components/schemas/WebhookToolDelivery"}],"discriminator":{"propertyName":"mode","mapping":{"client":"#/components/schemas/ClientToolDelivery","webhook":"#/components/schemas/WebhookToolDelivery"}}},"ClientToolDelivery":{"type":"object","additionalProperties":false,"description":"Tool calls are delivered to the in-browser widget as an `ojinToolCall` CustomEvent.","properties":{"mode":{"type":"string","enum":["client"]}},"required":["mode"]},"WebhookToolDelivery":{"type":"object","additionalProperties":false,"description":"Tool calls are POSTed to an external webhook URL.","properties":{"mode":{"type":"string","enum":["webhook"]},"url":{"type":"string","format":"uri","maxLength":2048},"wait_for_response":{"type":"boolean","default":false,"description":"When true, the LLM waits for the webhook's response and incorporates it\ninto the conversation. When false, the webhook is fired-and-forgotten and\nthe LLM receives a neutral acknowledgement immediately."}},"required":["mode","url"]}}}}
```

## The CreateAgentRequest object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"CreateAgentRequest":{"type":"object","description":"Payload for creating a new Agent, optionally from a preset.","properties":{"title":{"type":"string","maxLength":255},"mode":{"$ref":"#/components/schemas/AgentMode"},"preset_id":{"type":"string","format":"uuid","description":"Optional preset to seed the new agent from."}},"required":["title"]},"AgentMode":{"type":"string","enum":["ojin","third_party"],"description":"The operating mode of an agent. Ojin mode uses the built-in pipeline; third_party mode delegates to an external STS provider."}}}}
```

## The UpdateAgentRequest object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"UpdateAgentRequest":{"type":"object","description":"Payload for updating an Agent (partial update — all fields optional).","properties":{"title":{"type":"string","maxLength":255},"description":{"type":"string","maxLength":1000,"nullable":true},"mode":{"$ref":"#/components/schemas/AgentMode"},"face_id":{"type":"string","format":"uuid","nullable":true},"language":{"$ref":"#/components/schemas/AgentLanguage"},"system_prompt":{"type":"string","maxLength":10000,"nullable":true},"tts_provider":{"type":"string","enum":["elevenlabs","ojin"]},"voice_id":{"type":"string","maxLength":255,"nullable":true},"behaviour":{"$ref":"#/components/schemas/AgentBehaviour"},"advanced":{"$ref":"#/components/schemas/AgentAdvanced"},"sts_provider":{"type":"string","maxLength":100,"nullable":true},"sts_api_key":{"type":"string","maxLength":1000,"nullable":true,"writeOnly":true},"sts_config_id":{"type":"string","maxLength":255,"nullable":true},"provider_config":{"type":"object","additionalProperties":true,"nullable":true},"preview_url":{"type":"string","maxLength":2048,"nullable":true,"description":"A direct URL or a bare asset-ID UUID. The public agent endpoint resolves UUIDs to signed S3 URLs before returning them to clients."},"session_limit_seconds":{"type":"integer","minimum":1,"maximum":86400},"max_concurrency":{"oneOf":[{"type":"integer","enum":[-1]},{"type":"integer","minimum":1,"maximum":100}],"description":"Maximum concurrent sessions. -1 means unbounded (no limit); valid positive values are 1–100."},"starts_conversation":{"type":"boolean"},"auth_enabled":{"type":"boolean"},"allowed_hostnames":{"type":"array","items":{"type":"string","maxLength":255}},"tools":{"type":"array","description":"Replace the agent's tools with this array (full-replace semantics).\nOmit to leave tools unchanged. UPSERTs by `function.name`; tools not\npresent in the array are deleted from the agent.","items":{"$ref":"#/components/schemas/AgentToolInput"}}}},"AgentMode":{"type":"string","enum":["ojin","third_party"],"description":"The operating mode of an agent. Ojin mode uses the built-in pipeline; third_party mode delegates to an external STS provider."},"AgentLanguage":{"type":"string","enum":["en","de","fr","es","ar","ja"],"description":"Spoken language code for the agent. Drives Deepgram STT language,\nElevenLabs voice filtering in the dashboard, and an LLM\nsystem-prompt suffix that pins the response language.\n"},"AgentBehaviour":{"type":"object","description":"Conversational behaviour knobs applied to an Agent.","properties":{"greeting":{"type":"string","maxLength":2000,"nullable":true},"greeting_reference":{"type":"string","maxLength":2000,"nullable":true},"greeting_mode":{"type":"string","enum":["verbatim","composed"],"nullable":true},"nudge_message":{"type":"string","maxLength":2000,"nullable":true},"nudge_reference":{"type":"string","maxLength":2000,"nullable":true},"nudge_mode":{"type":"string","enum":["verbatim","composed"],"nullable":true},"farewell_message":{"type":"string","maxLength":2000,"nullable":true},"farewell_reference":{"type":"string","maxLength":2000,"nullable":true},"farewell_mode":{"type":"string","enum":["verbatim","composed"],"nullable":true},"max_conversation_duration_seconds":{"type":"integer","minimum":1,"maximum":86400,"nullable":true},"inactivity_nudge_seconds":{"type":"integer","minimum":1,"maximum":3600,"nullable":true},"allow_interruption":{"type":"boolean","nullable":true}}},"AgentAdvanced":{"type":"object","description":"Advanced configuration for an Agent (video pipeline + LLM tuning).","properties":{"max_video_source_dimension":{"type":"integer","minimum":1,"nullable":true},"llm_max_tokens":{"type":"integer","minimum":64,"maximum":4096,"nullable":true,"description":"Maximum completion tokens the managed (Ojin-mode) LLM may generate per spoken reply. Raise it if answers get cut off mid-sentence; lower it to keep replies short. Defaults to 384 when unset."}}},"AgentToolInput":{"type":"object","additionalProperties":false,"description":"Input shape for an agent tool. `tool_id` is optional — when present and\nmatched (by `function.name`) the existing row is updated in place; when\nabsent or unmatched a new tool is created. `enabled` defaults to true\nand `type` defaults to \"function\" server-side when omitted.","properties":{"tool_id":{"type":"string","format":"uuid"},"enabled":{"type":"boolean"},"type":{"type":"string","enum":["function"]},"function":{"$ref":"#/components/schemas/ToolFunction"},"delivery":{"$ref":"#/components/schemas/ToolDelivery"}},"required":["function","delivery"]},"ToolFunction":{"type":"object","additionalProperties":false,"description":"OpenAI / Anthropic tool function definition.","properties":{"name":{"type":"string","maxLength":64,"pattern":"^[a-zA-Z0-9_-]+$","description":"Function name. Must match the LLM tool-name regex."},"description":{"type":"string","maxLength":1024,"nullable":true},"parameters":{"type":"object","additionalProperties":true,"nullable":true,"description":"JSON Schema for the function's parameters (opaque pass-through)."}},"required":["name"]},"ToolDelivery":{"oneOf":[{"$ref":"#/components/schemas/ClientToolDelivery"},{"$ref":"#/components/schemas/WebhookToolDelivery"}],"discriminator":{"propertyName":"mode","mapping":{"client":"#/components/schemas/ClientToolDelivery","webhook":"#/components/schemas/WebhookToolDelivery"}}},"ClientToolDelivery":{"type":"object","additionalProperties":false,"description":"Tool calls are delivered to the in-browser widget as an `ojinToolCall` CustomEvent.","properties":{"mode":{"type":"string","enum":["client"]}},"required":["mode"]},"WebhookToolDelivery":{"type":"object","additionalProperties":false,"description":"Tool calls are POSTed to an external webhook URL.","properties":{"mode":{"type":"string","enum":["webhook"]},"url":{"type":"string","format":"uri","maxLength":2048},"wait_for_response":{"type":"boolean","default":false,"description":"When true, the LLM waits for the webhook's response and incorporates it\ninto the conversation. When false, the webhook is fired-and-forgotten and\nthe LLM receives a neutral acknowledgement immediately."}},"required":["mode","url"]}}}}
```

## The UpdateAgentStatusRequest object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"UpdateAgentStatusRequest":{"type":"object","description":"Payload for toggling Agent publication status.","properties":{"status":{"$ref":"#/components/schemas/AgentStatus"}},"required":["status"]},"AgentStatus":{"type":"string","enum":["published","unpublished"],"description":"The publication status of an agent. Published agents are available for connections; unpublished agents are not."}}}}
```

## The AgentProvider object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"AgentProvider":{"type":"object","description":"STS provider descriptor (returned by GET /agents/providers).","properties":{"slug":{"type":"string"},"label":{"type":"string"},"required_persisted":{"type":"array","items":{"type":"string"},"description":"Provider-specific fields that must be persisted in provider_config."},"optional_persisted":{"type":"array","items":{"type":"string"},"description":"Provider-specific fields that may be persisted in provider_config."},"session_fields":{"type":"array","items":{"type":"string"},"description":"Provider-specific fields that must be supplied per-session."},"status":{"type":"string"}},"required":["slug","label","required_persisted","optional_persisted","session_fields","status"]}}}}
```

## The CallRecord object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"CallRecord":{"type":"object","description":"A single historical call for an Agent (one call = one agent session).","properties":{"call_id":{"type":"string","format":"uuid"},"agent_id":{"type":"string","format":"uuid"},"organization_id":{"type":"string","format":"uuid"},"session_id":{"type":"string","format":"uuid","nullable":true},"applied_session_limit_seconds":{"type":"integer"},"client_user_ref":{"type":"string","nullable":true},"started_at":{"type":"string","format":"date-time"},"ended_at":{"type":"string","format":"date-time","nullable":true},"status":{"type":"string","description":"e.g. 'active', 'completed', 'failed'"},"termination_reason":{"type":"string","nullable":true},"failure_reason":{"type":"string","nullable":true},"participant_count":{"type":"integer"},"metadata":{"type":"object","additionalProperties":true,"nullable":true}},"required":["call_id","agent_id","organization_id","applied_session_limit_seconds","started_at","status","participant_count"]}}}}
```

## The VerifyProviderResult object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"VerifyProviderResult":{"type":"object","description":"Result of a live credential verification check against a third-party STS provider.","properties":{"valid":{"type":"boolean"},"provider":{"type":"string"},"error":{"type":"string","description":"Human-readable reason when valid is false."}},"required":["valid","provider"]}}}}
```

## The AgentMode object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"AgentMode":{"type":"string","enum":["ojin","third_party"],"description":"The operating mode of an agent. Ojin mode uses the built-in pipeline; third_party mode delegates to an external STS provider."}}}}
```

## The AgentStatus object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"AgentStatus":{"type":"string","enum":["published","unpublished"],"description":"The publication status of an agent. Published agents are available for connections; unpublished agents are not."}}}}
```

## The AgentLanguage object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"AgentLanguage":{"type":"string","enum":["en","de","fr","es","ar","ja"],"description":"Spoken language code for the agent. Drives Deepgram STT language,\nElevenLabs voice filtering in the dashboard, and an LLM\nsystem-prompt suffix that pins the response language.\n"}}}}
```

## The AgentBehaviour object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"AgentBehaviour":{"type":"object","description":"Conversational behaviour knobs applied to an Agent.","properties":{"greeting":{"type":"string","maxLength":2000,"nullable":true},"greeting_reference":{"type":"string","maxLength":2000,"nullable":true},"greeting_mode":{"type":"string","enum":["verbatim","composed"],"nullable":true},"nudge_message":{"type":"string","maxLength":2000,"nullable":true},"nudge_reference":{"type":"string","maxLength":2000,"nullable":true},"nudge_mode":{"type":"string","enum":["verbatim","composed"],"nullable":true},"farewell_message":{"type":"string","maxLength":2000,"nullable":true},"farewell_reference":{"type":"string","maxLength":2000,"nullable":true},"farewell_mode":{"type":"string","enum":["verbatim","composed"],"nullable":true},"max_conversation_duration_seconds":{"type":"integer","minimum":1,"maximum":86400,"nullable":true},"inactivity_nudge_seconds":{"type":"integer","minimum":1,"maximum":3600,"nullable":true},"allow_interruption":{"type":"boolean","nullable":true}}}}}}
```

## The AgentAdvanced object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"AgentAdvanced":{"type":"object","description":"Advanced configuration for an Agent (video pipeline + LLM tuning).","properties":{"max_video_source_dimension":{"type":"integer","minimum":1,"nullable":true},"llm_max_tokens":{"type":"integer","minimum":64,"maximum":4096,"nullable":true,"description":"Maximum completion tokens the managed (Ojin-mode) LLM may generate per spoken reply. Raise it if answers get cut off mid-sentence; lower it to keep replies short. Defaults to 384 when unset."}}}}}}
```

## The AgentTool object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"AgentTool":{"type":"object","additionalProperties":false,"description":"A function-calling tool exposed by the agent to the LLM, with per-tool delivery and enabled flag.","properties":{"tool_id":{"type":"string","format":"uuid","readOnly":true},"enabled":{"type":"boolean","default":true,"description":"When false, the tool is hidden from the LLM but its delivery config is preserved."},"type":{"type":"string","enum":["function"],"default":"function"},"function":{"$ref":"#/components/schemas/ToolFunction"},"delivery":{"$ref":"#/components/schemas/ToolDelivery"}},"required":["tool_id","enabled","type","function","delivery"]},"ToolFunction":{"type":"object","additionalProperties":false,"description":"OpenAI / Anthropic tool function definition.","properties":{"name":{"type":"string","maxLength":64,"pattern":"^[a-zA-Z0-9_-]+$","description":"Function name. Must match the LLM tool-name regex."},"description":{"type":"string","maxLength":1024,"nullable":true},"parameters":{"type":"object","additionalProperties":true,"nullable":true,"description":"JSON Schema for the function's parameters (opaque pass-through)."}},"required":["name"]},"ToolDelivery":{"oneOf":[{"$ref":"#/components/schemas/ClientToolDelivery"},{"$ref":"#/components/schemas/WebhookToolDelivery"}],"discriminator":{"propertyName":"mode","mapping":{"client":"#/components/schemas/ClientToolDelivery","webhook":"#/components/schemas/WebhookToolDelivery"}}},"ClientToolDelivery":{"type":"object","additionalProperties":false,"description":"Tool calls are delivered to the in-browser widget as an `ojinToolCall` CustomEvent.","properties":{"mode":{"type":"string","enum":["client"]}},"required":["mode"]},"WebhookToolDelivery":{"type":"object","additionalProperties":false,"description":"Tool calls are POSTed to an external webhook URL.","properties":{"mode":{"type":"string","enum":["webhook"]},"url":{"type":"string","format":"uri","maxLength":2048},"wait_for_response":{"type":"boolean","default":false,"description":"When true, the LLM waits for the webhook's response and incorporates it\ninto the conversation. When false, the webhook is fired-and-forgotten and\nthe LLM receives a neutral acknowledgement immediately."}},"required":["mode","url"]}}}}
```

## The AgentToolInput object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"AgentToolInput":{"type":"object","additionalProperties":false,"description":"Input shape for an agent tool. `tool_id` is optional — when present and\nmatched (by `function.name`) the existing row is updated in place; when\nabsent or unmatched a new tool is created. `enabled` defaults to true\nand `type` defaults to \"function\" server-side when omitted.","properties":{"tool_id":{"type":"string","format":"uuid"},"enabled":{"type":"boolean"},"type":{"type":"string","enum":["function"]},"function":{"$ref":"#/components/schemas/ToolFunction"},"delivery":{"$ref":"#/components/schemas/ToolDelivery"}},"required":["function","delivery"]},"ToolFunction":{"type":"object","additionalProperties":false,"description":"OpenAI / Anthropic tool function definition.","properties":{"name":{"type":"string","maxLength":64,"pattern":"^[a-zA-Z0-9_-]+$","description":"Function name. Must match the LLM tool-name regex."},"description":{"type":"string","maxLength":1024,"nullable":true},"parameters":{"type":"object","additionalProperties":true,"nullable":true,"description":"JSON Schema for the function's parameters (opaque pass-through)."}},"required":["name"]},"ToolDelivery":{"oneOf":[{"$ref":"#/components/schemas/ClientToolDelivery"},{"$ref":"#/components/schemas/WebhookToolDelivery"}],"discriminator":{"propertyName":"mode","mapping":{"client":"#/components/schemas/ClientToolDelivery","webhook":"#/components/schemas/WebhookToolDelivery"}}},"ClientToolDelivery":{"type":"object","additionalProperties":false,"description":"Tool calls are delivered to the in-browser widget as an `ojinToolCall` CustomEvent.","properties":{"mode":{"type":"string","enum":["client"]}},"required":["mode"]},"WebhookToolDelivery":{"type":"object","additionalProperties":false,"description":"Tool calls are POSTed to an external webhook URL.","properties":{"mode":{"type":"string","enum":["webhook"]},"url":{"type":"string","format":"uri","maxLength":2048},"wait_for_response":{"type":"boolean","default":false,"description":"When true, the LLM waits for the webhook's response and incorporates it\ninto the conversation. When false, the webhook is fired-and-forgotten and\nthe LLM receives a neutral acknowledgement immediately."}},"required":["mode","url"]}}}}
```

## The PublicModelConfig object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"PublicModelConfig":{"type":"object","description":"Public variant of ModelConfig for widget embedding.\nStrips internal fields (organization_id, created_by, model_id) — the widget\nchains through ``model_variant_id`` and calls ``GET /public/model-variants/{model_variant_id}``\nwhen it needs the parent ``Model`` reference.","properties":{"model_config_id":{"type":"string","format":"uuid","readOnly":true,"description":"Server-generated unique ID."},"model_variant_id":{"type":"string","description":"ID of the ModelVariant being configured."},"title":{"type":"string","description":"Title for the configuration."},"model_configurations":{"type":"object","additionalProperties":true,"description":"Parameters for the model variant.","default":{}},"created_at":{"type":"string","format":"date-time","readOnly":true,"description":"Timestamp of creation."},"updated_at":{"type":"string","format":"date-time","readOnly":true,"description":"Timestamp of last update."}},"required":["model_config_id","model_variant_id","title","model_configurations","created_at","updated_at"]}}}}
```

## The PublicAsset object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"PublicAsset":{"type":"object","description":"Public variant of Asset for widget embedding.\nStrips internal fields (organization_id, created_by) and includes a pre-signed download URL.","properties":{"asset_id":{"type":"string","format":"uuid","readOnly":true,"description":"Unique identifier for the Asset."},"name":{"type":"string","description":"The original file name of the Asset."},"category":{"type":"string","description":"Primary category of the Asset (e.g., 'video', 'image', 'weight')."},"content_type":{"type":"string","description":"The MIME type of the asset."},"size_bytes":{"type":"integer","format":"int64","description":"The size of the asset in bytes."},"etag":{"type":"string","description":"The ETag of the S3 object."},"created_at":{"type":"string","format":"date-time","readOnly":true,"description":"Timestamp of creation."},"updated_at":{"type":"string","format":"date-time","readOnly":true,"description":"Timestamp of last update."},"asset_url":{"type":"string","format":"uri","readOnly":true,"description":"A temporary, pre-signed URL to download the asset's content. This URL will expire."}},"required":["asset_id","name","category","content_type","size_bytes","etag","created_at","updated_at","asset_url"]}}}}
```

## The ErrorResponse object

```json
{"openapi":"3.0.0","info":{"title":"Ojin REST API","version":"v1.0.0"},"components":{"schemas":{"ErrorResponse":{"type":"object","properties":{"code":{"type":"string","description":"A short, machine-readable error code string."},"message":{"type":"string","description":"A human-readable description of the error."},"details":{"type":"object","additionalProperties":true,"nullable":true,"description":"Optional. Additional structured details about the error."}},"required":["code","message"]}}}}
```


# Support

Need help with the Ojin platform? We're here to assist you with any questions, issues, or feedback you may have.

## Contact Us

For support inquiries, please reach out to our team:

**Email**: <support@ojin.ai>

**Please do not send job applications to this address. We cannot respond to them.**

Our support team will respond to your inquiry as soon as possible.

{% hint style="info" %}
Use this address for support inquiries about the Ojin platform and for data-rights requests, including [account and data deletion](/getting-started/data-deletion). For everything else, please refer to [ojin.ai](https://ojin.ai).
{% endhint %}

## What to Include in Your Support Request

To help us assist you more efficiently, please include the following information when contacting support:

* **Description**: A clear description of your issue or question
* **Model**: Which model you're working with (e.g., `ojin/human-presence`, `ojin/human-portrait`)
* **Error Messages**: Any error messages or codes you're encountering
* **Steps to Reproduce**: If applicable, steps to reproduce the issue
* **Expected vs Actual Behavior**: What you expected to happen vs what actually happened
* **Environment**: Your development environment details (language, framework, etc.)

{% hint style="info" %}
Before reaching out, check the [Troubleshooting guide](/guides/troubleshooting).
{% endhint %}

## Additional Resources

* [Documentation](/)
* [Data Deletion](/getting-started/data-deletion)
* [Quickstart Guide](/getting-started/quickstart)
* [Build with the Python SDK](/models/build-with-python-sdk)
* [Human Presence](/models/human-presence)
* [Human Portrait](/models/human-portrait)


# Data Deletion

You can ask us to delete your Ojin account at any time.

## How to request deletion

From the dashboard, go to **Settings → Account** and use **Request deletion**. That sends the request to our team directly. We run a few internal checks, delete your account, and email you to confirm once it is done.

## What gets deleted

Deletion removes your **Ojin login** and cancels any pending invitations to join an organization. You can no longer sign in with it. If you sign up again later with the same email address, you start over with a new, empty account.

Ojin accounts belong to an **organization**, and the organization is not deleted with your login. Its agents, model configurations, API keys, uploaded assets, knowledge and session records stay in place, because they belong to the organization rather than to you. Colleagues in the same organization keep working as before.

**Where you are the only member of your organization**, we also end its paid plan so it does not renew. Usage of the organization's API keys or published agents is still billed as usual.

## What we have to keep

We cannot delete everything, and we would rather say so than promise otherwise.

Ojin is operated by Journee Technologies GmbH, a German company, and German law (§147 AO / §257 HGB) requires us to retain **invoices and accounting records for ten years**. The GDPR recognises this: the right to erasure does not override a legal retention obligation (Art. 17(3)(b)).

In practice this means your organization's invoices are kept, together with the billing customer record they are attached to, which carries the name, email address and postal address used for billing. **Where nobody else is a member of your organization or holds a pending invitation to it**, we replace the billing contact email on that record, with us and with our payment provider, by an address of our own, so billing notices no longer reach you. Otherwise, billing notices for the organization can still go to that address. Our payment provider likewise retains a record of past charges.

We also keep a **record of the deletion request itself** and what we did, as the evidence that we handled your request properly. Data-protection rules expect us to be able to show that, so this record outlives the account it refers to.

Anything we retain for these reasons is kept for that purpose alone and is not used to operate the product or to contact you. The one exception is billing: where your organization still has other members or pending invitations, its billing notices keep going to the billing contact on file.

## How long it takes

We respond to deletion requests **within 30 days of receiving them** and usually complete them in that time.

## Questions

Email <support@ojin.ai>.


# Human Agent

Ojin's star product, give your AI agent a face. A lifelike visual avatar that speaks, listens, and expresses emotion with real-time synchronized animation, embedded with a single line of code.

## Overview

The Human Agent is Ojin's complete, ready-to-deploy conversational agent: it combines speech-to-speech (STS) with a lifelike animated face, powered by one of Ojin's face models, [Human Presence](/models/human-presence) or [Human Portrait](/models/human-portrait), into one product. Instead of wiring up STT, LLM, TTS, and avatar services yourself, you create an agent in the Ojin dashboard, embed a single widget on your site, and your users get a live, real-time conversation with a fully animated avatar. It's the fastest way to ship a talking agent, with no pipeline to assemble.

## Key Features

* **Lifelike visual avatar**: your agent has a face with synchronized lip movements and natural expressions
* **End-to-end conversational AI**: speech in, speech out, no pipeline assembly required
* **Real-time**: WebRTC transport for audio, video, and signaling
* **No pipeline assembly required**: Ojin manages the full speech-to-speech stack (or bring your own provider)
* **Drop-in widget**: one HTML tag to embed the agent in any web page
* **Dashboard configuration**: create, configure, and monitor agents without writing code
* **Knowledge**: the agent answers from your organization's documents, kept in its prompt or searched during the conversation

## Agent Modes

### Ojin Agent (managed)

You configure the personality and appearance, system prompt, face, voice, and behaviour. Ojin handles everything else: the conversational pipeline, avatar rendering, and infrastructure. You never see or manage the underlying providers.

### Third-Party Agent

You bring your own speech-to-speech provider: ElevenLabs Agents or OpenAI Realtime (Hume is available to enabled organisations on request). Ojin adds the visual avatar layer and runs the agent through Ojin infrastructure. You supply that provider's credentials in the dashboard (ElevenLabs Agents needs an API key and an agent ID; OpenAI Realtime needs an API key, with its other settings optional); Ojin handles the rest.

## How It Works

1. **Create an agent** in the [Ojin dashboard](https://ojin.ai/dashboard). Pick a mode, configure it, publish it
2. **Get your agent ID** from the agent settings page
3. **Embed the widget** on your site or call the Session API from your backend
4. **Your users interact** via WebRTC: audio, video, and real-time avatar in a single connection

What a session looks like once the agent is live:

```mermaid
sequenceDiagram
    participant U as Your user
    participant C as Widget or your client
    participant S as Session API
    participant A as Ojin agent runtime

    C->>S: POST /v1/public/agents/connect (agent_id)
    S-->>C: session_id, room_url, room_name, token, provider
    C->>A: Join the WebRTC room (credentials for that provider)
    A-->>C: Agent audio + avatar video tracks
    loop Conversation
        U->>A: Speech
        A-->>U: Spoken reply, lip-synced avatar
    end
```

The widget performs every step above for you. Call the [Session API](/apps/overview/api-reference) directly only if you are building a custom client. A custom client must branch on `provider`, which is `daily` or `livekit`, because the two take different join inputs:

* **Daily** joins with `room_url` and `token`. The room is part of the URL.
* **LiveKit** joins with `room_url` as the server URL, plus `room_name` and `token`. The URL does not name the room.

Either way, keep `room_name`: it is what the cancel endpoint takes.

## Use Cases

* **Customer Support**: let customers talk to a lifelike agent instead of a chatbot
* **Sales**: greet and qualify leads with a conversational avatar
* **Education**: build interactive tutors with natural speech and expressions
* **Healthcare**: create empathetic virtual health assistants
* **Reception**: deploy a digital receptionist on your website or kiosk

## Pricing

Agent sessions are metered based on usage. Visit [ojin.ai/pricing](https://ojin.ai/pricing) for details on plans and per-session costs.

## Quick Start

1. [**Create an API key**](/getting-started/authentication): set up authentication for the Ojin platform
2. [**Create & configure your agent**](/apps/overview/configure): set up appearance, voice, and behaviour
3. [**Widget Integration**](/apps/overview/widget-integration): drop the agent into your web page
4. [**Session API Reference**](/apps/overview/api-reference): for custom integrations beyond the widget


# Create & Configure

Set up your Human Agent in the Ojin dashboard. Pick a mode, configure appearance and behaviour, and publish it.

## Prerequisites

1. An Ojin account. An API key is only needed if you will manage agents from your own backend rather than the dashboard, [get your API key](/getting-started/authentication)

## Creating an Agent

Head to the [Ojin dashboard](https://ojin.ai/dashboard) and create a new agent. Give it a name and pick your mode:

* **Ojin Agent**: Ojin handles everything: the conversational pipeline and avatar rendering. You just configure the personality and appearance.
* **Third-Party Agent**: you bring your own speech-to-speech provider (ElevenLabs Agents or OpenAI Realtime). Ojin adds the visual avatar.

### Starting from a Preset

If you choose Ojin Agent mode, you can start from a preset, a ready-made template that pre-fills the face, voice, system prompt, and behaviour for common use cases like Customer Support, Sales Assistant, or Receptionist. You can customize everything after creation.

Alternatively, start blank and configure each field yourself.

## Editing and saving

Edit an agent's name and description in the header of its configure page. Text appears as you type and stays visible when you click away. A name is required. Leaving the name blank shows **Name is required** when you leave the field.

Valid changes save automatically one second after your last edit. The status beside the agent's name shows the save progress:

* **Unsaved changes**: edits are waiting for autosave.
* **Saving…**: a save is running or waiting for an earlier save to finish.
* **Saved**: the latest valid changes have finished saving.
* **Couldn't save**: a save failed. Your text remains editable so you can correct it and try again.

You can keep editing while a save runs. Your latest edits remain visible while changes save in order. The dashboard sends valid pending edits when you switch agents or move to another dashboard page. Wait for **Saved** before closing or reloading the browser.

## Configuring an Ojin Agent

### System Prompt

Write a prompt that defines how the agent behaves: its personality, tone, and any instructions for the conversation. This works the same as a system prompt for any LLM. For documents and reference material the agent should answer from, use [Knowledge](/apps/overview/knowledge) rather than pasting them into the prompt.

#### Expressions

Under the system prompt you can set how the agent uses voice cues such as laughs, sighs and whispers. The agent's voice performs them, and they never appear in the chat transcript or the captions. They apply when the agent speaks through ElevenLabs.

* **Expressions** sets how often the agent uses them: Off, Subtle, Balanced (the default) or Expressive. Off means the agent speaks without laughs, sighs or other cues.
* **Laughter, Whispering, Sighs and breaths, Tone shifts, Crying** turn each kind on or off. When a kind is off, the agent never does it. It is removed before the voice is generated, so it cannot slip through.
* **Delivery note** is one short rule, up to 300 characters. Example: "Never laugh while the user describes a problem."

Changes apply to the next session. You do not need to edit the system prompt.

### Face

Pick a visual appearance for your agent. The face is powered by one of Ojin's face models, [Human Presence](/models/human-presence) or [Human Portrait](/models/human-portrait), which generate lifelike personas from a single reference image. Browse the available face configurations in the dashboard and select the one that best fits your agent's personality.

Production keeps the existing face selector. The searchable face field and live-switch behavior below are enabled only in the local/staging trial.

In the local/staging trial, search by name and scroll to load more organization faces and templates. To add a face, choose **New face** or drop a JPEG, PNG, or WebP image on the face thumbnail or picker; the create dialog lets you name it before saving.

Changing between Human Presence and Human Portrait in the local/staging trial keeps the selected portrait. When Ojin creates a face configuration for the new model, it carries over the portrait and settings that model accepts; other settings use that model's defaults. If you switch back to a model already used in the current configure session, Ojin reuses its configuration. If the target model or a compatible configuration cannot be loaded or applied, the current saved face stays selected and the picker shows feedback.

Changing a face model does not reallocate an active call. During a local/staging preview call, you can still choose a face, but the model picker is disabled until the call ends. A connected local/staging preview updates in place only when its host and allocated face model support live switching; otherwise, the saved face is used the next time the agent connects. During a supported refresh while a preview call is connected, the preview keeps its size. The current face blurs for 160 ms, then the requested portrait eases in over 200 ms, and the cover stays until the new video frame is confirmed. If the refresh fails, or the requested portrait cannot be loaded, the last usable face returns and the widget shows retry guidance. An idle face change, when the preview is not in a call, swaps straight to the new portrait with no cover, blur, or loading indicator. If that idle change fails during the refresh, the retry message shows and the previous portrait stays. Reduced motion skips the live blur, the portrait ease, and the cover reveal, shows the requested portrait immediately, and follows a change to that setting during the switch. After a failed live switch, the retry guidance stays once the cover lifts and the previous face is back. Production keeps its existing face-selection and preview-refresh behavior.

### Captions

Choose the caption treatment shown over the avatar while it speaks:

* **Off**: do not show captions
* **Conversation**: calm captions with active-word emphasis
* **TikTok**: kinetic one-to-four-word beats with active-word emphasis
* **YouTube**: bold, uppercase karaoke captions
* **Arthouse**: restrained cinematic subtitles
* **Journalist**: an editorial caption pill with an active-word underline

The dashboard also lets you choose dark or light text, an accent colour, text size, and no background or a solid background. Arthouse always uses its yellow text without a background. The widget uses the style's matching typeface and animation automatically.

Caption settings belong to the agent creator. Viewers cannot override or turn them off. The widget temporarily hides captions while its chat panel is open. New agents start with captions off until their creator chooses a style.

### Voice

Select a TTS voice for the agent's speech output. The voice determines how the agent sounds when it responds.

Ojin Agents speak through ElevenLabs. The default model is `eleven_v4_turbo`, which performs audio tags: the agent's language model can open a sentence with a delivery cue such as `[laughs]` or `[whispers]`, and the voice performs it. You do not need to write anything about tags in your system prompt. Ojin adds the instructions, and the tags never appear in the chat transcript or the captions.

To put one agent on a different ElevenLabs model, set `elevenlabs_model` in the agent's `advanced_overrides` (for example `eleven_flash_v2_5` for the classic text-to-speech path, which does not perform tags). An `eleven_v3` model needs a voice selected for the agent, and that voice cannot be a professional voice. An `eleven_v4` model uses the agent's voice, or the default voice when the agent has none.

### Behaviour

Configure how the agent interacts:

* **Starts conversation**: whether the agent speaks first or waits for the user
* **Greeting**: the first thing the agent says when a session starts. Either spoken verbatim, or composed from a style reference
* **Farewell**: what the agent says when the session ends
* **Inactivity nudge**: a message the agent sends if the user stays silent, with the delay in seconds
* **Max conversation length**: how long a conversation may run, in seconds
* **Allow interruption**: whether the user can talk over the agent

The voice you pick also sets the agent's language (English, German, French, Spanish, Arabic or Japanese).

### Knowledge

Tick the collections of your organization's knowledge the agent answers from, either in its prompt or by searching them during the conversation. See [**Knowledge**](/apps/overview/knowledge) for adding knowledge, collections, limits, and what callers can ask the agent to repeat.

### Tools (Function Calling)

Give the agent tools it can call during a conversation, to look something up, update your UI, or notify a backend. Add and configure tools here, choosing how each one's calls are delivered (to a webhook or to the embedding page). See [**Tools & Events**](/apps/overview/tools) for the delivery modes and how to handle calls.

### Advanced Settings

* **Max response length**: the token ceiling for a single agent reply (64 to 4096, default 384)

Developer accounts also get an overrides field for pipeline settings that are not exposed in the UI.

### Session length

Set **Max conversation length** in seconds under Behaviour. A dashboard-created agent defaults to 360 seconds (6 minutes), and the hard session cap sits 60 seconds above whatever you set. The allowed range is 1 to 86400 seconds. When the cap is reached, the session ends automatically.

## Configuring a Third-Party Agent

### Face

Same as Ojin Agent. Pick a visual appearance using [Human Presence](/models/human-presence) or [Human Portrait](/models/human-portrait). Regardless of which provider powers the conversation, Ojin renders the avatar.

### Provider

Select your speech-to-speech provider from the dropdown:

* **ElevenLabs Agents**: enter your ElevenLabs API key and your ElevenLabs agent ID (both required). To fill the ElevenLabs agent's `{{placeholders}}` for each chat, see [Dynamic Variables for ElevenLabs Agents](/apps/overview/widget-integration#dynamic-variables-for-elevenlabs-agents).
* **OpenAI Realtime**: enter your OpenAI API key. Voice, instructions, model and turn-detection mode are optional.

**Hume** is also supported, but only for organisations that have been enabled for it. If your organisation has not, Hume does not appear in the dropdown. Ask support if you need it.

{% hint style="warning" %}
Your provider API key is encrypted at rest and never displayed after you save it. To rotate a key, enter the new one in the dashboard. It takes effect for new sessions immediately.
{% endhint %}

## Publishing your agent

When your agent is configured, publish it from the **Publish** tab in the [dashboard](https://ojin.ai/dashboard). An agent is either published or unpublished. The system validates that all required fields are filled before allowing it to go live:

* **Ojin Agent** requires: a name, instructions (the system prompt), a voice and its voice provider, and a face
* **Third-Party Agent** requires: a name, a provider, and that provider's required credentials (the API key, plus the agent ID for ElevenLabs Agents)

A face is strongly recommended for a third-party agent but is not enforced at publish time.

If anything is missing, the dashboard tells you which fields need attention.

## Concurrency

The **max concurrency** setting caps how many sessions your agent runs at once. New agents are **unbounded** by default (`max_concurrency` is `-1`). Set a positive value between 1 and 100 to cap it. The field is set through the API rather than the dashboard.

When all slots are in use, new connection attempts get a `429` whose `error` is `concurrency_limit`, with a `retry_after_seconds` hint.

## Next Steps

* [**Tools & Events**](/apps/overview/tools): give the agent function-calling tools and react to it from your page
* [**Widget Integration**](/apps/overview/widget-integration): add the agent to your web page
* [**Session API Reference**](/apps/overview/api-reference): for custom integrations


# Knowledge

Give your Human Agent your organization's documents to answer from, in its prompt or by searching them during a conversation.

Knowledge is the text and documents your agents answer from: product guides, policies, price lists, FAQs. It belongs to your organization, is grouped into **collections**, and each agent uses only the collections you tick for it.

{% hint style="warning" %}
**Knowledge works only for Ojin Agents.** A Third-Party Agent (ElevenLabs Agents, OpenAI Realtime) runs its own conversation and never receives your organization's knowledge.
{% endhint %}

## Adding knowledge

Open **Knowledge** in the [Ojin dashboard](https://ojin.ai/dashboard) sidebar and choose **Add knowledge**. You can:

* **Upload files**: `.txt`, `.md`, `.pdf`, `.docx` (Word) or `.pptx` (PowerPoint), several at once.
* **Paste text**: give it a title and paste the text.

Every item goes into a collection. Pick an existing one, or name a new one in the same dialog.

An item can't be edited. To change one, delete it and add the new version.

### Status

Each item shows its status on the Knowledge page:

* **Processing…**: Ojin is extracting the text of a document, or making an item searchable.
* **Ready**: agents can use the item the way its collection says.
* **Failed**: the item can't be used, with the reason. Some failures offer **Retry**. Others mean the file needs fixing, such as "This file can't be read" for a password-protected or damaged file.

**Try a search** on the Knowledge page shows what a search finds in your organization's knowledge.

## Collections

Every item belongs to exactly one collection, and each collection is one of two kinds:

* **Search only** (the default for a new collection): the agent searches the collection during a conversation and gets the passages that best match.
* **Always in the prompt**: the full text of the collection's items goes into the agent's prompt at the start of every session.

Use **Always in the prompt** for short material the agent needs in nearly every conversation, such as opening hours or key policies. Use **Search only** for everything else, especially long documents.

* Collection names are unique within your organization, ignoring case.
* Switching a collection between the two kinds applies from each agent's next session.
* Moving an item into a **Search only** collection makes it **Processing…** until it can be searched there. An item moved into an **Always in the prompt** collection keeps its status.
* Deleting a collection deletes every item in it, and removes it from every agent that uses it.

## Using knowledge in an agent

In an Ojin Agent's settings, on the **Basics** tab under **Conversation**, tick the collections the agent uses under **Knowledge**. An agent with nothing ticked uses no knowledge. An agent can use up to 45 collections. Changes apply from the agent's next session.

Under the checklist, the dashboard estimates how much the ticked **Always in the prompt** collections add to the agent's prompt ("Adds ≈N tokens…").

### How the agent uses it

* **Always in the prompt:** the ready items of the agent's ticked **Always in the prompt** collections are added after your system prompt, under a "Reference material" heading, and are sent to the LLM with every reply.
* **Search only:** when a ticked **Search only** collection has a ready item, the agent gets a built-in `search_knowledge` tool. It searches only the collections ticked for it, of both kinds, and gets 5 passages per search, each with its item's title and, for PDF and Word files, its page.
  * The agent may search up to 3 times per caller turn, and searches count toward the [3 tool calls per model response](/apps/overview/tools).
  * `search_knowledge` is reserved: a custom tool of that name is replaced by the built-in search while the agent has searchable knowledge.
  * The agent is asked to say a short line before it searches, such as that it's looking it up. On the default model it doesn't, in our measurements, so callers hear a short pause before the answer.
  * When nothing matches, or a search fails, the agent hears that nothing in your knowledge matched.

Text you add to an **Always in the prompt** collection is ready for the agent's prompt at once, but searches find it only after Ojin has indexed it, usually within minutes. Nothing on the Knowledge page shows that step. Material you want found by search belongs in a **Search only** collection, where **Ready** means searchable.

Ojin tells the agent to answer from your reference material when it covers the question. It adds no instruction to cite sources, to say when your knowledge doesn't cover something, or to keep the material private. Put any such rules in the agent's system prompt.

{% hint style="danger" %}
**Anyone who can talk to the agent can hear its knowledge.** A caller can ask the agent to read out what is in its prompt or what it finds by search, and what the agent says appears in the transcript. Only add material every caller may hear.
{% endhint %}

## Limits

| What                                                 | Limit                                     |
| ---------------------------------------------------- | ----------------------------------------- |
| A text item (`.txt`, `.md` or pasted text)           | 4 MiB                                     |
| A document (`.pdf`, `.docx`, `.pptx`)                | 500 MB, and up to 4 MiB of extracted text |
| Item title                                           | 200 characters                            |
| Collection name                                      | 100 characters                            |
| Collections per agent                                | 45                                        |
| **Always in the prompt** knowledge one session loads | 4 MiB of text and 500 items               |

When an agent's ticked **Always in the prompt** collections hold more than the session limit, the agent's sessions don't start: connecting answers `422` (see the Session API's [error responses](/apps/overview/api-reference#error-responses)). The Knowledge page and the agent's checklist warn when that happens. Untick a collection or switch it to **Search only**.

The agent's model sets a lower practical limit. The default model reads about 128,000 tokens in all: your system prompt, the knowledge in the prompt, and the conversation so far. Keep the "Adds ≈N tokens" figure well below that, and move larger material to **Search only** collections. Above the model's limit the agent stays silent: the call stays connected, but the agent can't reply. The estimate assumes about 4 bytes of text per token, so it undercounts text in scripts such as Japanese or Arabic.

## Managing knowledge with the API

Every knowledge endpoint accepts your API key in the `X-API-Key` header (see [Get your API key](/getting-started/authentication)) and acts on that key's organization. The base URL is `https://api.ojin.ai`.

| Endpoint                                           | What it does                                                                            |
| -------------------------------------------------- | --------------------------------------------------------------------------------------- |
| `GET /v1/knowledge/collections`                    | List the organization's collections, by name                                            |
| `POST /v1/knowledge/collections`                   | Create a collection: `name`, and `in_prompt` (`false` for **Search only**, the default) |
| `PATCH /v1/knowledge/collections/{collection_id}`  | Rename a collection (`name`) or switch its kind (`in_prompt`)                           |
| `DELETE /v1/knowledge/collections/{collection_id}` | Delete a collection and every item in it                                                |
| `POST /v1/knowledge/uploads`                       | Start an upload (see below)                                                             |
| `POST /v1/knowledge/items`                         | Finish an upload (see below)                                                            |
| `GET /v1/knowledge/items`                          | List every item, without its text, plus the organization's limits                       |
| `GET /v1/knowledge/items/{item_id}`                | One item, with the text agents load as `content`                                        |
| `PATCH /v1/knowledge/items/{item_id}`              | Move an item to another collection (`collection_id`)                                    |
| `DELETE /v1/knowledge/items/{item_id}`             | Delete an item                                                                          |
| `POST /v1/knowledge/items/{item_id}/retry`         | Retry an item whose `retryable` is `true`                                               |
| `POST /v1/knowledge/search`                        | Search the organization's knowledge (see [below](#searching-from-your-own-llm))         |

### Uploading a file

Create a collection first: every item needs one.

1. **Start the upload** with the file's exact size in bytes and its type:

   ```bash
   curl -X POST https://api.ojin.ai/v1/knowledge/uploads \
     -H "X-API-Key: $OJIN_API_KEY" \
     -H "Content-Type: application/json" \
     -d '{ "content_length": 48213, "file_extension": "pdf" }'
   ```

   The answer holds an `item_id`, an `upload_url`, the `upload_headers` the upload must send, and `expires_at`. A file over the limit for its type answers `413`.
2. **Upload the file** to `upload_url` with a `PUT` that sends exactly the `upload_headers` and nothing else, within 15 minutes:

   ```bash
   curl -X PUT "$UPLOAD_URL" \
     -H "Content-Type: application/pdf" \
     -H "If-None-Match: *" \
     --data-binary @returns-policy.pdf
   ```

   Upload from your server. The upload URL accepts browser uploads only from the Ojin dashboard.
3. **Finish the upload** with the same `item_id` and `file_extension`, a `title`, and the `collection_id` it goes in:

   ```bash
   curl -X POST https://api.ojin.ai/v1/knowledge/items \
     -H "X-API-Key: $OJIN_API_KEY" \
     -H "Content-Type: application/json" \
     -d '{
       "item_id": "'"$ITEM_ID"'",
       "title": "Returns policy",
       "file_extension": "pdf",
       "collection_id": "'"$COLLECTION_ID"'"
     }'
   ```

   A new item answers `201`; finishing the same upload again returns the item with `200`. A collection that isn't your organization's answers `400`.

Each item carries a `status` (`processing`, `ready` or `failed`). A failed item also has a `failure_reason`:

| `failure_reason`    | Meaning                                                                                                  |
| ------------------- | -------------------------------------------------------------------------------------------------------- |
| `no_text`           | No text was found in the file                                                                            |
| `too_much_text`     | The file has more text than an agent can load                                                            |
| `unsupported`       | The file can't be read; check it isn't password-protected or damaged                                     |
| `source_missing`    | The uploaded file is missing; delete the item and upload it again                                        |
| `processing_failed` | The file couldn't be processed; retry it when `retryable` is `true`                                      |
| `not_searchable`    | An item in a **Search only** collection couldn't be made searchable; retry it when `retryable` is `true` |

### Choosing an agent's collections

Set the collections an agent uses with `knowledge_collection_ids` on `PATCH /v1/agents/{agent_id}`:

```bash
curl -X PATCH https://api.ojin.ai/v1/agents/$AGENT_ID \
  -H "X-API-Key: $OJIN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "knowledge_collection_ids": ["'"$COLLECTION_ID"'"] }'
```

* The list holds ids of your organization's collections, at most 45, with no id twice. An id that isn't your organization's answers `400`.
* It replaces the agent's whole list. An empty list means the agent uses no knowledge.
* Leave the field out to keep the list as it is.
* Reading the agent returns its current `knowledge_collection_ids`.

## Searching from your own LLM

If you run your own LLM, for example when you drive a face model through the [Python SDK](/models/build-with-python-sdk) or the [realtime API](/models/introduction/api), you can search your organization's knowledge and put the passages into your LLM's prompt before it answers.

```bash
curl -X POST https://api.ojin.ai/v1/knowledge/search \
  -H "X-API-Key: $OJIN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "query": "How long do customers have to return an item?", "max_results": 5 }'
```

```json
{
  "results": [
    {
      "item_id": "6f0c2a8e-0000-4000-8000-000000000001",
      "title": "Returns policy",
      "page": 2,
      "text": "Customers may return any item within 30 days of delivery…",
      "score": 0.71
    }
  ]
}
```

* `query` is 1 to 1,000 characters. `max_results` is 1 to 20, and 5 when left out.
* Results come most relevant first. `page` is set for PDF and Word files, and `null` otherwise. `score` is a relevance score: higher is more relevant.
* A search covers every collection of the organization, of both kinds. An item in a **Search only** collection is searchable once it shows **Ready**. Text in an **Always in the prompt** collection becomes searchable a little later, usually within minutes, with no status showing it. So keep the material your pipeline searches in **Search only** collections.
* No results is an empty `results` list, not an error.
* Searches are limited to about 60 a minute per organization, counting the dashboard's **Try a search** but not your agents' own searches. Past the limit, a search can answer `429`: wait and try again.
* A search usually takes about a second.


# Tools & Events

Let your Human Agent call functions during a conversation, and react to the agent from your own page.

## Tool Calling

Tools (function calling) let the agent's LLM trigger actions while it talks: look something up, submit a form, update your UI, or notify a backend system. You define each tool's name, description, and JSON-schema parameters; the LLM decides when to call it and with what arguments.

{% hint style="warning" %}
**Tools work only on Ojin's default speech pipeline.** An agent configured with a speech-to-speech provider (OpenAI Realtime, ElevenLabs Agents, Hume) runs a different worker that never dispatches tool calls. You can still save tools on such an agent, but they will never fire.
{% endhint %}

Tools are configured **per agent**. You can manage them two ways:

* In the [Ojin dashboard](https://ojin.ai/dashboard) when [configuring an agent](/apps/overview/configure), the agent's tools editor.
* Programmatically via the [REST API](#managing-tools-via-the-rest-api).

Each tool has an **enabled** flag. A disabled tool keeps its configuration but is hidden from the LLM, so you can turn a tool off without losing its setup.

Limits worth knowing before you design a tool:

* The agent executes at most **3 tool calls per model response**. Further calls in the same response are dropped, and the model is told to answer with speech instead.
* Identical calls (same tool, same arguments) inside one turn are collapsed to a single delivery, and so is an identical call to a webhook tool that waits for a response while the first is still running. A tool meant to be called repeatedly with the same arguments should vary an argument.
* `end_call` is reserved for the built-in hang-up tool. Do not use it as a custom tool name.
* `search_knowledge` is reserved for the built-in [knowledge](/apps/overview/knowledge) search. While the agent has searchable knowledge, a custom tool of that name is replaced by the built-in one.
* Only `properties` and `required` are read from your `parameters` object. Every other top-level JSON Schema keyword is accepted by the API and then dropped, including `type` (even `type: object`), `additionalProperties`, `$defs`, `oneOf`, `anyOf`, `allOf` and a top-level `description`. Express constraints inside each property rather than at the top level.

## Delivery Modes

Every tool declares how its calls are delivered. There is no agent-wide default. Each tool picks its own mode.

| Mode        | Where the call goes                                     | Your responsibility                        |
| ----------- | ------------------------------------------------------- | ------------------------------------------ |
| **Webhook** | Ojin POSTs the call to a URL you configure, server-side | Stand up the endpoint; no browser code     |
| **Client**  | The widget emits a DOM event in the user's browser      | Listen for the event on the embedding page |

Use **webhook** delivery for backend actions (write to a database, call an API, send a notification). Use **client** delivery for things that happen in the user's browser (navigate the page, open a modal, update on-page state).

## Webhook Delivery

When a webhook tool fires, Ojin sends an HTTP request to the tool's configured URL:

* Method `POST`, header `Content-Type: application/json`.
* A 30-second timeout.
* Redirects are not followed. Point the tool at the final URL: a `301` or `302` reaches the model as an error.
* The URL must be `http` or `https` and must resolve to a public address. Loopback and private addresses (`localhost`, `127.0.0.1`, `10.x`, `192.168.x`, `169.254.x`, `::1`) are rejected, and a tool with a rejected URL is dropped for that session. You cannot point a webhook at your laptop; use a tunnel with a public hostname.

The request body carries the call under a `tool_call_message` object. The fields you'll use:

```json
{
  "tool_call_message": {
    "name": "get_order_status",
    "parameters": "{\"order_id\":\"A123\"}",
    "tool_call_id": "call_abc",
    "response_required": true,
    "tool_type": "function"
  }
}
```

| Field               | Meaning                                                        |
| ------------------- | -------------------------------------------------------------- |
| `name`              | The tool that was called                                       |
| `parameters`        | The call arguments, as a **JSON string** (parse it before use) |
| `tool_call_id`      | Unique id for this call                                        |
| `response_required` | `true` when the agent is waiting for your response (see below) |

The body also includes additional session metadata fields alongside `tool_call_message`; you can ignore them for most integrations.

{% hint style="warning" %}
The webhook request is **not signed**. There is no secret header. Treat the webhook URL itself as a secret, serve it over HTTPS, and validate the payload before acting on it.
{% endhint %}

### Waiting for a response

Each webhook tool has a **wait for response** setting:

* **On** (`response_required: true`), the agent waits for your endpoint in the background, then feeds the result back into the conversation so the LLM can use it. While your endpoint works, the agent knows the call is still running and keeps talking with the user without calling the tool again. When the result arrives, the agent speaks about it, even if it had already said something or the user has spoken since. Return HTTP `2xx` with a JSON body:

  ```json
  { "result": "Your order shipped on Tuesday." }
  ```

  If you omit the `result` key, the entire JSON body is used as the result. An empty body (or `204`) is treated as an empty result. A non-`2xx` status, a timeout, or an unparseable body surfaces an error result to the LLM instead.
* **Off** (`response_required: false`), fire-and-forget. Ojin sends the request and does not wait; the LLM immediately continues with a neutral acknowledgement. Anything your endpoint returns is ignored.

{% hint style="info" %}
If your endpoint answers within a second or so, tell the agent in its system prompt not to say anything in the same reply as calling the tool. An announcement such as "let me check" followed at once by the answer sounds redundant, and in rare timings the agent may repeat itself or call the tool twice. For slower tools, a short announcement keeps the user informed while they wait.
{% endhint %}

## Client Delivery

When a client tool fires, the widget dispatches a DOM `CustomEvent` named `ojinToolCall`. The event fires on **`window`** (not on the `<ojin-agent>` element), so add the listener to `window`:

```js
window.addEventListener("ojinToolCall", (event) => {
  const { function_name, tool_call_id, arguments: args } = event.detail;
  // Run the browser-side action for `function_name` using `args`.
  // `args` is already an object, no parsing needed.
});
```

The `arguments` field is renamed to `args` above because `arguments` is a reserved word inside regular functions.

`event.detail` carries:

| Field           | Type     | Meaning                            |
| --------------- | -------- | ---------------------------------- |
| `function_name` | `string` | The tool that was called           |
| `tool_call_id`  | `string` | Unique id for this call            |
| `arguments`     | `object` | The call arguments, already parsed |

{% hint style="info" %}
Client delivery is **one-way**: the agent does not wait for your page, and there is no tool-result channel back from the browser. If the LLM needs to use a result, use **webhook** delivery with *wait for response* turned on. To feed information back for later turns, the widget exposes `appendSystemContext()`, which works on the default speech pipeline.
{% endhint %}

## Managing Tools via the REST API

Agent endpoints accept your API key, so you can manage tools programmatically. Authenticate with the `X-API-Key` header (see [Get your API key](/getting-started/authentication)).

Tools live on the agent itself. Set them with the agent update endpoint, `PATCH /v1/agents/{agent_id}`, using the `tools` array:

```bash
curl -X PATCH https://api.ojin.ai/v1/agents/$AGENT_ID \
  -H "X-API-Key: $OJIN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "tools": [
      {
        "enabled": true,
        "function": {
          "name": "open_pricing",
          "description": "Open the pricing page for the user.",
          "parameters": {
            "type": "object",
            "properties": { "plan": { "type": "string" } }
          }
        },
        "delivery": { "mode": "client" }
      },
      {
        "enabled": true,
        "function": {
          "name": "create_ticket",
          "description": "File a support ticket.",
          "parameters": {
            "type": "object",
            "properties": { "summary": { "type": "string" } }
          }
        },
        "delivery": {
          "mode": "webhook",
          "url": "https://example.com/hooks/ticket",
          "wait_for_response": true
        }
      }
    ]
  }'
```

{% hint style="warning" %}
The `tools` array is **full-replace**. Tools are matched by `function.name`: a name already on the agent is updated in place, a new name is created, and **any existing tool whose name is not in the array is deleted**. To change one tool, send the complete set. To leave tools untouched, omit `tools` from the request entirely.
{% endhint %}

To read an agent's current tools (each returned with its server-assigned `tool_id`), use `GET /v1/agents/{agent_id}`. For the full schema, see the [REST API](/getting-started/api) reference.

The API enforces these limits on each tool:

| Field                  | Constraint                                              |
| ---------------------- | ------------------------------------------------------- |
| `function.name`        | Max 64 characters, `^[a-zA-Z0-9_-]+$`, unique per agent |
| `function.description` | Max 1024 characters                                     |
| `delivery.url`         | Max 2048 characters, must be a valid URL                |

## Widget Events

Beyond `ojinToolCall`, the `<ojin-agent>` widget emits DOM events you can listen for to build custom UI, transcripts, or telemetry around the conversation.

All of them are observable on `window`, but they get there two different ways. `ojinToolCall`, `LatencyReport`, `ConnectionTimingReport` and `OjinSessionOutcome` are dispatched on `window` directly. The rest are dispatched on the `<ojin-agent>` element and bubble up to `window`.

### Conversation events

| Event                          | `detail`                                        | Fires when                                                                                                          |
| ------------------------------ | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| `ojinToolCall`                 | `{ function_name, tool_call_id, arguments }`    | A client-delivered tool is called (see above)                                                                       |
| `botIsSpeaking`                | `{ isSpeaking: boolean }`                       | The agent starts or stops speaking                                                                                  |
| `ReceivedTranscriptTurn`       | `{ owner: "user" \| "bot", text, final: true }` | One finished conversational turn. This is the event to use for a transcript: one clean, de-duplicated line per turn |
| `ReceivedTranscriptUser`       | `{ text, timestamp, user, final }`              | A user speech transcript arrives (`final: false` for interim)                                                       |
| `ReceivedTranscriptBot`        | `{ text }`                                      | A chunk of the agent's response text arrives. Raw deltas, not a finished line                                       |
| `ReceivedTranscriptBotPartial` | `{ owner: "bot", text, final: false }`          | The cumulative text produced by the speech service for the agent's current turn updates                             |
| `BotTtsStopped`                | *no payload (`detail` is `null`)*               | The agent's current spoken turn ends or is interrupted                                                              |
| `UserStartedSpeaking`          | `{ instanceId }`                                | The user starts speaking                                                                                            |
| `UserStoppedSpeaking`          | `{ instanceId }`                                | The user stops speaking                                                                                             |
| `ConnectionTimeout`            | `{ duration_s, bot_state, connection_state }`   | Connection setup exceeds its timeout; the widget resets and shows an error                                          |
| `UpdateBotState`               | `{ botState, instanceId }`                      | The agent's lifecycle state changes                                                                                 |
| `UpdateConnectionState`        | `{ connectionState }`                           | The transport connection state changes                                                                              |
| `UpdateQueuing`                | `{ queuing: boolean }`                          | The session enters or leaves the waiting queue                                                                      |

Where a payload includes `instanceId`, it identifies the `<ojin-agent>` element the event came from, so a page hosting several widgets can tell them apart.

```js
window.addEventListener("ReceivedTranscriptUser", (event) => {
  const { text, final } = event.detail;
  if (final) console.log("User said:", text);
});
```

### Advanced / telemetry events

These carry fine-grained audio and timing signals, useful for meters, latency dashboards, or debugging. They are more granular than the conversation events above and may change. Don't depend on them for core logic.

| Event                    | `detail`                                                                                                | Fires when                                             |
| ------------------------ | ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------ |
| `userSpeakingChanged`    | `{ isSpeaking: boolean }`                                                                               | Browser voice-activity detection toggles               |
| `userVolume`             | `{ volume: number }`                                                                                    | The user's microphone level is sampled                 |
| `botVolume`              | `{ volume: number }`                                                                                    | The agent's playback level is sampled                  |
| `LatencyReport`          | per-utterance latency breakdown                                                                         | The agent reports timing for a turn                    |
| `ConnectionTimingReport` | connection timing breakdown                                                                             | The session finishes connecting                        |
| `OjinSessionOutcome`     | `{ outcome, phase, faultDomain, sessionId, agentId, instanceId, httpStatus, elapsedMs, widgetVersion }` | A connection attempt or a live session ends. See below |

#### `OjinSessionOutcome`

Fires once when a connection attempt finishes and again when a live session ends, so you can measure how often visitors reach a conversation and why they don't. `phase` is `connect` or `session`; `outcome` is a value such as `success`, `mic_permission_denied`, `agent_unavailable`, `transport_lost` or `ended_by_visitor`. `faultDomain` coarsely attributes it, `client_env`, `ojin`, `backend`, or `unknown` when the outcome carries no attribution (every normal ending does).

`instanceId` identifies which `<ojin-agent>` element it came from, since the event fires on `window` and a page may host several. `sessionId` is present only once a session exists, a microphone refused before the session starts has none.

Treat the `outcome` vocabulary as open: new values are added as new failure modes are identified, so match on the ones you care about rather than assuming the list is closed.

## Next Steps

* [**Create & Configure**](/apps/overview/configure): set up the agent these tools belong to
* [**Widget Integration**](/apps/overview/widget-integration): embed the agent on your page
* [**REST API**](/getting-started/api): full schema for programmatic management


# Widget Integration

Embed a fully interactive Human Agent on your website with a single HTML tag.

## Quick Start

Load the widget bundle once, then drop the `<ojin-agent>` tag wherever you want it. No backend code is required: the widget calls Ojin directly.

{% tabs %}
{% tab title="Plain HTML" %}

```html
<!DOCTYPE html>
<html>
  <body>
    <script src="https://cdn.jsdelivr.net/npm/@ojin/agent@latest/dist/ojin-agent.js"></script>
    <ojin-agent
      agent-id="your-agent-id"
      core-api-endpoint="https://api.ojin.ai"
      style="position: fixed; bottom: 24px; right: 24px; width: 320px; height: auto; z-index: 9999;"
    ></ojin-agent>
  </body>
</html>
```

{% endtab %}

{% tab title="React / Next.js" %}
The widget is a web component, so it needs to mount on the client. It reads `window` at mount time, which is why the App Router example loads the script with `strategy="afterInteractive"` rather than during server rendering.

Declaring the element in `IntrinsicElements` is what stops TypeScript rejecting the tag.

```tsx
// app/layout.tsx (Next.js App Router)
import Script from "next/script";

declare module "react" {
  namespace JSX {
    interface IntrinsicElements {
      "ojin-agent": React.DetailedHTMLProps<
        React.HTMLAttributes<HTMLElement>,
        HTMLElement
      > & {
        "agent-id"?: string;
        "core-api-endpoint"?: string;
        collapsable?: string;
        "default-collapsed"?: string;
        "dynamic-variables"?: string;
        "enable-video"?: string;
        "preview-url"?: string;
      };
    }
  }
}

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body>
        {children}
        <Script
          src="https://cdn.jsdelivr.net/npm/@ojin/agent@latest/dist/ojin-agent.js"
          strategy="afterInteractive"
        />
        <ojin-agent
          agent-id="your-agent-id"
          core-api-endpoint="https://api.ojin.ai"
          style={{ position: "fixed", bottom: 24, right: 24, width: 320, height: "auto", zIndex: 9999 }}
        />
      </body>
    </html>
  );
}
```

**Vite** and **Create React App** have no `next/script`, so put the bundle in the HTML shell instead, then use the tag in any component. Vite uses the project-root `index.html`, Create React App uses `public/index.html`.

```html
<script src="https://cdn.jsdelivr.net/npm/@ojin/agent@latest/dist/ojin-agent.js"></script>
```

{% endtab %}

{% tab title="Vue" %}
Load the bundle once in `index.html`, then use the tag in any template.

```html
<!-- index.html: load the widget bundle once -->
<script src="https://cdn.jsdelivr.net/npm/@ojin/agent@latest/dist/ojin-agent.js"></script>
```

Vue 3's template compiler treats an unknown tag as a component, so tell it `ojin-agent` is a custom element. Without this you get a `Failed to resolve component: ojin-agent` warning:

```js
// vite.config.js
import vue from "@vitejs/plugin-vue";

export default {
  plugins: [
    vue({
      template: {
        compilerOptions: {
          isCustomElement: (tag) => tag.startsWith("ojin-"),
        },
      },
    }),
  ],
};
```

```vue
<!-- Any Vue component: drop the custom element into a template -->
<template>
  <ojin-agent
    agent-id="your-agent-id"
    core-api-endpoint="https://api.ojin.ai"
    style="position: fixed; bottom: 24px; right: 24px; width: 320px; height: auto; z-index: 9999;"
  />
</template>
```

{% endtab %}

{% tab title="REST + Daily" %}
Only reach for this if you are building your own UI. You give up everything the widget handles: the avatar layout, audio controls, captions, reconnection and session teardown.

Call [`POST /v1/public/agents/connect`](/apps/overview/api-reference) to get a Daily room and a token, then join the room yourself.

```ts
// Install: npm i @daily-co/daily-js
import DailyIframe from "@daily-co/daily-js";

const AGENT_ID = "your-agent-id";
const CONNECT_URL = "https://api.ojin.ai/v1/public/agents/connect";

async function startSession(clientUserRef?: string) {
  const res = await fetch(CONNECT_URL, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ agent_id: AGENT_ID, client_user_ref: clientUserRef }),
  });
  if (!res.ok) throw new Error(`connect failed: ${res.status}`);

  const { room_url, token } = await res.json();
  const call = DailyIframe.createCallObject();
  await call.join({ url: room_url, token });
  return call;
}
```

The response also carries `session_id` and `agent_id`. End the session with the cancel beacon described in the [Session API Reference](/apps/overview/api-reference).
{% endtab %}
{% endtabs %}

{% hint style="info" %}
The same script URL, `core-api-endpoint` and your agent id are in the embed snippet on your agent's settings page in the [dashboard](https://ojin.ai/dashboard). Copy that snippet rather than retyping the id.
{% endhint %}

## Embed Attributes

| Attribute           | Default              | Description                                                                                                                                                                                                         |
| ------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `agent-id`          | required             | The agent to connect to. Copy it from the agent settings page                                                                                                                                                       |
| `core-api-endpoint` | required             | `https://api.ojin.ai`                                                                                                                                                                                               |
| `enable-video`      | `true`               | Set `"false"` for an audio-only agent                                                                                                                                                                               |
| `collapsable`       | `true` when floating | Set `"false"` to pin the widget open. `widget-placement="inline"` is an alias for this                                                                                                                              |
| `default-collapsed` | `false`              | Set `"true"` to load collapsed. Only the value at mount matters; use `collapse()` and `expand()` afterwards                                                                                                         |
| `widget-placement`  | `floating`           | `inline` embeds the widget in the page flow instead of floating over it                                                                                                                                             |
| `dynamic-variables` | none                 | ElevenLabs agents only. A JSON object of per-chat values for your agent's `{{placeholders}}`, read each time a chat starts. See [Dynamic Variables for ElevenLabs Agents](#dynamic-variables-for-elevenlabs-agents) |

`preview-url` appears in the TypeScript declaration above because the widget *writes* it, exposing the resolved preview image. Do not set it yourself.

## Dynamic Variables for ElevenLabs Agents

If your agent is a [Third-Party Agent](/apps/overview/configure) on **ElevenLabs Agents**, its prompt, first message and tools can contain `{{placeholders}}`: ElevenLabs' [dynamic variables](https://elevenlabs.io/docs/agents-platform/customization/personalization/dynamic-variables). Fill them for each chat with the `dynamic-variables` attribute, a JSON object mapping each placeholder's name to its value. The name and format match ElevenLabs' own widget.

```html
<ojin-agent
  agent-id="your-agent-id"
  core-api-endpoint="https://api.ojin.ai"
  dynamic-variables='{"user_name": "Ada", "plan": "pro"}'
></ojin-agent>
```

The widget reads the attribute each time a chat starts, so you can set or change it any time before then. Pages that compute the values set it from JavaScript:

```js
document
  .querySelector("ojin-agent")
  .setAttribute("dynamic-variables", JSON.stringify({ user_name: "Ada", plan: "pro" }));
```

The element takes only attributes, so in React pass `dynamic-variables={JSON.stringify(values)}`, and in Vue bind `:dynamic-variables="JSON.stringify(values)"`.

Only ElevenLabs agents use the values for now. Other agents accept them and ignore them, so a page that sends values keeps working if you change the agent.

{% hint style="warning" %}
**Visitors can see and edit these values in their browser.** Use them to personalise the conversation, never to identify an account or grant access.
{% endhint %}

{% hint style="warning" %}
**Set a default value in ElevenLabs for every placeholder your agent uses.** ElevenLabs refuses a conversation that uses a placeholder with no default and no value, so without defaults a chat where the page sent no values, or values the widget had to drop, fails to start.
{% endhint %}

### Rules

* At most 32 variables.
* Names start with a letter and use only letters, digits and underscores, up to 64 characters. Names starting with `system__` are reserved for ElevenLabs' system variables, and `constructor` and `prototype` are reserved too.
* Values are text, numbers or `true`/`false`. Objects, arrays and `null` are not allowed.
* Text is at most 1000 characters, counted in UTF-16 code units (an emoji counts as two), and must not contain half of an emoji or other surrogate pair.
* The whole object is at most 4096 bytes as JSON, in UTF-8.
* Pass IDs as strings: JSON numbers above 2^53 lose precision in the browser.

If the attribute breaks a rule, the widget sends **none** of the values, starts the chat anyway, and logs the reason in the browser console as `[ojin-agent] dynamic-variables ignored: ...`. The reason names the rule and the variable, never a value.

Keep HTML and code out of the values. Ojin's firewall can block a chat start whose values look like markup; see [Troubleshooting](#no-chat-after-adding-dynamic-variables).

Ojin uses the values only to start that chat. They are not stored, not shown in the dashboard and not written to logs. What the agent says with them is conversation content like any other.

Custom integrations send the same object as the `dynamic_variables` field of [`POST /v1/public/agents/connect`](/apps/overview/api-reference#dynamic-variables).

## Appearance & Layout

The widget renders as a floating overlay on your page. It includes the avatar video feed, audio controls, and session management: all self-contained.

The agent owner can choose `off`, `conversation`, `tiktok`, `youtube`, `arthouse`, or `journalist` in the dashboard. They can also choose dark or light text, an accent colour, text size, and no background or a solid background. New agents start with captions off.

Caption settings come from the agent configuration. The embed has no caption attributes or viewer controls. Captions hide while the viewer opens the chat panel and return when it closes.

{% hint style="info" %}
Widget styling and positioning options are configured in your agent's settings in the [dashboard](https://ojin.ai/dashboard). Check your agent's widget configuration for available customization options.
{% endhint %}

## Finding Your Agent ID

After [creating and configuring your agent](/apps/overview/configure), copy the agent ID from the agent settings page in the [Ojin dashboard](https://ojin.ai/dashboard).

## Controlling Access

Agents are **private by default**: connections from any website are rejected until you configure access.

### Hostname Allowlist

In the [dashboard](https://ojin.ai/dashboard), add the domains that are allowed to connect to your agent:

| Configuration                    | Behaviour                                           |
| -------------------------------- | --------------------------------------------------- |
| No hostnames configured          | **Private**: all connections rejected               |
| `myapp.com`, `staging.myapp.com` | Only requests from those exact domains are accepted |
| `*`                              | **Public**: connections accepted from any domain    |

{% hint style="warning" %}
Using `*` (wildcard) allows anyone to connect to your agent. This is useful for demos but not recommended for production. Use specific hostnames to restrict access to your own domains.
{% endhint %}

{% hint style="info" %}
No API key is needed in the widget. Access is controlled entirely by the hostname allowlist: the server checks the request's origin against your configured domains.
{% endhint %}

## How It Works

When the widget loads on your page:

1. The widget calls the Session API (`POST /v1/public/agents/connect`) with your agent ID, plus any `dynamic-variables` values
2. The server validates the request origin against the hostname allowlist
3. On success, the server returns a WebRTC room URL and token
4. The widget connects to the WebRTC room directly
5. Audio, video, and signaling all flow over a single WebRTC connection

The entire handshake takes a few seconds. After that, your user is in a live conversation with the agent.

## Network Requirements

If your site sets a Content Security Policy, the widget needs these sources allowed. Blocking the widget script stops it loading at all; blocking anything else fails quietly, leaving the widget running with the affected capability gone. The "If blocked" column says which is which.

| Source                          | Directive              | Purpose                                                                                            | If blocked                                                      |
| ------------------------------- | ---------------------- | -------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
| `https://cdn.jsdelivr.net`      | `script-src`           | The widget bundle itself                                                                           | The widget does not load                                        |
| `https://api.ojin.ai`           | `connect-src`          | Session API: starting and monitoring a session                                                     | Sessions cannot start                                           |
| `https://*.daily.co`            | `connect-src`          | WebRTC signalling, and fetching the call engine the widget joins the room with                     | No audio or video                                               |
| `https://*.pluot.blue`, `wss:`  | `connect-src`          | Daily's media servers and their signalling sockets                                                 | No audio or video                                               |
| `'unsafe-eval'`, `blob:`        | `script-src`           | The call engine is fetched at runtime and evaluated in the page                                    | No audio or video                                               |
| `'self'`, `blob:`               | `worker-src`           | Daily runs noise cancellation in a worker started from a blob URL                                  | No audio or video                                               |
| `https://*.amazonaws.com`       | `media-src`, `img-src` | The agent's idle preview video and poster image: the Session API returns them as presigned S3 URLs | The idle preview is blank; sessions still work                  |
| `https://cdn.jsdelivr.net`      | `font-src`             | Caption fonts, loaded from beside the widget bundle when captions are on                           | Captions use each style's fallback fonts; everything else works |
| `data:`                         | `font-src`             | Bundled Geist (`@font-face` data URL in the shadow sheet)                                          | Chrome falls back to `sans-serif`                               |
| `'unsafe-inline'`               | `style-src`            | The widget's components inject their own styles at runtime                                         | The widget renders unstyled                                     |
| `https://*.ingest.us.sentry.io` | `connect-src`          | Error and reliability reporting                                                                    | Reporting stops; conversations are unaffected                   |

A policy that covers all of it:

```
default-src 'self';
script-src 'self' https://cdn.jsdelivr.net 'unsafe-eval' blob:;
style-src 'self' 'unsafe-inline';
font-src 'self' data: https://cdn.jsdelivr.net;
img-src 'self' data: blob: https://*.amazonaws.com;
media-src 'self' blob: https://*.amazonaws.com;
connect-src 'self' https://api.ojin.ai https://*.daily.co https://*.pluot.blue https://*.ingest.us.sentry.io wss:;
worker-src 'self' blob:;
frame-src 'self';
```

{% hint style="info" %}
`'unsafe-eval'` is needed because the WebRTC SDK downloads its call engine at connect time and evaluates it in the page. If your policy cannot allow it, get in touch: the SDK has a script-loading mode that trades `'unsafe-eval'` for `script-src https://*.daily.co`.
{% endhint %}

The widget also needs `microphone` permission via `Permissions-Policy` if you serve one, and WebRTC must not be disabled by a browser extension or corporate proxy.

Note the widget has always contacted a Sentry host: the WebRTC library it embeds reports its own errors there. Ojin's own reporting uses the same host.

### What the widget reports

The widget records how each connection attempt ended (succeeded, the microphone was refused, the agent was unavailable, the connection dropped) so we can find and fix problems that only appear on real devices.

It does **not** send conversation audio, video, transcripts, anything your user types, or your `dynamic-variables` values. The conversation itself is never recorded. It does not set cookies for this, and does not send an identifier that follows a visitor between sessions. What it sends is the outcome, a coarse attribution of where the fault lay, a coarse browser family (for example "Safari"), whether the page is inside an in-app browser, the microphone permission state, the HTTP status when the connect was rejected, the widget version, the avatar model variant that served the attempt, and, when an attempt timed out without reporting, how far it had got.

## Reacting to the Agent

The widget emits DOM events on `window` while a session runs (speaking state, live transcripts, and client-delivered tool calls) so your page can build custom UI or trigger actions. See [**Tools & Events**](/apps/overview/tools) for the full event reference and for handling function-calling tools.

## Custom Integrations

If you need more control than the widget provides, for example building a native mobile app or a custom web experience, you can call the Session API directly from your backend and connect to the WebRTC room yourself. The **REST + Daily** tab in [Quick Start](#quick-start) shows the browser version of this.

See the [Session API Reference](/apps/overview/api-reference) for details.

## Troubleshooting

### Widget not loading

* Use `https://cdn.jsdelivr.net/npm/@ojin/agent@latest/dist/ojin-agent.js`. Do not use `https://widget.ojin.ai/ojin-agent.js`: that host has no DNS record, so the script never loads and `<ojin-agent>` stays an empty tag.
* Confirm the `agent-id` attribute matches your agent's ID in the dashboard
* Set `core-api-endpoint` to the value in the dashboard snippet (`https://api.ojin.ai` in production)

### "agent\_offline" error

* Check that your agent is **published** in the [dashboard](https://ojin.ai/dashboard)
* Ensure all required fields are filled: the dashboard won't let you publish with missing configuration

### "auth\_failed" error

* Verify your domain is in the agent's hostname allowlist in the [dashboard](https://ojin.ai/dashboard)
* Check that the `Origin` header sent by the browser matches one of your configured hostnames exactly
* If testing locally, add `localhost` or `127.0.0.1` to the allowlist

### "concurrency\_limit" error

* Your agent's maximum concurrent sessions are in use. Wait for an active session to end or increase the **max concurrency** setting in the dashboard

### No audio or video

* Ensure the user's browser has granted microphone and camera permissions
* Check that the WebRTC connection is not blocked by a firewall or corporate proxy

### No chat after adding `dynamic-variables`

If the chat stopped starting once you added `dynamic-variables`, and the browser console shows a CORS error or `Failed to fetch`, Ojin's firewall has most likely blocked a value that looks like HTML or code. The widget then also logs `[ojin-agent] Chat start failed with a network or CORS error`. Remove markup from the values and try again.

### `dynamic-variables ignored` in the console

The attribute broke one of the [rules](#rules), so the widget sent none of the values. The message names the rule and the variable to fix.

### An ElevenLabs agent's chat fails to start

* Check that every `{{placeholder}}` the ElevenLabs agent uses has a default value in ElevenLabs. A placeholder with no default and no value makes ElevenLabs refuse the conversation.


# Session API Reference

Start agent sessions programmatically. The widget uses this API automatically, call it directly for custom integrations.

## Base URL

```
https://api.ojin.ai
```

The API is not regional, so there is no region to choose. Every path below already includes the `/v1` prefix, so append it to the base URL as written.

{% hint style="info" %}
**This is not the same endpoint as the one the "deploy in US East" guidance refers to.** They are two different things:

* **`api.ojin.ai` (this API)** is the agent control plane. You call it to start and cancel sessions. One global endpoint, no region in the hostname.
* **The models WebSocket** is where audio and video stream. If you drive the face models yourself with the [Python SDK](/models/build-with-python-sdk) or the [realtime API](/models/introduction/api), run **your own backend** in US East, close to Ojin's inference. See [Optimizing Performance](/guides/optimizing-performance).

If you only use the Human Agent widget or this Session API, the US East guidance does not apply to you.
{% endhint %}

## Start a Session

### `POST /v1/public/agents/connect`

Start a new session for a given agent. Returns connection details for joining the WebRTC room.

### Request

**Headers:**

| Header                 | Required                         | Description                                                                                                                                |
| ---------------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| `Content-Type`         | Yes                              | `application/json`                                                                                                                         |
| `Origin`               | Yes, unless the agent allows `*` | The browser sets this. It is checked against the agent's allowed hostnames (see [Authentication](#authentication))                         |
| `X-Session-Attempt-Id` | No                               | A client-generated id for this attempt. Lets the server correlate retries, and is what makes a `409 session_already_in_flight` recoverable |

**Body:**

```json
{
  "agent_id": "550e8400-e29b-41d4-a716-446655440000",
  "client_user_ref": "optional-user-identifier",
  "dynamic_variables": { "user_name": "Ada" }
}
```

| Field               | Type          | Required | Description                                                                                                                                                                                         |
| ------------------- | ------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `agent_id`          | string (UUID) | Yes      | The ID of the agent to start a session with. Must be a UUID: any other string is rejected with `400` before the agent is looked up                                                                  |
| `client_user_ref`   | string        | No       | An opaque identifier for your end user. Appears in call history for analytics and tracking. Max 255 characters.                                                                                     |
| `dynamic_variables` | object        | No       | ElevenLabs agents only: per-session values for the agent's `{{placeholders}}`. Other agents accept and ignore it. `null` is the same as leaving it out. See [Dynamic variables](#dynamic-variables) |

Unknown body properties are rejected, not ignored: sending a field that is not listed here returns `400`. The names inside `dynamic_variables` are yours to choose; they follow the rules below instead.

### Require transcript storage on preview sessions

The authenticated `POST /v1/agents/{agent_id}/preview-connect` route accepts `require_transcript`. Authenticate with a dashboard session or an organisation API key. Set the field to `true` when the resulting session must store transcript turns. If organisation storage is off or the agent's pipeline cannot produce a transcript, the route returns `409` with `code: TRANSCRIPT_STORAGE_OFF` before creating the session. The field defaults to `false`.

### Dynamic variables

`dynamic_variables` fills an [ElevenLabs Agents](/apps/overview/configure) agent's [dynamic variables](https://elevenlabs.io/docs/agents-platform/customization/personalization/dynamic-variables) for this session. It is the same object the widget sends from its [`dynamic-variables` attribute](/apps/overview/widget-integration#dynamic-variables-for-elevenlabs-agents).

* At most 32 entries. Names start with a letter and use only letters, digits and underscores, up to 64 characters. Names starting with `system__`, and `constructor` and `prototype`, are reserved.
* Values are strings, numbers or booleans. A string is at most 1000 UTF-16 code units and must not contain an unpaired surrogate.
* The object is at most 4096 bytes when serialised as JSON in UTF-8.
* Set a default value in ElevenLabs for every placeholder the agent uses. ElevenLabs refuses a conversation that uses a placeholder with no default and no value.
* Treat the values as untrusted: anyone who can call this endpoint can send any values. Use them to personalise the conversation, never to identify an account or grant access.

A value that breaks a rule rejects the whole request with `400`, and `message` names the rule and the variable, never the value.

The whole request body must stay under **8 KB as sent**. Some JSON libraries escape non-ASCII characters by default (Python's `json.dumps` does), and an escaped character counts at its escaped length. Ojin's firewall can also block a request whose values look like HTML or code; a browser reports that block as a CORS error with no status.

### Response (200 OK)

```json
{
  "session_id": "550e8400-e29b-41d4-a716-446655440000",
  "agent_id": "3f1c2d4e-5a6b-47c8-9d0e-1f2a3b4c5d6e",
  "room_url": "https://example.daily.co/room-name",
  "room_name": "room-name",
  "token": "eyJhbGciOiJIUzI1NiIs...",
  "provider": "daily",
  "transcript": { "stored": true }
}
```

| Field               | Type          | Description                                                                                       |
| ------------------- | ------------- | ------------------------------------------------------------------------------------------------- |
| `session_id`        | string        | Unique identifier for this session                                                                |
| `agent_id`          | string (UUID) | The agent this session belongs to                                                                 |
| `room_url`          | string        | On Daily, the full room URL. On LiveKit, the server URL, which does not contain the room          |
| `room_name`         | string        | The room to join. Pass this to the cancel endpoint. Required by LiveKit, and correct on Daily too |
| `token`             | string        | Authentication token for joining the room                                                         |
| `provider`          | string        | `daily` or `livekit`. Which transport these credentials are for                                   |
| `timings`           | object        | Diagnostic timings. Unstable, do not depend on the shape                                          |
| `transcript.stored` | boolean       | Whether this session will store transcript turns. Explicit deletion later sets this to `false`    |

Use `room_url` and `token` to connect to the WebRTC room from your client.

### Transcript storage

Transcript storage is configured per organisation with `GET /v1/organisations/{id}/transcript-settings` and `PATCH /v1/organisations/{id}/transcript-settings`. An organisation that has not saved settings uses storage off and a 30-day retention period. Turn storage on to store future sessions of Ojin-managed agents; it does not store third-party or speech-to-speech pipelines. Turning storage off stops new sessions from being stored but leaves existing transcripts until they expire. Retention can be set from 1 to 365 days after a session ends. These settings govern Ojin's transcript copy; Human+ may retain a separate copy under its own retention policy.

Dashboard sessions can read settings; an organisation admin or `org-global-admin` can update them. An API key for the organisation can read settings; only an administrator-granted `transcripts:manage` key can update them.

Set `require_transcript: true` in the authenticated preview-connect request when the application needs the resulting session to be stored. If storage is off or the agent's pipeline does not produce a transcript, connect returns `409` with `code: TRANSCRIPT_STORAGE_OFF` before creating the session. With the default `false`, connect succeeds and `transcript.stored` reports whether turns will be stored.

After connect, read session state without transcript words with `GET /v1/sessions/{session_id}`. Read the turns with `GET /v1/sessions/{session_id}/transcript`. An organisation API key needs the administrator-granted `transcripts:read` or `transcripts:manage` scope to read transcript words. `transcripts:manage` also allows deletion and changes to transcript settings. Dashboard reads and deletes require the organisation admin role or `org-global-admin`. To delete a transcript after the session ends, call `DELETE /v1/sessions/{session_id}/transcript`. Deletion keeps the session record, sets `transcript.stored` to `false`, and prevents late retries from restoring turns. This removes only Ojin's copy; it does not delete a separate copy Human+ may retain. Deletion while a session is active returns `409` with `code: SESSION_ACTIVE`.

{% hint style="warning" %}
**Branch on `provider`, do not assume Daily.** The transport is an organisation-level setting, so the same agent can return `daily` credentials today and `livekit` credentials after a settings change. Read `room_name` from the response rather than parsing it out of `room_url`: on LiveKit there is nothing to parse.
{% endhint %}

### Error Responses

**Branch on the HTTP status, not on a code string.** Most errors return the standard body below, where `message` is human-readable text and `error` is the HTTP reason phrase:

```json
{
  "statusCode": 404,
  "timestamp": "2026-09-08T09:12:34.567Z",
  "path": "/v1/public/agents/connect",
  "message": "Agent not found",
  "error": "Not Found"
}
```

A few cases carry a machine-readable slug under `error` instead of the reason phrase, plus extra fields:

```json
{
  "statusCode": 429,
  "error": "concurrency_limit",
  "message": "Agent has reached max concurrency (3)",
  "retry_after_seconds": 10
}
```

| HTTP Status | Meaning                                                                                                                                                                                         | Body notes                                                                                                                       |
| ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `400`       | Request validation failed: `agent_id` is not a UUID, `client_user_ref` is over 255 characters, `dynamic_variables` breaks a [rule](#dynamic-variables), or the body carries an unknown property | `message` is an array of strings, except for a `dynamic_variables` rule, where it is one string naming the rule and the variable |
| `402`       | The organisation is out of credits. Not retryable                                                                                                                                               | `error` is `insufficient_credits`                                                                                                |
| `403`       | Hostname allowlist check failed, or the agent is unpublished                                                                                                                                    | Standard body                                                                                                                    |
| `404`       | Agent id does not exist or is not visible to the caller                                                                                                                                         | Standard body                                                                                                                    |
| `409`       | A session for this caller is already being started. Recover with [Cancel by attempt](#cancel-a-session-by-attempt), then retry                                                                  | Carries `reason` (`session_already_in_flight`), `attempt_id` and `detail`                                                        |
| `422`       | The agent's **Always in the prompt** [knowledge](/apps/overview/knowledge#limits) is over what one session loads. Not retryable until the agent's collections hold less                         | Standard body                                                                                                                    |
| `429`       | The agent is at its concurrency limit                                                                                                                                                           | `error` is `concurrency_limit`, plus `retry_after_seconds`                                                                       |
| `500`       | Unexpected server error                                                                                                                                                                         | Standard body                                                                                                                    |
| `502`       | The room could not be created, or an upstream service returned an error                                                                                                                         | Standard body                                                                                                                    |
| `503`       | Starting the session timed out. Retryable                                                                                                                                                       | Carries `reason` and `detail`                                                                                                    |

A `429` can also be relayed from upstream rather than raised by the API, in which case it carries `reason` and `detail` instead of `error`. Always read `retry_after_seconds` when it is present rather than assuming a fixed delay.

On a `409` you have no `room_name` yet, because no room was allocated. Recover through the attempt-keyed endpoint instead: `POST /v1/public/agents/cancel` with the same `X-Session-Attempt-Id` you sent on the failed connect, wait for it to return, then retry the connect. The room-keyed endpoint below cannot help here, since it needs a room name you never received.

### Authentication

Currently, the public Session API uses **hostname allowlist** authentication. When a browser request arrives, the server checks the `Origin` header against the domains configured on the agent:

* The origin's hostname must match a configured entry **exactly**, ignoring case. There is no subdomain or wildcard-suffix matching, so `app.example.com` is rejected by an allowlist containing only `example.com`. List every subdomain you serve from
* If no hostnames are configured, all requests are rejected (agent is private)
* If `*` is configured, all origins are accepted
* A missing or malformed `Origin` header is rejected with `403`

No API key or token is needed from the client side when using hostname allowlist.

{% hint style="info" %}
Server-side calls without a browser `Origin` header only work for agents configured with `*` in their allowed hostnames. Production server-to-server authentication is planned separately.
{% endhint %}

## Cancel a Session by Room

### `POST /v1/public/agents/connect/{room}`

Cancel an active public session after a room has been allocated. This is mainly used by browser clients during unload, tab-hide, or abort cleanup.

`{room}` is the `room_name` returned by `POST /v1/public/agents/connect`. Do not derive it from `room_url`: that only ever worked on Daily, and on LiveKit `room_url` carries no room name.

A room name over 128 characters returns `400`. Omitting the segment entirely does not reach this endpoint at all: the path no longer matches a route, so you get the API's route-not-found response rather than a `400`.

### Cancel Response (200 OK)

```json
{
  "released": 1
}
```

| Field      | Type   | Description                                                                         |
| ---------- | ------ | ----------------------------------------------------------------------------------- |
| `released` | number | Number of active sessions released. `0` means the room was already gone or unknown. |

## Cancel a Session by Attempt

### `POST /v1/public/agents/cancel`

Release a session that is stuck mid-start, before any room was allocated. This is the recovery path for a `409 session_already_in_flight`.

| Header                 | Required | Description                                                                                |
| ---------------------- | -------- | ------------------------------------------------------------------------------------------ |
| `X-Session-Attempt-Id` | Yes      | The same attempt id you sent on the connect that returned `409`. Omitting it returns `400` |

There is no request body. The attempt id is a random per-client value, so this can only ever release your own stuck attempt, never another caller's session.

The response is the same shape as the room-keyed cancel:

```json
{
  "released": 1
}
```

Wait for it to return before retrying the connect.

## Examples

{% tabs %}
{% tab title="curl" %}

```bash
# Works only for wildcard/demo agents because curl does not attach a browser Origin.
curl -X POST https://api.ojin.ai/v1/public/agents/connect \
  -H "Content-Type: application/json" \
  -d '{"agent_id": "550e8400-e29b-41d4-a716-446655440000"}'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

# Works only for wildcard/demo agents because server-side HTTP clients do not
# attach a browser Origin.
response = requests.post(
    "https://api.ojin.ai/v1/public/agents/connect",
    json={"agent_id": "550e8400-e29b-41d4-a716-446655440000"}
)

data = response.json()
print(f"Session: {data['session_id']}")
print(f"Room: {data['room_url']}")
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const response = await fetch(
    "https://api.ojin.ai/v1/public/agents/connect",
    {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ agent_id: "550e8400-e29b-41d4-a716-446655440000" })
    }
);

const { session_id, room_url, room_name, token, provider } = await response.json();
```

Release the session when the user leaves the page:

```javascript
navigator.sendBeacon(
  `https://api.ojin.ai/v1/public/agents/connect/${encodeURIComponent(room_name)}`,
  ""
);
```

{% endtab %}
{% endtabs %}

## Connecting to the Room

The example below is for `provider: "daily"`. If the response says `livekit`, join with a LiveKit client instead, passing `room_url` as the server URL and `room_name` as the room.

After receiving the `room_url` and `token` from the Session API, connect to the WebRTC room using the [Daily JavaScript SDK](https://docs.daily.co/reference/daily-js):

```bash
npm install @daily-co/daily-js
```

```javascript
import DailyIframe from '@daily-co/daily-js';

// Create a call frame (attaches to DOM automatically)
const callFrame = DailyIframe.createFrame();

// Join the room with the token from the Session API
await callFrame.join({ url: room_url, token: token });

// The agent's audio and video tracks are now available
callFrame.on('track-started', (event) => {
    if (event.participant && !event.participant.local) {
        // Remote participant = the agent
        // event.track contains the audio or video MediaStreamTrack
    }
});
```

{% hint style="info" %}
This is only needed for custom integrations. If you're using the [widget](/apps/overview/widget-integration), it handles the room connection automatically.
{% endhint %}


# Introduction

Ojin offers two real-time face models. [**Human Portrait**](/models/human-portrait) and [**Human Presence**](/models/human-presence). Both turn speech audio into a synchronized talking-avatar video in real time, and both are driven the same way: pick the model with its `config_id` and the integration code is identical.

## Presence vs Portrait, which face model?

{% columns %}
{% column %}

<figure><img src="https://716616036-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FS2Pj5IbDX90dps067L35%2Fuploads%2Fgit-blob-f4d10a50059e93f330c4bda4bfa4b79749e21928%2Fcompare-presence.avif?alt=media" alt="" height="240" width="145"><figcaption><p><strong>Human Presence</strong>, expression and movement, including the hands.</p></figcaption></figure>
{% endcolumn %}

{% column %}

<figure><img src="https://716616036-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FS2Pj5IbDX90dps067L35%2Fuploads%2Fgit-blob-68672379c36e2a037ffcfffb6b68ad9c73d09a7a%2Fcompare-portrait.avif?alt=media" alt="" height="240" width="240"><figcaption><p><strong>Human Portrait</strong>, a focused talking face at the best price.</p></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

*Two personas, one rendered by each model. Presence moves through the whole frame; Portrait concentrates on the face.*

|          | **Human Presence**                                    | **Human Portrait**                     |
| -------- | ----------------------------------------------------- | -------------------------------------- |
| Quality  | Flagship, the most expressive and lifelike            | Great, focused on the talking face     |
| Motion   | Generative expressions **and** movement (incl. hands) | Lip-sync with facial expression        |
| Best for | When quality and expressiveness matter most           | A solid talking face at the best price |
| Cost     | Higher                                                | Lower                                  |

Both run in real time, and both are driven by the same [Python SDK](/models/build-with-python-sdk) and [Pipecat](/models/introduction/integrations) integration. You select the model with its `config_id`. To build, head to [**Get started**](/models/introduction/integrations).


# Get started

Build a real-time **Ojin** avatar in minutes, the same flow drives both [Human Portrait](/models/human-portrait) and [Human Presence](/models/human-presence). Pick the integration that fits your stack. We recommend the **Python SDK** or **Pipecat**. The raw WebSocket API is there when you need low-level control.

## Prerequisites

1. An Ojin account with an active API key, if you don't have one, [get your API key](/getting-started/authentication).
2. [Create a custom persona](/models/introduction/creating-persona) or use a [Persona Template](/models/introduction/using-persona-template).
3. A `config_id`, the **Model Config ID** shown on your configuration in the [dashboard](https://ojin.ai/dashboard).
4. Python 3.10 or newer (3.11 or newer for the Pipecat integration).

{% hint style="info" %}
**Choose your media transport:** WebSocket is the default and returns avatar frames to your backend. For browser playback, we recommend [direct LiveKit delivery](/models/build-with-python-sdk/python-sdk-webrtc) for smoother playback across varying network conditions. Ojin publishes avatar audio and video straight into your room, avoiding a backend media relay. Daily is also supported. Your backend still sends TTS audio and session commands over WebSocket and receives events there.

Run the Python SDK and Pipecat integration in a backend process to keep your API key secure. Direct WebRTC works with a local Python backend too. For production, host the backend in **US East**, near Ojin's inference, to reduce latency.
{% endhint %}

{% tabs %}
{% tab title="Python SDK" %}

### Python SDK

The [`ojin-client`](https://pypi.org/project/ojin-client/) SDK is the fastest way to drive Ojin from your own code. It streams a synchronized talking-avatar video from the TTS audio you feed it.

```bash
pip install "ojin-client[stv]"
```

```python
import os
from ojin.stv import OjinSTVClient

client = OjinSTVClient(
    api_key=os.environ["OJIN_API_KEY"],
    config_id=os.environ["OJIN_CONFIG_ID"],  # your Human Portrait or Human Presence config
)
# await client.start()  # opens the session; constructing the client does not connect
# Feed TTS audio with client.say(...), or start_turn() + send_tts_audio() to stream,
# and consume the synced 25 fps audio + video from client.output_stream().
```

**Viewers in a LiveKit or Daily room?** Pass `webrtc=WebRTCSettings(...)` and Ojin publishes the avatar straight into the room. See [Direct WebRTC (LiveKit & Daily)](/models/build-with-python-sdk/python-sdk-webrtc).

**Full walkthrough →** [**Build with the Python SDK**](/models/build-with-python-sdk)**.**
{% endtab %}

{% tab title="Pipecat" %}

### Pipecat

Drop an Ojin face into a [Pipecat](https://github.com/pipecat-ai/pipecat) voice agent with the [`pipecat-ojin`](https://pypi.org/project/pipecat-ojin/) package. `OjinVideoService` is the one stage that turns a voice agent into a video-call avatar. It sits right after your TTS and lip-syncs to it:

```mermaid
flowchart LR
    A["transport.input()"] --> B[STT] --> C[LLM] --> D[TTS]
    D --> E["OjinVideoService"]
    E --> F["transport.output()"]

    style E fill:#6366f1,stroke:#4338ca,color:#ffffff
```

`OjinVideoService` is the only stage you add. Everything upstream of it is your existing voice pipeline, unchanged.

Requires **Python 3.11+** (`pipecat-ai`'s floor); the SDK on its own needs only 3.10.

```bash
pip install pipecat-ojin
```

```python
import os

from pipecat_ojin import OjinVideoService, OjinVideoSettings

avatar = OjinVideoService(
    OjinVideoSettings(
        api_key=os.environ["OJIN_API_KEY"],
        config_id=os.environ["OJIN_CONFIG_ID"],   # your Human Portrait or Human Presence config
    )
)
```

The avatar's frame size comes from your model (`config_id`). Set the transport's `video_out_width` / `video_out_height` to match it.

#### How it works

1. The microphone captures speech input
2. Voice Activity Detection identifies speech segments
3. Your **STT** service transcribes user audio to text
4. Your **LLM** generates the assistant's reply
5. Your **TTS** service synthesizes the reply to audio
6. `OjinVideoService` animates your persona from that TTS audio
7. Synchronized video and audio frames stream back to the client in real time

**Using a LiveKit or Daily transport?** Set `webrtc=WebRTCSettings(...)` on `OjinVideoSettings` and Ojin publishes the avatar straight into the room; turn off the transport's `audio_out_enabled` and `video_out_enabled`. See [Direct WebRTC → Pipecat](/models/build-with-python-sdk/python-sdk-webrtc#pipecat).

A complete, runnable voice + avatar agent (browser WebRTC or Daily) lives in [`pipecat-ojin/examples/ojin-bot`](https://github.com/ojinai/pipecat-ojin/tree/main/examples/ojin-bot). You bring the STT / LLM / TTS services for the pipeline.
{% endtab %}

{% tab title="WebSocket (advanced)" %}

### WebSocket (advanced)

For low-level control, connect directly to the real-time WebSocket API and implement the binary protocol yourself. See the [API Reference (advanced) →](/models/introduction/api).
{% endtab %}
{% endtabs %}

## Next Steps

* [**Build with the Python SDK →**](/models/build-with-python-sdk): install, auth, events, and the full quickstart
* [**API Reference (advanced) →**](/models/introduction/api): the raw WebSocket protocol for custom integrations
* [**Search your knowledge →**](/apps/overview/knowledge#searching-from-your-own-llm): answer from your organization's documents in your own LLM


# API reference

{% hint style="info" %}
Most builders should use the [**Python SDK**](/models/build-with-python-sdk) or [**Pipecat**](/models/introduction/integrations). They implement this protocol, buffering, and audio/video sync for you. Read on only if you need low-level WebSocket control.
{% endhint %}

## Overview

Real-time talking head synthesis API. Send speech audio, receive synchronized video and audio frames.

After connecting and receiving `SessionReady`, the server immediately begins streaming video and audio frames at 25fps. It does not wait for you to send anything first. When no speech audio has been sent, the server generates **silence frames** (persona at rest with idle animation). When you send speech audio, the server generates **speech frames** with lip-synced animation synchronized to your audio.

Send your TTS audio as it arrives, including its natural quiet or silent pauses. No extra silent padding or keep-alive messages are required.

{% hint style="info" %}
**Production deployments:** WebSocket is the default and is intended for **server-to-server** use over a stable connection. Connect from a backend process to keep your API key secure. For browser playback, we recommend [direct WebRTC with LiveKit](/models/build-with-python-sdk/python-sdk-webrtc) to avoid a backend media relay and handle changing network conditions. Daily is also supported. Your backend still sends TTS audio and session commands over WebSocket and receives events and frame metadata there; avatar audio and video go directly to the room. This works with local or hosted backends. For production, host the backend in **US East**, close to Ojin's inference, to reduce latency.
{% endhint %}

***

## How It Works

1. **Connect** to the WebSocket endpoint with your API key and config ID
2. **Receive `SessionReady`**: the server has allocated inference resources for your session
3. **The server starts streaming frames immediately**: silence frames with idle animation, no request needed
4. **Send speech audio** whenever it becomes available, for example TTS output from your language model
5. **Receive speech frames**: the server transitions to lip-synced animation and returns to silence frames when audio runs out
6. **Render video frames** at 25fps, keeping a small jitter buffer (trim idle frames only if they back up after a stall)
7. **Play the audio payload that arrives with each frame** alongside that frame's image. The server returns them already aligned, so there is no audio clock to run

### Frame Types

Every frame arrives as a binary `InteractionResponse` containing both a JPEG image and a PCM audio chunk. Frames are always delivered in order. The `frame_type` field classifies each frame:

| `frame_type` | Description                                                                                                                                        |
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| `0`          | **Idle**, persona at rest with idle animation. Generated automatically when no speech audio is queued                                              |
| `1`          | **Speech**, animation generated from your audio input, including quiet pauses within the turn                                                      |
| `2`          | **Fade-out**, post-cancel ramp back toward idle after an interruption                                                                              |
| `3`          | **Start of speech**, first speech frame of a turn **resuming after an interruption/cancel**. Natural (uninterrupted) turns start with `1`, not `3` |

A speech frame can contain silent audio from your input. Its type does not indicate whether the samples are audible.

### Buffering for Network Jitter

The server delivers frames at **realtime 25 fps**, so your buffer does not grow on its own. Keep a **small client-side buffer** (a few frames) to absorb network jitter and prevent stuttering during speech, and start playback once it's filled.

The right buffer size depends on your network conditions and latency requirements: keep it as low as possible to minimize latency, but high enough to absorb jitter without starving playback.

If frames ever back up, for example a brief network stall followed by a burst of queued frames arriving at once. You can recover by trimming **idle** frames (`frame_type == 0`). Only idle frames are safe to drop, never drop speech (`1`), start-of-speech (`3`), or fade-out (`2`) frames.

```python
# When consuming frames from the buffer:
frame = buffer.popleft()

# If frames backed up after a stall, recover by skipping every other idle frame.
# Test the frame you are about to drop, not the one you just took: an idle
# frame is often followed by speech, and dropping that leaves a media gap.
if len(buffer) > target_buffer_size and buffer[0].frame_type == 0:
    skip_counter += 1
    if skip_counter % 2 == 0:
        buffer.popleft()  # drop one idle frame
```

***

## Connection Flow

```mermaid
sequenceDiagram
    participant Client
    participant Server

    Note over Client,Server: Connection
    Client->>Server: WebSocket Connect
    Server->>Client: SessionReady (JSON)

    Note over Client,Server: Server Streams Immediately
    Server->>Client: Frame (idle, frame_type=0)
    Server->>Client: Frame (idle, frame_type=0)
    Server->>Client: Frame (idle, frame_type=0)

    Note over Client,Server: Client Sends Speech Audio
    Client->>Server: InteractionInput (TTS audio chunk 1)
    Client->>Server: InteractionInput (TTS audio chunk 2)

    Note over Client,Server: Server Transitions to Speech
    Server->>Client: Frame (start-of-speech, frame_type=3)
    Server->>Client: Frame (speech, frame_type=1)
    Server->>Client: Frame (speech, frame_type=1)
    Note right of Server: Delivered at realtime 25 fps

    Note over Client,Server: Audio Runs Out → Back to Idle
    Server->>Client: Frame (idle, frame_type=0)
    Server->>Client: Frame (idle, frame_type=0)
    Note right of Client: Client keeps a small jitter buffer
```

### Direct WebRTC

If you requested direct WebRTC in the [handshake](#websocket-handshake), the flow is the same with three differences:

1. **Check the outcome in `SessionReady`.** `payload.parameters.webrtc` reports whether the avatar joined your room:

   | `webrtc` value                                                                        | Meaning                                                                  |
   | ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
   | `{"version": 2, "status": "connected", "provider": "daily", "participant_id": "..."}` | The avatar is in the room and publishes its audio and video there        |
   | `{"status": "failed", "error": {"code": "AUTH", "message": "..."}}`                   | The room join failed. `code` is `AUTH`, `NETWORK`, or `INVALID_SETTINGS` |
   | key absent                                                                            | This session doesn't support direct WebRTC                               |
2. **Send audio at your declared rate.** Once connected, send `InteractionInput` audio as mono int16 PCM at `webrtc_audio_sample_rate`, not 16 kHz.
3. **Frames carry metadata only.** Every `InteractionResponse` keeps the same header, including the trailing frame type, but has no image or audio payload. Use them for speaking state and timing; the media is in the room.

After connecting, the server may send a [`WebrtcStatus`](#webrtcstatus-server-client-json) message if the avatar loses the room.

***

## WebSocket Handshake

```
GET wss://models.ojin.ai/realtime?config_id=<your-config-id>
Authorization: <your-api-key>
```

Provide your API key in the `Authorization` header and the persona's `config_id` as a query parameter. The server upgrades the connection, sends `SessionReady`, and begins streaming frames immediately.

| Parameter                  | In     | Required | Description                                                                                           |
| -------------------------- | ------ | -------- | ----------------------------------------------------------------------------------------------------- |
| `Authorization`            | header | yes      | Your raw API key. No `Bearer` prefix                                                                  |
| `config_id`                | query  | yes      | Configuration ID for the persona. Create one in the dashboard, under Human Presence or Human Portrait |
| `webrtc_version`           | query  | no       | Direct WebRTC only. Always `2`                                                                        |
| `webrtc_provider`          | query  | no       | Direct WebRTC only. `livekit` or `daily`                                                              |
| `webrtc_room_url`          | query  | no       | Direct WebRTC only. URL-encoded LiveKit server URL (`wss://…`) or Daily room URL                      |
| `webrtc_audio_sample_rate` | query  | no       | Direct WebRTC only. Sample rate of the audio you send, e.g. `24000` (8000 to 48000, divisible by 25)  |
| `X-Ojin-Webrtc-Token`      | header | no       | Direct WebRTC only. The room token for the avatar participant. Send it as a header, never in the URL  |

{% hint style="info" %}
**Direct WebRTC.** Add the `webrtc_*` parameters and the `X-Ojin-Webrtc-Token` header to have Ojin publish the avatar straight into your LiveKit or Daily room instead of streaming media over this WebSocket. See [Direct WebRTC](#direct-webrtc) below. Using the Python SDK? Pass `webrtc=` instead; see [Direct WebRTC (LiveKit & Daily)](/models/build-with-python-sdk/python-sdk-webrtc).
{% endhint %}

| Status | Meaning                                                                                                              |
| ------ | -------------------------------------------------------------------------------------------------------------------- |
| `101`  | Upgrade successful. The server sends a `SessionReady` JSON message, then streams binary `InteractionResponse` frames |
| `403`  | No API key was supplied, or `config_id` is missing. The body is empty                                                |

An **invalid** key does not fail the handshake. The upgrade succeeds with `101`, and the rejection arrives on the open socket as an `errorResponse` with code `AUTH_FAILED`, followed by close code `1008`. Handle authentication failures on the message stream, not on the HTTP status.

Recommended client settings: `ping_interval` 30 seconds, `ping_timeout` 10 seconds.

***

## Message Format

{% hint style="info" %}
**Mixed message types:** Both JSON (text) and binary messages are exchanged on the same WebSocket connection. Your client must check the WebSocket frame type to distinguish them:

* **Text frames (JSON):** `SessionPing`, `SessionReady`, `ErrorResponse`, `WebrtcStatus` (server → client), `CancelInteraction` (client → server)
* **Binary frames:** `InteractionResponse` (server → client), `InteractionInput` (client → server)
  {% endhint %}

{% hint style="info" %}
**Byte order:** All multi-byte integer fields in binary messages use **network byte order (big-endian)**.
{% endhint %}

***

## Messages Reference

### Server → Client Messages

| Message                                                            | Frame  | Description                                                                                                                                    |
| ------------------------------------------------------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| `SessionPing`                                                      | JSON   | Sent at least every 10 s while the session is still starting, before `SessionReady`. Says which startup phase the server is in. Safe to ignore |
| `SessionReady`                                                     | JSON   | Sent once after the connection is established and inference resources are allocated. The server begins streaming frames immediately afterwards |
| [`InteractionResponse`](#interactionresponse-server-client-binary) | binary | A video frame and its synchronized audio chunk. Streamed continuously: idle frames when at rest, speech frames when processing your audio      |
| [`ErrorResponse`](#errorresponse-server-client-json)               | JSON   | Sent when an error occurs. In some conditions, such as no backend server being available, the connection may close without one                 |
| [`WebrtcStatus`](#webrtcstatus-server-client-json)                 | JSON   | Direct WebRTC only. Sent when the avatar's room connection changes after `SessionReady`                                                        |

### Client → Server Messages

| Message                                                      | Frame  | Description                                                                                                                                                       |
| ------------------------------------------------------------ | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`InteractionInput`](#interactioninput-client-server-binary) | binary | Your source audio, including its natural pauses. No extra silent padding is required                                                                              |
| [`CancelInteraction`](#cancelinteraction)                    | JSON   | Abort the current turn. Queued speech frames are discarded, then the server sends a `2` fade-out frame and continues streaming idle frames. Use for interruptions |

Field-level layouts for the binary messages are in [Message Details](#message-details) below.

***

## Message Details

### InteractionInput (Client → Server, Binary)

Binary message for sending your source audio to the server. Include natural pauses in your TTS audio, even when the PCM samples are all zero. The server generates idle frames when it has no source audio to process, so no extra silent padding is required.

**Binary structure:**

```
[1 byte ]  Payload type       : uint8, always 1 for audio
[8 bytes]  Timestamp           : uint64, milliseconds since Unix epoch
[4 bytes]  Params size         : uint32, byte length of the JSON params block (0 if no params)
[N bytes]  Params JSON         : UTF-8 encoded JSON (only present if params size > 0)
[M bytes]  Audio payload       : raw PCM int16 speech audio data
```

**Header fields** use **big-endian** byte order. The PCM audio samples in the payload use **little-endian** (standard for PCM int16). In Python: `struct.pack('!BQI', payload_type, timestamp, params_size)`.

**Audio requirements:**

All-zero payloads are accepted and counted as input audio. Presence with steady small chunks preserves quiet source audio from the start of a turn, without an extra frame holdback. Other serving modes may trim a short, bounded quiet prefix. Quiet source audio within a turn retains its duration and speech-frame classification. All-zero input does not start the time-to-first-audible-frame measurement.

| Property         | Value                                                                                                                                                                                                                                                       |
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Format           | PCM signed 16-bit integers (little-endian samples)                                                                                                                                                                                                          |
| Sample rate      | 16,000 Hz                                                                                                                                                                                                                                                   |
| Channels         | 1 (mono)                                                                                                                                                                                                                                                    |
| Max message size | 512 KB (entire binary message including header). Do not rely on a particular failure mode for an oversized message: depending on where it is rejected you may get a `FRAME_SIZE_EXCEEDED` error or the connection may close without one. Stay under the cap |

**Recommended streaming pattern:**

The minimum initial audio is **320 ms for Presence or 200 ms for Portrait**. Smaller messages are accepted.

1. **Start each turn with 500 ms for Presence or 400 ms for Portrait**, then stream the rest as it arrives.
2. Then send the **largest chunks you can**, coalesce queued fragments into **\~400 ms** sends (under the 512 KB cap).
3. Stay realtime: never wait for the whole utterance before sending.

{% hint style="success" %}
The [**Python SDK**](/models/build-with-python-sdk) and [**Pipecat**](/models/introduction/integrations) shape the input for you. `OjinSTVClient` batches your TTS audio automatically, so you just feed audio as it arrives. This pattern only applies if you drive this WebSocket API directly. See [Optimizing Performance](/guides/optimizing-performance).
{% endhint %}

```python
import struct, json, time

def build_audio_message(audio_bytes):
    header = struct.pack('!BQI',
        1,                         # payload type: audio
        int(time.time() * 1000),   # timestamp ms
        0,                         # params size (no per-chunk params are read today)
    )
    return header + audio_bytes
```

***

### InteractionResponse (Server → Client, Binary)

Binary message containing a video frame and synchronized audio. The server streams these continuously after `SessionReady`. **Frames always arrive in order.**

**Binary structure:**

```
[1 byte  ]  Is final flag      : uint8, always 0 on the realtime stream; reserved
[16 bytes]  Interaction ID      : UUID bytes (big-endian)
[8 bytes ]  Timestamp           : uint64, milliseconds since Unix epoch
[4 bytes ]  Usage               : uint32, usage metric for this response
[4 bytes ]  Index               : uint32, legacy frame classifier, superseded by the trailing frame-type byte; ignore
[4 bytes ]  Num payloads        : uint32, number of payload entries that follow

For each payload entry:
  [4 bytes]  Data size           : uint32, byte length of the payload data only
  [1 byte ]  Payload type        : uint8, 1 = audio, 2 = image
  [N bytes]  Payload data        : raw payload bytes

[1 byte ]  Frame type          : uint8, appended after all payload entries: 0=idle, 1=speech, 2=fade-out, 3=start-of-speech
```

All multi-byte integers are **big-endian**. In Python: `struct.unpack('!B16sQIII', header_bytes)` for the main header, `struct.unpack('!IB', entry_bytes)` for each payload entry. The `Frame type` byte is a single trailing `uint8` after the last payload entry and is the authoritative frame classifier.

Do not use `is_final` as a turn or interaction boundary: the server sends `0` on every frame.

There is no definitive end-of-turn marker on the wire either. An idle frame (`0`) tells you the persona is currently at rest, not that the turn is over: a server that has run short of audio mid-utterance emits idle frames and then resumes speech. Treat idle as a state, and if you track turns, wait out a run of idle frames rather than ending the turn on the first one. A fade-out frame (`2`) is specific: it acknowledges a `CancelInteraction` you sent.

**Frame type:**

| Frame type | Meaning                                                                                                                |
| ---------- | ---------------------------------------------------------------------------------------------------------------------- |
| `0`        | **Idle**, persona at rest with idle animation                                                                          |
| `1`        | **Speech**, animation from your audio, including quiet pauses within the turn                                          |
| `2`        | **Fade-out**, post-cancel ramp toward idle                                                                             |
| `3`        | **Start of speech**, first speech frame of a turn resuming after an interruption/cancel (natural turns start with `1`) |

**Payload types:**

| Type      | Format                | Typical size per frame                                                                                                                      |
| --------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| 1 (audio) | PCM int16, 16kHz mono | **1,280 bytes** (640 samples = 40ms at 25fps)                                                                                               |
| 2 (image) | JPEG-encoded image    | Square, and fixed for the life of a session. Human Portrait delivers 1024x1024. Read the size off the first frame rather than hardcoding it |

**Parsing example:**

```python
import struct, uuid

HEADER_FMT = '!B16sQIII'
HEADER_SIZE = struct.calcsize(HEADER_FMT)   # 37 bytes
ENTRY_FMT = '!IB'
ENTRY_SIZE = struct.calcsize(ENTRY_FMT)     # 5 bytes

def parse_response(data):
    # The 5th header field is the legacy index; ignore it.
    is_final, uuid_bytes, timestamp, usage, _index, num_payloads = \
        struct.unpack(HEADER_FMT, data[:HEADER_SIZE])

    offset = HEADER_SIZE
    image = audio = None

    for _ in range(num_payloads):
        size, ptype = struct.unpack(ENTRY_FMT, data[offset:offset + ENTRY_SIZE])
        offset += ENTRY_SIZE
        payload = data[offset:offset + size]
        offset += size

        if ptype == 2:
            image = payload   # JPEG bytes
        elif ptype == 1:
            audio = payload   # PCM int16 bytes

    # Trailing frame type byte, appended after the payload entries.
    frame_type = data[offset]

    return {
        'is_final': bool(is_final),
        'frame_type': frame_type,    # 0=idle, 1=speech, 2=fade-out, 3=start-of-speech
        'image': image,
        'audio': audio,
    }
```

***

### CancelInteraction

Sent as a **text frame**:

```json
{"type": "cancelInteraction", "payload": {"timestamp": 1723567892000}}
```

| Message             | Purpose                | Server behavior                                                                                                                                                                                                       | Use case          |
| ------------------- | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- |
| `CancelInteraction` | Abort the current turn | Discards queued and in-flight speech frames. **The stream does not stop**: the server keeps delivering at 25 fps, sends one `frame_type` `2` (fade-out) frame to acknowledge the cut, then returns to `0` idle frames | User interruption |

A second `CancelInteraction` sent before any new audio has been accepted is ignored, so it cannot restart the fade. Wait for the acknowledging `2` frame before treating the cut as done.

***

### SessionPing (Server → Client, JSON)

While a session is starting, the server sends a `SessionPing` at least every 10 s (normally every 5 s) until `SessionReady` or an `ErrorResponse`. A cold start can take longer than 30 s; the pings say the server is still working on it and that its own deadlines bound the wait, so a client can watch for silence rather than guess a total.

```json
{
  "type": "sessionPing",
  "payload": {
    "phase": "waiting_for_container",
    "elapsed_ms": 12400,
    "timestamp": 1723567893000
  }
}
```

| Field        | Description                                                                                                                                                           |
| ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `phase`      | `waiting_for_container` while inference capacity is being started, then `setting_up_session` while the model loads the persona and, for direct WebRTC, joins the room |
| `elapsed_ms` | Milliseconds since the server started working on the session                                                                                                          |
| `timestamp`  | Server time in milliseconds since the Unix epoch                                                                                                                      |

Older servers may send the message without a `payload`. No `SessionPing` arrives after `SessionReady`. A client that wants a startup limit should fail on **silence** (no `SessionPing` for 20 s, twice the longest interval) rather than on a total: the server reports a stalled start itself, as `BACKEND_UNAVAILABLE` when no inference capacity came up within its limit (while `phase` was `waiting_for_container`) or `TIMEOUT` when the session setup hung after that (`setting_up_session`).

### ErrorResponse (Server → Client, JSON)

{% hint style="warning" %}
**Plain text errors:** In some error conditions (e.g., no backend servers available), the server may send a plain text message instead of a structured JSON `ErrorResponse`. Your client should handle non-JSON text messages gracefully.
{% endhint %}

**Error codes:**

| Code                  | Description                                                                                                         |
| --------------------- | ------------------------------------------------------------------------------------------------------------------- |
| `AUTH_FAILED`         | Invalid API key                                                                                                     |
| `UNAUTHORIZED`        | Caller lacks permission                                                                                             |
| `MISSING_CONFIG_ID`   | `config_id` query parameter not provided                                                                            |
| `INVALID_MESSAGE`     | Malformed or unsupported message payload                                                                            |
| `INVALID_HEADERS`     | Missing or invalid headers                                                                                          |
| `MODEL_NOT_FOUND`     | Config ID not found or invalid                                                                                      |
| `BACKEND_UNAVAILABLE` | No healthy inference backend available                                                                              |
| `RATE_LIMITED`        | Too many requests                                                                                                   |
| `TIMEOUT`             | Operation exceeded processing time, including a session that did not become ready within the server's startup limit |
| `CANCELLED`           | Interaction cancelled by client                                                                                     |
| `INTERNAL_ERROR`      | Unexpected server error                                                                                             |
| `FRAME_SIZE_EXCEEDED` | Message exceeded 512KB limit                                                                                        |

***

### WebrtcStatus (Server → Client, JSON)

Direct WebRTC only. Sent after `SessionReady` when the avatar loses your room:

```json
{
  "type": "webrtcStatus",
  "payload": {
    "status": "failed",
    "provider": "daily",
    "error": {"code": "REJOIN_FAILED", "message": "..."}
  }
}
```

| `status`       | Meaning                                                                                                                                |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| `disconnected` | The avatar dropped out of the room and Ojin is trying to rejoin. Treat it as a warning                                                 |
| `failed`       | The rejoin failed (`error.code` is `REJOIN_FAILED`). The avatar is no longer in the room; close the connection and start a new session |

Ignore `status` values you don't recognize.

***

## Rate Limits & Constraints

| Constraint       | Value                      |
| ---------------- | -------------------------- |
| Rate limit       | 6 requests per second      |
| Max message size | 512 KB per message         |
| Video output     | 25 fps (realtime delivery) |

Exceeding limits results in an `ErrorResponse` with code `RATE_LIMITED`.

***

## Best Practices

### Audio Input

* **Send your TTS audio with its natural pauses.** The server starts streaming idle frames on its own, so there is no handshake frame to send first and no need to add silent padding between utterances
* **Start with 500 ms of audio for Presence or 400 ms for Portrait**, then send the largest chunks you can (\~400 ms). The minimum initial audio is 320 ms for Presence or 200 ms for Portrait. See the **InteractionInput** message details above and [Optimizing Performance](/guides/optimizing-performance).
* The [Python SDK](/models/build-with-python-sdk) and [Pipecat](/models/introduction/integrations) handle this input shaping for you. This only matters when driving the WebSocket API directly.

### Buffer Management

* Play frames at **25 fps** (40ms per frame)
* **Play each frame's audio payload with that frame's image.** The server returns them aligned, so you do not need an audio master clock
* The server delivers at realtime 25 fps. Keep a **small jitter buffer** (a few frames); it won't grow on its own
* **Recovery:** if frames back up after a network stall, drop a frame only when both the frame you just presented and the frame you are about to drop are idle (`frame_type == 0`), and stop as soon as the backlog clears. That keeps every drop inside an idle stretch; trimming across a transition into speech leaves a visible gap
* **When recovering from jitter, only idle (`0`) frames are safe to drop.** Never drop speech (`1`), start-of-speech (`3`), or fade-out (`2`) frames. Clearing the buffer on a deliberate interruption is the exception, see [Interruption Handling](#interruption-handling)
* Tune your target buffer size based on your network conditions. Keep it as low as possible for minimal latency

### Audio and Video Synchronization

Each `InteractionResponse` carries a JPEG image and the audio for that same frame, 40 ms of PCM, and frames always arrive in order at realtime 25 fps. The server aligns the two for you. You do not need an audio master clock, and you do not need to gate playback on `frame_type`:

1. **Render each frame's image and play that frame's audio payload together**, in arrival order
2. Keep a **small jitter buffer** (a few frames) to absorb network jitter
3. **Render video from every frame**, whatever its `frame_type`

Speech frames carry back your own 16 kHz audio, sliced per frame. It round-trips through the model's float format, so individual samples can differ by one least-significant bit. That is inaudible, but it is not a bit-exact copy of your bytes. Idle and fade-out frames carry silence. Playing every frame's audio keeps the mouth and the voice locked together with no gating logic.

Playback may pause or include silence if audio delivery stalls. Use the recommended initial amount and keep subsequent audio flowing. See [Troubleshooting](/guides/troubleshooting).

```python
# When TTS audio arrives from your speech service:
await ojin.send_audio(tts_audio_chunk)            # send to Ojin for lip-sync

# In your playback loop, present what arrived together:
frame = buffer.popleft()
render_video(frame.image)                         # always render the video
play_audio(frame.audio)                           # the matching 40 ms of audio
```

If you play your own copy of the TTS audio instead, you take the alignment back from the server: the voice is never interrupted, but nothing keeps the mouth on it. In that case you buffer your TTS locally, start playback on the first speech frame (`frame_type` `1` or `3`), and keep it running at a steady rate. Stop it when your own audio source ends, not on the first idle frame: an idle frame only means the persona is at rest right now, and one can appear mid-utterance when the server runs short, so stopping there cuts off speech that is still coming. A fade-out frame (`2`) is different: it acknowledges a `CancelInteraction` you sent, so it is a real stop signal.

### Error Handling

* Handle both JSON `ErrorResponse` messages and plain text error strings
* Implement exponential backoff for reconnection
* Monitor server `load` in the `SessionReady` message

### Interruption Handling

* Stop old-turn audio sends and use `CancelInteraction` when the user interrupts. Wait for the acknowledging `2` frame before sending the next turn's audio.
* Then pick a strategy for what you have already buffered:
  * **Instant cut:** drop everything buffered and resume rendering from the next frame that arrives. Lowest latency, and the pose can visibly jump.
  * **Smooth:** stop audio playback immediately but keep rendering the frames you hold, including the `2` fade-out frame the server sends. The avatar eases back to idle instead of snapping, at the cost of a few frames of latency.
* This is the one case where dropping non-idle frames is intended. The never-drop rule under Buffer Management applies to jitter recovery, not to a deliberate barge-in.

***

## Complete Example

```python
import asyncio
import json
import struct
import time
from collections import deque
import numpy as np
import websockets
from dotenv import load_dotenv
import os

load_dotenv()

API_KEY = os.getenv("OJIN_API_KEY", "")
CONFIG_ID = os.getenv("OJIN_CONFIG_ID", "")
URL = f"wss://models.ojin.ai/realtime?config_id={CONFIG_ID}"

SAMPLE_RATE = 16000
FPS = 25
TARGET_BUFFER = 10  # Tune based on your network conditions

def build_audio_message(audio_bytes):
    """Build a binary InteractionInput message."""
    header = struct.pack('!BQI', 1, int(time.time() * 1000), 0)
    return header + audio_bytes

def parse_response(data):
    """Parse a binary InteractionResponse message."""
    fmt = '!B16sQIII'
    hdr_size = struct.calcsize(fmt)
    # The 5th header field is reserved; ignore it.
    is_final, uid_bytes, ts, usage, _index, n_payloads = struct.unpack(fmt, data[:hdr_size])

    offset = hdr_size
    image = audio = None
    for _ in range(n_payloads):
        size, ptype = struct.unpack('!IB', data[offset:offset+5])
        offset += 5
        if ptype == 2:
            image = data[offset:offset+size]
        elif ptype == 1:
            audio = data[offset:offset+size]
        offset += size

    # Trailing frame type byte, appended after the payload entries.
    frame_type = data[offset]

    return {
        'is_final': bool(is_final),
        'frame_type': frame_type,    # 0=idle, 1=speech, 2=fade-out, 3=start-of-speech
        'image': image,
        'audio': audio,
    }

async def main():
    headers = {"Authorization": API_KEY}
    # For older websockets versions, use extra_headers instead.
    async with websockets.connect(URL, additional_headers=headers, ping_interval=30) as ws:
        # 1. Wait for SessionReady; the server starts streaming frames immediately after
        msg = json.loads(await ws.recv())
        assert msg["type"] == "sessionReady"
        print(f"Session ready: {msg['payload']}")

        buffer = deque()
        skip_counter = 0
        playback_started = False
        frame_count = 0
        audio_sent = False

        # 2. Receive and process frames. The server streams idle frames
        #    immediately after SessionReady; nothing needs to be sent first.
        async for data in ws:
            if isinstance(data, str):
                msg = json.loads(data)
                if msg.get("type") == "errorResponse":
                    print(f"Error: {msg['payload']}")
                    break
                continue

            frame = parse_response(data)
            buffer.append(frame)
            frame_count += 1

            # Wait for initial buffer before playback
            if not playback_started:
                if len(buffer) >= TARGET_BUFFER:
                    playback_started = True
                    print(f"Buffer filled ({TARGET_BUFFER} frames), starting playback")
                continue

            # Consume one frame
            if buffer:
                play_frame = buffer.popleft()

                # Drop excess idle frames when the buffer is too large. This example
                # consumes one frame per arrival, so a backlog never builds here; the branch
                # matters once you drain on a 40 ms timer instead.
                # Only idle (frame_type 0) is safe to drop; keep speech (1),
                # start-of-speech (3), and fade-out (2). Both the frame just
                # presented and the one about to be dropped must be idle, so the
                # drop always happens inside an idle stretch and never across a
                # transition into speech, which would leave a visible gap.
                if (len(buffer) > TARGET_BUFFER
                        and play_frame['frame_type'] == 0
                        and buffer[0]['frame_type'] == 0):
                    skip_counter += 1
                    if skip_counter % 2 == 0:
                        buffer.popleft()  # drop one idle frame

                kind = {0: "idle", 1: "speech", 2: "fade-out", 3: "start-of-speech"}.get(
                    play_frame['frame_type'], "?"
                )
                print(f"[{kind}] frame #{frame_count}, buffer={len(buffer)}")

                # In a real app: render play_frame['image'] and play play_frame['audio']

            # Demo: send test audio after receiving some silence frames
            if frame_count == 50 and not audio_sent:
                # Synthetic one-shot test buffer, not the recommended live pattern:
                # with real TTS, send audio as it arrives.
                duration_ms = 500  # Presence; use 400 for Portrait
                samples = SAMPLE_RATE * duration_ms // 1000
                t = np.arange(samples) / SAMPLE_RATE
                audio_data = (32767 * 0.5 * np.sin(2 * np.pi * 440 * t)).astype(np.int16)
                await ws.send(build_audio_message(audio_data.tobytes()))
                audio_sent = True
                print(f"Sent {duration_ms} ms of test audio")

            if frame_count > 200:
                break

asyncio.run(main())
```

***

## Troubleshooting

Symptoms, causes, and fixes, connection and auth, a starved/idle mouth, choppy playback, latency, and frame lag, live in the global [Troubleshooting guide](/guides/troubleshooting), where each entry is tagged 🟢 SDK-handled or 🟠 your setup.

***

## Example Implementation

A complete working Python example integrating Ojin Human Portrait with a speech-to-speech service (Hume EVI) is available here:

[**github.com/journee-live/speech-to-video-samples/tree/main/samples**](https://github.com/journee-live/speech-to-video-samples/tree/main/samples) (includes Hume STS → Human Portrait walkthroughs)

The repository demonstrates the full integration pattern: microphone capture → STS service → TTS audio → Ojin lip-sync → synchronized video and audio playback at 25fps. It includes the buffer management and frame handling approach described in [Best Practices](#best-practices) above.

***


# Using a Persona Template

Learn how to create a persona out of a template to get started ASAP with your application. Templates work for both [Human Portrait](/models/human-portrait) and [Human Presence](/models/human-presence).

## Prerequisites

* An Ojin account with an active API key

## Creating a Persona through the Dashboard

The simplest way to create a persona is through the Ojin Dashboard:

1. Log in to the [Ojin Dashboard](https://ojin.ai)
2. Navigate to the [**Human Portrait**](https://ojin.ai/models/ojin/human-portrait) or [**Human Presence**](https://ojin.ai/models/ojin/human-presence) section
3. Navigate to the **Configs** sub-section
4. Select a persona template and press **Copy Template**
5. Open the newly created model configuration and save the **Model Config ID** parameter which will be used by your application
6. You can now integrate it through the [model API endpoints](/models/introduction/api)

## Next Steps

Once your persona is ready, you can:

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Integration Guide</strong></td><td>Integrate your persona using Pipecat or the WebSocket API.</td><td><a href="/models/introduction/integrations">Get started</a></td></tr><tr><td><strong>API Reference</strong></td><td>Explore the complete API documentation.</td><td><a href="/models/introduction/api">API reference</a></td></tr></tbody></table>


# Creating a custom persona

Create a persona by uploading a reference image when you add a configuration in the [Ojin Dashboard](https://ojin.ai/dashboard). The flow is the same for both face models.

## Creating a configuration through the Dashboard

1. Log in to the [Ojin Dashboard](https://ojin.ai/dashboard)
2. Select your model: [**Human Portrait**](/models/human-portrait) or [**Human Presence**](/models/human-presence)
3. Navigate to the **Configs** sub-section
4. Press **New Configuration** to create a new configuration
5. Fill in the required fields and upload a reference image; follow your model's reference-image best practices for the best result
6. Click **Create Configuration**
7. Open your new configuration and copy the **Model Config ID** for your application

{% hint style="info" %}
Reference-image guidance is specific to each model. See **Best practices** for [Human Portrait](/models/human-portrait/best-practices) or [Human Presence](/models/human-presence/best-practices).
{% endhint %}

## Next Steps

* [**Get started**](/models/introduction/integrations): integrate with the Python SDK, Pipecat, or WebSocket
* [**API Reference (advanced)**](/models/introduction/api): the raw WebSocket protocol


# Human Portrait

A cost-effective, lifelike persona model that transforms reference images into natural animated personas

## Overview

The ojin/human-portrait model creates realistic, expressive digital humans from a single reference image. It excels at producing natural facial animations, lip-syncing, and emotional expressions that bring your persona to life with synchronized speech, at the best price for a real-time talking face.

{% columns %}
{% column %}

<figure><img src="https://716616036-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FS2Pj5IbDX90dps067L35%2Fuploads%2Fgit-blob-2ae32dfb9ddc926c15020421a86166ba00117d5c%2Fportrait-1.avif?alt=media" alt="" height="200" width="200"><figcaption><p><strong>Hana</strong>, virtual assistant</p></figcaption></figure>
{% endcolumn %}

{% column %}

<figure><img src="https://716616036-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FS2Pj5IbDX90dps067L35%2Fuploads%2Fgit-blob-33872aadb188484db50cc3930f288a48cc45440a%2Fportrait-2.avif?alt=media" alt="" height="200" width="200"><figcaption><p><strong>Marcus</strong>, tutor</p></figcaption></figure>
{% endcolumn %}

{% column %}

<figure><img src="https://716616036-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FS2Pj5IbDX90dps067L35%2Fuploads%2Fgit-blob-d5ee948594ce4eea402a8441ef1145184229714d%2Fportrait-3.avif?alt=media" alt="" height="200" width="200"><figcaption><p><strong>Asha</strong>, health assistant</p></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

*One model, any persona. Each generated from a single reference image.*

Want the most expressive, lifelike result? [Human Presence](/models/human-presence) is our flagship face model, with generative expressions and natural movement. Both models are driven the same way. See [Build with the Python SDK](/models/build-with-python-sdk).

## Key Features

* **Full persona look control** - Generate a persona based on any image reference, the persona will behave exactly the same
* **No training required** - You don't need to wait for your persona to be ready, as soon as the reference image is uploaded, you can start using it
* **Natural Lip-Syncing** - Precise lip movements synchronized with speech audio
* **Expressive delivery** - facial expression follows the speech audio. There are no selectable emotion states on this model
* **Real-Time** - Streams synchronized audio and video at a fixed 25 fps, for live conversation
* **Square 1024x1024 output** - fixed 1:1 aspect, constant for the life of a session

## Quick Start

Getting started with ojin/human-portrait is simple:

1. [**Create an API key**](/getting-started/authentication) - Set up authentication for the Ojin platform
2. [**Use a persona template**](/models/introduction/using-persona-template) - Use a persona template to generate your persona in seconds
3. [**Integrate with your application**](/models/introduction/integrations) - Recommended: the [Python SDK](/models/build-with-python-sdk) or Pipecat

## Use Cases

* **Virtual Assistants** - Create responsive customer service personas
* **Educational Content** - Develop engaging tutors and instructors
* **Entertainment** - Produce animated characters for games and media
* **Presentations** - Transform static slides into dynamic video presentations
* **Healthcare** - Build empathetic virtual health assistants


# Best practices

Follow the guidance below for the best results. Your reference image is the foundation of the persona, so a clean, well-framed image gives the most natural output.

## Reference image best practices

* **Image content**:
  * Mouth should be closed, but smiles or subtle expressions are fine
  * The eyes should be looking directly into the camera
  * Keep the expression balanced, the image is used as the base for both the idle loop and speech, so avoid extreme poses
* **Format**: JPEG, PNG, or WebP
* **Lighting**: Even lighting with no harsh shadows
* **Aspect**: the reference is centre-cropped to a 1:1 square, so supply a square image and keep the subject centred. Anything outside the centre square is cut off
* **Face Position**: The face should be clearly visible and centered
* **Background**: Simple backgrounds work best
* **Accessories**: Avoid sunglasses or items that obscure facial features


# Human Presence

Our flagship face model, a fully expressive, generative presence that goes beyond lip-sync.

## Overview

**Human Presence** is Ojin's highest-quality real-time face model. It generates a fully expressive *presence*, rich facial expressions and natural movement, including the hands, for the most lifelike, dynamic result.

{% columns %}
{% column %}

<figure><img src="https://716616036-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FS2Pj5IbDX90dps067L35%2Fuploads%2Fgit-blob-873165daaba663308e4e1d6b69fdb605769b01c2%2Fpresence-1.avif?alt=media" alt="" height="248" width="150"><figcaption><p><strong>Seraphina</strong>, game character</p></figcaption></figure>
{% endcolumn %}

{% column %}

<figure><img src="https://716616036-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FS2Pj5IbDX90dps067L35%2Fuploads%2Fgit-blob-4cdd9899fcd5acf6569aa17ce5da057a21691142%2Fpresence-2.avif?alt=media" alt="" height="248" width="150"><figcaption><p><strong>Mathieu</strong>, chef</p></figcaption></figure>
{% endcolumn %}

{% column %}

<figure><img src="https://716616036-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FS2Pj5IbDX90dps067L35%2Fuploads%2Fgit-blob-c0fdc09a0d27f92d3ac82c250be2e062ede76d2f%2Fpresence-3.avif?alt=media" alt="" height="248" width="150"><figcaption><p><strong>Dr. Robert</strong>, clinician</p></figcaption></figure>
{% endcolumn %}

{% column %}

<figure><img src="https://716616036-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FS2Pj5IbDX90dps067L35%2Fuploads%2Fgit-blob-59714cc208b91adb81980aca2f72ca0e24e575f2%2Fpresence-4.avif?alt=media" alt="" height="248" width="150"><figcaption><p><strong>Olivia</strong>, brand spokesperson</p></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

*Generative expression and movement (including the hands) across four personas, photoreal and stylised alike.*

Feed it speech audio and it streams back a synchronized talking-avatar video in real time. Pick the model with its `config_id`. New here? See the [Introduction](/models/introduction) to compare Ojin's face models and choose the right one.

## Key features

* **Fully expressive presence**: generative facial expressions and natural movement, beyond lip-sync
* **Real-time**: conversation-ready, streamed as synchronized audio + video
* **One config, any integration**: drive it from the Python SDK, Pipecat, or the raw WebSocket API
* **Model slug**: `ojin/human-presence`

## Quick Start

The fastest way to build with Presence is the **Python SDK** or **Pipecat**:

1. [**Create an API key**](/getting-started/authentication): set up authentication for the Ojin platform
2. **Get a Human Presence `config_id`** from the [dashboard](https://ojin.ai/dashboard). See [Best practices](/models/human-presence/best-practices) for reference-image guidance
3. [**Integrate with your application**](/models/introduction/integrations): recommended: Python SDK or Pipecat

## Use Cases

* **Brand & spokesperson**: a premium, lifelike presence that represents your brand
* **High-touch support & sales**: expressive agents for moments that matter
* **Education & training**: engaging tutors with natural expression and movement
* **Interactive experiences**: installations, kiosks, and showcases that feel alive


# Best practices

Follow the guidance below for the best results. The higher the quality and the more detail your reference image has, the richer and more lifelike the generated video.

## Reference image best practices

* **Resolution**: Use a **768 × 1280** reference image for the best results.
* **Framing**: A **medium shot** (more of the body and hands in frame, best for rich, expressive motion) through to a **close-up** (best for fine facial detail) is the recommended range for this model. Choose where you sit in that range depending on whether you want more motion or more detail.
* **Avoid full-body shots**: At full-body distance the face and hands become too small and the result loses detail, stay within the medium-shot-to-close-up range.
* **Hands and body**: Show the hands in a passive, resting state and the body in a relaxed, resting position. The model generates natural body and hand movement from there.
* **Backgrounds can animate**: A good, detailed background can come to life too. You are not limited to a plain backdrop. Try to avoid other visible faces close to your persona's face.
* **Keep the face clearly visible**: A clearly visible, reasonably centered face is the main guideline; beyond that you have freedom over styling, pose, and background.
* **Format**: JPEG, PNG, or WebP.


# Python SDK

Drive Ojin's face models (Human Presence and Human Portrait) straight from Python. Feed in your TTS audio; get back a synchronized, lip-synced talking-avatar stream.

The [`ojin-client`](https://pypi.org/project/ojin-client/) SDK is the fastest way to add a real-time talking avatar to a Python app or voice agent. You bring the words (any TTS); the SDK streams back a face that speaks them (perfectly in sync) handling buffering, the playback clock, resampling, and barge-in for you.

{% hint style="info" %}
**Just want a complete agent?** If you'd rather not assemble a pipeline, the [Human Agent](/apps/overview) gives you a full speech-in, speech-out avatar with a single line of embed code. Already on [Pipecat](https://github.com/pipecat-ai/pipecat)? Jump to the [Pipecat integration](/models/introduction/integrations).
{% endhint %}

## Requirements

* **Python 3.10+**
* An **Ojin API key**, [get yours here](/getting-started/authentication)
* A face-model **config ID**, a Presence or Portrait configuration from your [dashboard](https://ojin.ai/dashboard)

New accounts start with **200 free credits**.

## Install

With [uv](https://docs.astral.sh/uv/) (recommended):

```bash
uv add "ojin-client[stv]"
```

Or with pip:

```bash
pip install "ojin-client[stv]"
```

The `[stv]` extra pulls in the speech-to-video helpers (`numpy`, `opencv-python-headless`, `soxr`) that handle resampling, decoding, and the sync math for you.

## Authenticate

The client needs your API key and a configuration ID. Keep both out of source. Read them from the environment:

```bash
export OJIN_API_KEY="…"      # from your Ojin account
export OJIN_CONFIG_ID="…"    # a Presence or Portrait configuration to drive
```

```python
import os
from ojin.stv import OjinSTVClient

client = OjinSTVClient(
    api_key=os.environ["OJIN_API_KEY"],
    config_id=os.environ["OJIN_CONFIG_ID"],
)
```

Or let the SDK load and validate them for you. `resolve_credentials()` reads an optional `.env` file and raises a clear error if either value is missing:

```python
from ojin import resolve_credentials
from ojin.stv import OjinSTVClient

creds = resolve_credentials()  # reads OJIN_API_KEY + OJIN_CONFIG_ID
client = OjinSTVClient(api_key=creds.api_key, config_id=creds.config_id)
```

By default the client connects to `wss://models.ojin.ai/realtime`.

{% hint style="warning" %}
Never hardcode your API key in source or commit it to version control.
{% endhint %}

## Pick your model

The SDK is **identical for both face models**; the `config_id` you pass selects which one runs.

| A `config_id` from…         | You get                                                                                   | Choose it when                                  |
| --------------------------- | ----------------------------------------------------------------------------------------- | ----------------------------------------------- |
| a **Human Presence** config | the flagship, fully expressive generative presence, rich expressions and natural movement | quality and expressiveness matter most          |
| a **Human Portrait** config | a cost-effective, real-time lip-synced talking face                                       | you want a great talking face at the best price |

Create configurations in the [dashboard](https://ojin.ai/dashboard). The code below is the same either way; only the `config_id` changes.

## Two clients, one package

|             | `OjinSTVClient` (high-level)                               | `OjinClient` (low-level)                  |
| ----------- | ---------------------------------------------------------- | ----------------------------------------- |
| Import      | `from ojin.stv import OjinSTVClient`                       | `from ojin.ojin_client import OjinClient` |
| You give it | TTS audio at **any** sample rate                           | 16 kHz mono `int16` PCM                   |
| You get     | synced `STVAudioFrame` + `STVVideoFrame` on a 25 fps clock | raw protocol messages (JPEG + PCM)        |
| It handles  | buffering, playback clock, resampling, barge-in re-sync    | just the WebSocket + wire protocol        |

Most applications want **`OjinSTVClient`**. Reach for `OjinClient` only when you're writing your own playback/sync layer.

**Choose how the avatar reaches your viewers.** WebSocket remains the default: `OjinSTVClient` streams frames back to your process, as in the quickstart below. For smoother, more stable browser playback, we recommend direct LiveKit delivery. It avoids relaying avatar media through your backend and uses WebRTC to handle network jitter and packet loss. This applies whether your Python backend runs locally or on a hosted server. Pass `webrtc=WebRTCSettings(...)` to publish into your room; Daily is also supported. See [Direct WebRTC (LiveKit & Daily)](/models/build-with-python-sdk/python-sdk-webrtc).

## Quickstart

Feed the avatar one utterance of TTS audio and consume the synchronized stream it speaks back.

```python
import asyncio
import os
import wave

from ojin.stv import OjinSTVClient, STVEvent, STVAudioFrame, STVVideoFrame


async def main() -> None:
    ready = asyncio.Event()
    done = asyncio.Event()

    async with OjinSTVClient(
        api_key=os.environ["OJIN_API_KEY"],
        config_id=os.environ["OJIN_CONFIG_ID"],
    ) as client:
        # Events may be sync or async; register with a decorator or add_listener().
        client.add_listener(STVEvent.SESSION_READY, lambda **_: ready.set())
        client.add_listener(STVEvent.BOT_STOPPED_SPEAKING, lambda **_: done.set())

        @client.on(STVEvent.ERROR)
        def _on_error(message: str, **_):
            print("ojin error:", message)

        # Wait until the avatar session is live (race-free: skip if already up).
        if not client.is_connected:
            await ready.wait()

        # Send one utterance of mono int16 PCM TTS audio at ANY sample rate:
        # the SDK resamples the copy it sends to the server for lip-sync.
        with wave.open("hello.wav", "rb") as wav:  # a mono WAV
            await client.say(
                wav.readframes(wav.getnframes()),
                sample_rate=wav.getframerate(),
                num_channels=1,
            )

        # Consume the synchronized 25 fps audio + video stream.
        async def consume() -> None:
            async for frame in client.output_stream():
                if isinstance(frame, STVVideoFrame) and frame.rgb is not None:
                    ...  # frame.rgb = width*height*3 RGB bytes, render it
                elif isinstance(frame, STVAudioFrame):
                    ...  # frame.pcm = int16 PCM @ frame.sample_rate, play it

        consumer = asyncio.create_task(consume())
        await done.wait()           # the avatar finished the turn
        await asyncio.sleep(0.5)    # let the tail frames drain
        consumer.cancel()


asyncio.run(main())
```

`say()` is a one-shot helper for `start_turn()` + `send_tts_audio()`. For a **live agent**, call `start_turn()` once per utterance and stream chunks with `send_tts_audio()` as your TTS produces them, the user hears the exact audio you sent, lip-synced to the avatar.

{% hint style="success" %}
**The SDK shapes the input for you.** Feed audio at whatever cadence your TTS produces, even tiny 40 ms fragments. `OjinSTVClient` batches the audio automatically; you do not need to collect several seconds before sending it. A pause in your TTS or network can still interrupt playback. It also paces `output_stream()` to realtime 25 fps with audio and video already in sync. You don't manage input buffering, the playback clock, or frame-dropping yourself. See [Optimizing Performance](/guides/optimizing-performance) for the recommended initial audio amounts and how to tune them.
{% endhint %}

## Events you'll use

Register handlers with `@client.on(STVEvent.X)` or `client.add_listener(STVEvent.X, cb)`. Handlers may be sync or async; a failing handler never breaks the playback loop.

| Event                  | Fires when                                                                                                |
| ---------------------- | --------------------------------------------------------------------------------------------------------- |
| `SESSION_READY`        | the session is live and ready for audio                                                                   |
| `FIRST_FRAME`          | the first avatar frame is out (`frame_type`)                                                              |
| `WEBRTC_CONNECTED`     | direct WebRTC only: the avatar has joined your room (`participant_id`)                                    |
| `BOT_STARTED_SPEAKING` | the first speech frame of a turn is played                                                                |
| `BOT_STOPPED_SPEAKING` | a turn has finished playing                                                                               |
| `INTERRUPTED`          | `interrupt()` took effect (check its return value to know whether a server-side cancel was actually sent) |
| `ERROR`                | a transport or server error occurred                                                                      |
| `CLOSED`               | the session has been torn down                                                                            |

## Where to go next

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Runnable examples</strong></td><td>Realtime streaming and render-to-MP4, ready to clone.</td><td><a href="https://github.com/ojinai/python-sdk/tree/main/examples">https://github.com/ojinai/python-sdk/tree/main/examples</a></td></tr><tr><td><strong>Build a voice agent</strong></td><td>Drop the avatar into a Pipecat pipeline.</td><td><a href="/models/introduction/integrations">Get started</a></td></tr><tr><td><strong>Direct WebRTC</strong></td><td>Publish the avatar straight into your LiveKit or Daily room.</td><td><a href="/models/build-with-python-sdk/python-sdk-webrtc">Direct WebRTC (LiveKit &amp; Daily)</a></td></tr></tbody></table>

* **Best practices**: [working-pipeline patterns](/models/build-with-python-sdk/python-sdk-best-practices) for browser output, WebRTC backends, and direct WebRTC
* **Choose a face model**: [Human Presence](/models/human-presence) (flagship) or [Human Portrait](/models/human-portrait) (cost-effective)
* **Tune latency & stability**: [Optimizing Performance](/guides/optimizing-performance) and the [Troubleshooting guide](/guides/troubleshooting)
* **Full API surface**: the complete client reference lives in the [`ojin-client` README](https://github.com/ojinai/python-sdk) and on [PyPI](https://pypi.org/project/ojin-client/)
* **Starter examples**: `02-realtime-speech-to-video` (live streaming) and `01-speech-to-video-mp4-generator` (render to file)


# Best Practices

The key things to get right for a smooth, low-latency avatar pipeline with OjinSTVClient, whether you're prototyping straight to a browser, relaying media over WebRTC, or publishing directly into a Li

## Essentials (every setup)

* **Run it server-side.** The SDK connects to Ojin over a **server-to-server** WebSocket. Run it in a backend process, including a local Python process during development, and keep your API key out of browser code and distributed client apps. In production, run it in **US East**, close to Ojin's inference, to reduce latency.
* **Feed audio as your TTS produces it.** Call `start_turn()` once per utterance, then `send_tts_audio()` for each chunk as it arrives, even tiny 40 ms fragments. The SDK handles batching. Don't collect several seconds or the whole utterance yourself. See [Optimizing Performance](/guides/optimizing-performance) for the recommended initial audio amounts and tuning.
* **For WebSocket output, present frames as they arrive. Don't re-sync.** `output_stream()` is already paced to realtime **25 fps**, with audio and video in sync and a small jitter buffer. Forward each frame the moment it arrives; never hold audio to wait for a video frame, and don't add your own A/V sync layer.
* **Handle the lifecycle.** Wait for `SESSION_READY` before relying on the stream; use `BOT_STARTED_SPEAKING` / `BOT_STOPPED_SPEAKING` for UI state; on `ERROR`, retry with backoff (e.g. `NO_BACKEND_SERVER_AVAILABLE`).
* **Barge-in with `interrupt()`.** Stop the current TTS producer and call `interrupt()` when the user starts talking. Call `start_turn()` before feeding the next utterance.

{% hint style="info" %}
On [Pipecat](/models/introduction/integrations)? `pipecat-ojin`'s `OjinVideoService` already wires all of this into a pipeline and pushes frames into your transport, start there instead of hand-rolling the loop.
{% endhint %}

## Setup A. Local, output to a browser (prototyping)

WebSocket is the default. For a simple local prototype, run the SDK in a local Python process and forward frames to a browser you control over a WebSocket to a `<canvas>`. For browser demos and production calls where playback performance and stability matter, we recommend direct LiveKit delivery in **Setup C**, even when Python runs locally.

* **Forward the JPEG straight to the browser.** Keep the default decoder and read the raw JPEG from `STVVideoFrame.source_bytes`, then draw it to a `<canvas>`/`<img>` as it arrives. It is **empty (`b""`) on a held tick** (the tick where no new server frame was ready), so skip those and keep showing the last image. Do **not** use a `PassthroughDecoder` to skip the decode: it makes the client emit no video frames at all, so the loop below never runs. (Need raw RGB in Python instead? The default decoder gives you `frame.rgb` as well.)
* **Play audio at the rate you fed.** Run the browser `AudioContext` at the rate you pass to `send_tts_audio()`. `STVAudioFrame.sample_rate` reports it per frame, but frames emitted before your first TTS audio default to 16 kHz. Don't configure the context from the first frame you see. You can feed higher-quality TTS (for example, 24 kHz) for better sound; the SDK plays back your original audio while lip-sync uses a 16 kHz copy.
* **Present as they come.** Draw each video frame and queue each audio chunk the instant it arrives, no re-sync; the stream is already aligned.

```python
client = OjinSTVClient(
    api_key=..., config_id=...,
)
async for frame in client.output_stream():
    if isinstance(frame, STVVideoFrame):
        if frame.source_bytes:                         # empty on a held tick
            await ws.send_bytes(frame.source_bytes)    # raw JPEG -> draw on a canvas
    elif isinstance(frame, STVAudioFrame):
        await ws.send_bytes(frame.pcm)                 # play at frame.sample_rate
```

## Setup B. Backend, relay to a WebRTC service (production)

Run the SDK on a backend and relay the media to your users over a **WebRTC** service (LiveKit, Daily, mediasoup, …), which absorbs packet loss, jitter, and varying networks that a raw WebSocket can't.

{% hint style="info" %}
**On LiveKit or Daily?** Use **Setup C** below: Ojin publishes the avatar straight into your room, avoiding the backend relay hop. Use Setup B when you need the frames in your process or use another WebRTC service.
{% endhint %}

* **Deploy in US East**, close to Ojin's inference.
* **Push frames into the transport with their `pts`.** Each `STVAudioFrame` / `STVVideoFrame` carries a `pts` timestamp in **monotonic nanoseconds**, so convert for your transport (`frame.pts // 1000` for a microsecond API, `frame.pts / 1e9` for seconds). Hand it to your WebRTC tracks and let the transport sync them. Don't re-sync yourself.
* **Push, don't poll, when you can.** Inject a custom `STVOutput` sink to write frames straight into your transport instead of draining `output_stream()`, for lower latency and less glue. (This is exactly what `pipecat-ojin` does.)
* **Match the video track to the model's frame size**: read `STVVideoFrame.width` / `height` and configure your outgoing track to match.
* **Deliver to end users over WebRTC, not the raw WebSocket.** Keep the Ojin WebSocket strictly server-to-server.

```python
async for frame in client.output_stream():
    if isinstance(frame, STVVideoFrame):
        video_track.push(frame.rgb, pts=frame.pts)     # feed your WebRTC track
    elif isinstance(frame, STVAudioFrame):
        audio_track.push(frame.pcm, pts=frame.pts)     # transport handles A/V sync
```

## Setup C. Direct WebRTC into your LiveKit or Daily room (recommended for browser playback)

For browser playback, we recommend **LiveKit**: Ojin publishes the avatar directly into the room, avoiding backend decoding and relaying of avatar frames. WebRTC handles network jitter, packet loss, and audio/video synchronization for smoother playback. **Daily** is also supported. Your backend still sends TTS audio and session commands to Ojin over WebSocket and receives events there.

This works with a local or hosted Python backend. The LiveKit server must be reachable from both Ojin and the browser; a server reachable only at `localhost` will not work for Ojin's remote publisher.

* **Pass `webrtc=WebRTCSettings(...)`** with the room URL and a token for the `ojin-avatar` participant. Mint the token on your backend and keep it there.
* **Set `audio_sample_rate` to your TTS output rate** so audio reaches the room without resampling.
* **Give the join room to breathe.** Set `webrtc_join_timeout_s` to about 90 s in production; it covers the room join and the model's cold start, which alone can take more than 30 s.
* **Drive UI state from events, not frames.** `output_stream()` receives no frames in this mode; use `WEBRTC_CONNECTED`, `BOT_STARTED_SPEAKING`, and `BOT_STOPPED_SPEAKING`.
* **Treat `ERROR` with `fatal=True` as the end of the session.** There is no fallback to the WebSocket; start a new session.
* **Keep your own bot from hearing the avatar.** If your agent is also in the room, unsubscribe it from the avatar's microphone.

```python
client = OjinSTVClient(
    api_key=..., config_id=...,
    webrtc=WebRTCSettings(provider="livekit", room_url=LIVEKIT_URL, token=avatar_token,
                          audio_sample_rate=24000, webrtc_join_timeout_s=90.0),
)
```

See [Direct WebRTC (LiveKit & Daily)](/models/build-with-python-sdk/python-sdk-webrtc) for credentials, events, errors, and Pipecat.

## See also

* [Build with the Python SDK](/models/build-with-python-sdk), install, auth, events, full quickstart
* [Direct WebRTC (LiveKit & Daily)](/models/build-with-python-sdk/python-sdk-webrtc), publish the avatar straight into your room
* [Optimizing Performance](/guides/optimizing-performance), the audio-feeding contract and tuning
* [Troubleshooting](/guides/troubleshooting), symptoms, causes, and fixes
* [API Reference (advanced)](/models/introduction/api), the raw WebSocket protocol


# Direct WebRTC (LiveKit & Daily)

Publish avatar audio and video directly into your LiveKit or Daily room. Avoid relaying avatar frames through your backend while keeping TTS input and control over WebSocket.

By default, `OjinSTVClient` streams the avatar's frames back to your process over the WebSocket. If your viewers are in a **LiveKit** or **Daily** room, Ojin can publish the avatar **straight into that room** instead. You add one argument and the rest of your program stays the same.

For smoother, more stable browser playback, we recommend direct **LiveKit** delivery. It removes the backend relay hop and uses WebRTC's handling of network jitter, packet loss, and audio/video synchronization. This applies to local demos as well as hosted apps. WebSocket remains the default when you need frames in your own process.

Requires `ojin-client` 0.11.0 or later (`pipecat-ojin` 0.1.5 or later for Pipecat).

## How it works

1. Your backend creates the room and a token for the avatar with your LiveKit or Daily account.
2. You pass the room URL and token to `OjinSTVClient` through `WebRTCSettings`.
3. Ojin joins the room as a participant named **`ojin-avatar`** and publishes the avatar's audio and video there.
4. Your viewers (browser, widget, or app) watch the avatar in the room like any other participant.

Your backend still sends TTS audio and session commands to Ojin over the same WebSocket and receives events and frame metadata there. Ojin publishes the avatar's audio and video directly into the room, so your backend does not decode or relay that output. The SDK doesn't join the room itself, and it doesn't create rooms or tokens.

## WebRTC or WebSocket?

|                        | WebSocket (default)                                       | Direct WebRTC                                                                        |
| ---------------------- | --------------------------------------------------------- | ------------------------------------------------------------------------------------ |
| Where the media goes   | to your process, via `output_stream()`                    | straight into your LiveKit or Daily room                                             |
| Media delivery path    | your backend receives frames and forwards them to viewers | avoids the backend relay hop                                                         |
| Backend work           | decode frames and relay them when serving viewers         | send TTS audio and handle session control/events; no avatar output decoding or relay |
| Frames in your process | yes                                                       | no                                                                                   |
| Choose it when         | you render, record, or post-process frames yourself       | you want browser playback over WebRTC, using a LiveKit or Daily room                 |

## Prerequisites

* Everything from [Build with the Python SDK](/models/build-with-python-sdk): an API key, a `config_id`, and `ojin-client[stv]` installed
* A LiveKit or Daily account, a room, and a token for the avatar

Your Python backend can run locally or on a hosted server. The room service must be reachable from both Ojin and your viewers. A LiveKit server reachable only at `localhost` cannot receive Ojin's avatar publisher.

{% tabs %}
{% tab title="LiveKit" %}
Mint an access token for the avatar. It only needs to join the room and publish:

```python
import os
from livekit import api  # pip install livekit-api

avatar_token = (
    api.AccessToken(os.environ["LIVEKIT_API_KEY"], os.environ["LIVEKIT_API_SECRET"])
    .with_identity("ojin-avatar")
    .with_grants(api.VideoGrants(
        room_join=True, room="my-room",
        can_publish=True, can_subscribe=False, can_publish_data=False,
    ))
    .to_jwt()
)
```

Mint the token with the identity `ojin-avatar`: on LiveKit a participant's identity comes from the token, so that claim is what your viewers use to tell the avatar apart from everyone else in the room.

| `WebRTCSettings` field | Value                                                         |
| ---------------------- | ------------------------------------------------------------- |
| `provider`             | `WebRTCProvider.LIVEKIT`                                      |
| `room_url`             | your LiveKit server URL, `wss://<your-project>.livekit.cloud` |
| `token`                | the access token above                                        |
| {% endtab %}           |                                                               |

{% tab title="Daily" %}
Create a room and a meeting token for it with the [Daily REST API](https://docs.daily.co/reference/rest-api):

```bash
curl -X POST https://api.daily.co/v1/rooms \
  -H "Authorization: Bearer $DAILY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "my-room"}'

curl -X POST https://api.daily.co/v1/meeting-tokens \
  -H "Authorization: Bearer $DAILY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"properties": {"room_name": "my-room"}}'
```

| `WebRTCSettings` field | Value                                                 |
| ---------------------- | ----------------------------------------------------- |
| `provider`             | `WebRTCProvider.DAILY`                                |
| `room_url`             | the room URL, `https://<your-domain>.daily.co/<room>` |
| `token`                | a meeting token for that room                         |
| {% endtab %}           |                                                       |
| {% endtabs %}          |                                                       |

{% hint style="warning" %}
Keep room credentials on your backend and never send the avatar's token to a browser.
{% endhint %}

## Switch to direct WebRTC

Pass `webrtc=WebRTCSettings(...)`. Leave it out and the same code runs over the WebSocket.

```python
import os
from ojin.stv import OjinSTVClient, WebRTCProvider, WebRTCSettings

client = OjinSTVClient(
    api_key=os.environ["OJIN_API_KEY"],
    config_id=os.environ["OJIN_CONFIG_ID"],
    webrtc=WebRTCSettings(
        provider=WebRTCProvider.LIVEKIT,                # Daily: WebRTCProvider.DAILY
        room_url="wss://your-project.livekit.cloud",    # Daily: https://your-domain.daily.co/room
        token=avatar_token,                             # credential for ojin-avatar
        audio_sample_rate=24000,                        # the rate your TTS emits
        webrtc_join_timeout_s=90.0,
    ),
)

async with client:
    await client.say(pcm, sample_rate=24000, num_channels=1)  # the avatar speaks in the room
```

`provider` also accepts the plain strings `"livekit"` and `"daily"`, if you carry the value in config. Everything else works as before: `start()`, `start_turn()`, `send_tts_audio()`, `say()`, `interrupt()`, `close()`, `async with`, and every event.

{% hint style="info" %}
**Tune two settings.**

* **`audio_sample_rate`**: set it to your TTS output rate (8000 to 48000 Hz, divisible by 25; default 16000) so audio reaches the room without resampling.
* **`webrtc_join_timeout_s`**: bounds the whole wait for the session to be ready, including the room join and the model's cold start. The default is 10 s. Use about **90 s** in production: a cold start alone can take more than 30 s.
  {% endhint %}

{% hint style="warning" %}
**`output_stream()` is empty in this mode.** The audio and video go to the room, not to your process, so `output_stream()` and any custom `STVOutput` receive no frames. The stream ends when the session closes. Use events for speaking state and timing.
{% endhint %}

## Events

| Event                  | Fires when                                                                                                                                                                             |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `SESSION_READY`        | the session is live and ready for audio                                                                                                                                                |
| `WEBRTC_CONNECTED`     | the avatar has joined the room (`participant_id`)                                                                                                                                      |
| `FIRST_FRAME`          | the first avatar frame is out (`frame_type`)                                                                                                                                           |
| `BOT_STARTED_SPEAKING` | the avatar starts speaking a turn                                                                                                                                                      |
| `BOT_STOPPED_SPEAKING` | the avatar finishes a turn                                                                                                                                                             |
| `INTERRUPTED`          | `interrupt()` took effect. In this mode it also fires when the barge-in only discarded input buffered before the room was open. Use `interrupt()`'s return value to tell the two apart |
| `ERROR`                | an error occurred (`message`, `fatal`, plus `code` for errors that carry one)                                                                                                          |
| `CLOSED`               | the session has been torn down                                                                                                                                                         |

`FIRST_FRAME` fires in WebSocket mode too.

{% hint style="info" %}
**The video track is silent until the first frame.** `WEBRTC_CONNECTED` means the avatar joined the room and published its tracks. It does not mean video is flowing. Nothing is sent on the video track until the model renders its first frame, which is what `FIRST_FRAME` reports.

That gap is the model's startup. It is under a second on a warm persona and can reach a few seconds on a cold one. `webrtc_join_timeout_s` bounds it.

If your viewer UI reveals the avatar as soon as it subscribes to the track, it shows an empty video element for that gap. Hold your own placeholder until `FIRST_FRAME`, or until your client reports a decoded frame. Gate the reveal on the signal rather than on the track: a UI that reveals on its first decoded frame shows whatever the track happened to carry before the avatar started.
{% endhint %}

## Errors

The client never falls back to the WebSocket silently. If the avatar can't get into the room, or later drops out of it, you get a fatal `ERROR` and the session closes. Each cause has its own `code`, so you can branch on it without reading the message:

| `code`                    | What happened                                                                      | What to do                                                                                                    |
| ------------------------- | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| `WEBRTC_AUTH_FAILED`      | the room rejected the avatar's token                                               | check the token is for the room in `room_url`, hasn't expired, and allows publishing                          |
| `WEBRTC_NETWORK_FAILED`   | Ojin couldn't reach the room                                                       | retry the session; if it persists, check your provider's status                                               |
| `WEBRTC_INVALID_SETTINGS` | the room URL or provider was unusable                                              | check `room_url` matches the provider (`wss://` for LiveKit, the room URL for Daily)                          |
| `WEBRTC_JOIN_TIMEOUT`     | the session wasn't ready within `webrtc_join_timeout_s`                            | raise the timeout. It covers the model's cold start as well as the room join                                  |
| `WEBRTC_ROOM_LOST`        | the avatar dropped out of the room mid-session                                     | start a new session                                                                                           |
| `WEBRTC_NOT_SUPPORTED`    | the server returned no room result, so this session can't be published into a room | connect without `webrtc` to receive frames over the WebSocket, or [contact support](/getting-started/support) |
| `WEBRTC_JOIN_FAILED`      | the join failed for a reason this SDK doesn't recognise                            | read `message` for the server's own code, retry, then [contact support](/getting-started/support)             |

```python
@client.on(STVEvent.ERROR)
def on_error(code: str = "", message: str = "", fatal: bool = False, **_):
    if code == "WEBRTC_AUTH_FAILED":
        remint_avatar_token()
    elif code == "WEBRTC_JOIN_TIMEOUT":
        retry_with_longer_timeout()
```

Invalid settings, such as an unknown provider or an empty `room_url` or `token`, raise `ValueError` when you construct `WebRTCSettings`.

## Pipecat

Pass the same `WebRTCSettings` to `OjinVideoService`. The service pushes no media in this mode, so turn off your transport's audio and video output:

```python
import os
from pipecat_ojin import OjinVideoService, OjinVideoSettings, WebRTCSettings
from ojin.stv import WebRTCProvider

avatar = OjinVideoService(
    OjinVideoSettings(
        api_key=os.environ["OJIN_API_KEY"],
        config_id=os.environ["OJIN_CONFIG_ID"],
        webrtc=WebRTCSettings(
            provider=WebRTCProvider.LIVEKIT, room_url=room_url, token=avatar_token
        ),
    )
)
# Transport params: audio_out_enabled=False, video_out_enabled=False
```

Lifecycle frames are unchanged. See the [Pipecat integration](/models/introduction/integrations) for the full pipeline.

## Where to go next

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Build with the Python SDK</strong></td><td>Install, authenticate, and run the quickstart.</td><td><a href="/models/build-with-python-sdk">Python SDK</a></td></tr><tr><td><strong>Best Practices</strong></td><td>Choose the right setup for your deployment.</td><td><a href="/models/build-with-python-sdk/python-sdk-best-practices">Best Practices</a></td></tr><tr><td><strong>Troubleshooting</strong></td><td>Join failures, timeouts, and session errors.</td><td><a href="/guides/troubleshooting">Troubleshooting</a></td></tr></tbody></table>


# Optimizing Performance

How to feed audio and play back frames for stable, low-latency lip-sync, and how the Python SDK and Pipecat handle most of it for you.

{% hint style="success" %}
**Using the** [**Python SDK**](/models/build-with-python-sdk) **or** [**Pipecat**](/models/introduction/integrations)**?** They already implement everything on this page, audio feeding, the playback clock, buffering, and audio/video sync. Read on if you want to tune them, or if you're building directly on the [raw WebSocket API](/models/introduction/api).
{% endhint %}

Each section below is tagged **🟢 SDK-handled** (automatic with the SDK or Pipecat, only your concern on the raw WebSocket API) or **🟠 Your setup** (you own it regardless of integration, deployment, network, credentials).

## Feed audio for stable, low-latency lip-sync

🟢 **SDK-handled**. `OjinSTVClient` shapes the feed automatically; the contract below is only for the raw WebSocket API.

Start with at least **320 ms of audio for Presence or 200 ms for Portrait**, then keep sending audio as your TTS produces it.

The recommended streaming pattern is:

1. **Start each turn with 500 ms for Presence or 400 ms for Portrait**, then stream the rest in real time as it arrives.
2. Then send the **largest chunks you can**: coalesce queued fragments into **\~400 ms** sends (staying under the 512 KB message cap).
3. Stay truly realtime: never wait for the whole utterance before you start.

{% hint style="success" %}
**`OjinSTVClient` shapes the input for you.** Feed audio as your TTS produces it. To use the recommended initial amounts, set `STVConfig.server_feed_initial_chunk_ms` to 500 for Presence or 400 for Portrait. The SDK handles batching automatically. A pause in your TTS or network can still interrupt playback. See the `server_feed_*` fields on `STVConfig` in the [`ojin-client` README](https://github.com/ojinai/python-sdk) for tuning. The contract above only matters if you drive the raw WebSocket API yourself.
{% endhint %}

```python
# With the SDK, feed audio as it arrives; shaping is automatic.
await client.start_turn()
async for chunk in tts_stream:          # e.g. 40 ms ElevenLabs / Cartesia chunks
    await client.send_tts_audio(chunk.pcm, sample_rate=chunk.rate, num_channels=1)
```

## Play back at realtime

🟢 **SDK-handled**: `output_stream()` is paced and buffered for you.

The model delivers frames at **realtime 25 fps**, so your buffer doesn't grow on its own. You just keep a **small buffer to absorb network jitter** (a few frames). How you consume them depends on your integration:

* **SDK / Pipecat**: `output_stream()` is already paced to realtime **25 fps with audio and video in sync**, and the client maintains the small jitter buffer for you (`initial_buffer_frames`). You don't manage buffering at all.
* **Raw WebSocket**: keep a small jitter buffer of a few frames before starting playback. If frames ever back up (e.g. a brief network stall, then a burst), trim idle frames (`frame_type == 0`) to recover, never drop speech (`1`), start-of-speech (`3`), or fade-out (`2`) frames. Drop a frame only when both the frame you just presented and the frame you are about to drop are idle, and stop as soon as the backlog is gone: trimming across a transition into speech leaves a visible gap. See [Buffer Management](/models/introduction/api#buffer-management) and [Audio and Video Synchronization](/models/introduction/api#audio-and-video-synchronization) in the API Reference.

{% hint style="info" %}
**Don't re-sync the SDK's output yourself.** `output_stream()` is already paced to 25 fps with audio and video aligned, so just present each frame **as it arrives**, never hold audio to wait for a video frame:

* **Playing directly (e.g. in a browser):** play audio and video frames as they come. No audio-clock or A/V re-sync logic needed.
* **Forwarding to a media transport (e.g. WebRTC):** each `STVAudioFrame` and `STVVideoFrame` carries a `pts` timestamp, pass it through and let the transport use it for sync. Don't build your own sync layer on top.

Building your own loop on the **raw WebSocket** instead? Every frame arrives with its own audio, so play that audio and render that image together. The server keeps them aligned, so you do not need an audio master clock there either. See [Audio and Video Synchronization](/models/introduction/api#audio-and-video-synchronization) in the API Reference.
{% endhint %}

## Where to run

🟠 **Your setup**: deployment is yours to get right, with the SDK or the raw API.

The realtime API is a **WebSocket built for server-to-server delivery over a stable connection**. It is not meant to run on an end-user device on flaky Wi‑Fi or mobile networks.

* **Run the client on a backend server**, not in the browser or on the user's device. This also keeps your API key off the client.
* **Deploy in US East**, where Ojin's realtime endpoint runs, for the lowest round-trip latency.
* **Deliver the final media to end users over a realtime transport** built for varying network conditions (typically **WebRTC**) rather than exposing the raw WebSocket to them.
* If your users are already on WebRTC, the SDK can have Ojin publish audio and video straight into your room (`OjinSTVWebRTCClient` with `WebRTCSettings`), instead of you draining frames and relaying them yourself.

## Publish directly into LiveKit or Daily

🟠 **Your setup**: choose it when your viewers are in a LiveKit or Daily room.

If your viewers are in a **LiveKit** or **Daily** room, use [direct WebRTC](/models/build-with-python-sdk/python-sdk-webrtc). Ojin publishes the avatar straight into the room, which removes the relay hop through your backend and gives viewers the lowest latency.

* **Match `audio_sample_rate` to your TTS output rate** (for example 24000) so audio isn't resampled on the way to the room.
* **Set a generous `webrtc_join_timeout_s`**, about 90 s in production. It covers the room join and the model's cold start, which alone can take more than 30 s.

## Play back higher-quality audio

🟢 **SDK-handled**: the SDK plays back your original audio automatically.

On the WebSocket transport, `OjinSTVClient` plays back the **original audio you fed it**. It only resamples a separate 16 kHz copy to send to the model for lip-sync. Your listeners hear your own audio rather than a 16 kHz round-trip. The client may trim or pad a few frames at a turn boundary to hold lip-sync, and fades the tail when you call `interrupt()`.

So you can feed **higher-quality TTS** (for example 24 kHz instead of 16 kHz) for better sound while lip-sync still works on the 16 kHz copy. This is an SDK-side capability: on the raw WebSocket API the audio you send must be 16 kHz mono PCM int16. Just make sure your player runs at the rate you fed — `STVAudioFrame.sample_rate` reports it per frame, but frames emitted before your first `send_tts_audio()` default to 16 kHz, so don't configure a player from the very first frame.

With [direct WebRTC](/models/build-with-python-sdk/python-sdk-webrtc) there is no local playback: set `audio_sample_rate` to your TTS rate and the room receives that audio without resampling.

## Relay frames without re-encoding

🟢 **SDK-handled**: the SDK exposes the raw JPEG (`source_bytes`) for you.

If you forward video frames to a browser or media transport that decodes JPEG itself, skip the decode:

* The **default decoder** populates `STVVideoFrame.rgb` (decoded RGB) and also keeps the raw JPEG in `STVVideoFrame.source_bytes`.
* `source_bytes` is **empty (`b""`) on a held tick** (no new server frame that tick), so skip those rather than relaying a zero-byte payload. `rgb` still carries the previous image if you need something on every tick.

{% hint style="warning" %}
**Do not reach for `PassthroughDecoder` to skip the decode.** It makes the client emit no video frames at all, so your relay loop silently never runs. Its `decode()` returns `None` for every frame, and the client only ever emits a video frame once it has an RGB image to attach, so it drops every tick instead. Keep the default decoder and read `source_bytes`.
{% endhint %}

## Keep latency low

🟢 **SDK-handled** · 🟠 **Your setup** (deployment)

Keep your buffers as small as your network allows; large buffers add latency. On the raw API, tune your target buffer size by watching it during playback: low enough to minimise latency, high enough to absorb jitter without starving playback. With the SDK, the relevant knobs live on `STVConfig` (`initial_buffer_frames`, `max_buffered_video_frames`) — see the [`ojin-client` README](https://github.com/ojinai/python-sdk) for the full list.

## Next steps

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Troubleshooting</strong></td><td>Symptoms, causes, and fixes.</td><td><a href="/guides/troubleshooting">Troubleshooting</a></td></tr><tr><td><strong>Python SDK Best Practices</strong></td><td>Working pipelines for browser output and WebRTC backends.</td><td><a href="/models/build-with-python-sdk/python-sdk-best-practices">Best Practices</a></td></tr></tbody></table>


# Troubleshooting

Common symptoms when building real-time avatars, with their cause and fix.

{% hint style="info" %}
**🟢 SDK-handled**: the [Python SDK](/models/build-with-python-sdk) and [Pipecat](/models/introduction/integrations) take care of this for you; it surfaces only on the raw WebSocket API (or if you turn a feature off). The simplest fix is usually "use the SDK."

**🟠 Your setup**: you own this regardless of integration: deployment, network, credentials, capacity, or raw-API tuning.
{% endhint %}

## Jump to a symptom

* [Mouth barely moves, idle animation only, or the avatar jumps between utterances](#mouth-barely-moves-idle-animation-only-or-the-avatar-jumps-between-utterances)
* [Lip-sync drifts out of sync with the audio](#lip-sync-drifts-out-of-sync-with-the-audio)
* [Choppy or crackling playback](#choppy-or-crackling-playback)
* [No video frames at all](#no-video-frames-at-all)
* [Growing latency over time](#growing-latency-over-time)
* [Frame lag during speech on the raw API](#frame-lag-during-speech-on-the-raw-api)
* [No backend servers available](#no-backend-servers-available)
* [Connection or authentication fails](#connection-or-authentication-fails)
* [ElevenLabs Agents: the avatar connects but does not respond](#elevenlabs-agents-the-avatar-connects-but-does-not-respond)
* [Interruptions look abrupt or the avatar keeps speaking after a barge-in](#interruptions-look-abrupt-or-the-avatar-keeps-speaking-after-a-barge-in)
* [Direct WebRTC: the avatar's video is blank right after it joins](#direct-webrtc-the-avatars-video-is-blank-right-after-it-joins)
* [Direct WebRTC: the avatar can't join the room](#direct-webrtc-the-avatar-cant-join-the-room)
* [Direct WebRTC: the session times out before it's ready](#direct-webrtc-the-session-times-out-before-its-ready)
* [Direct WebRTC: the avatar drops out mid-session](#direct-webrtc-the-avatar-drops-out-mid-session)
* [Direct WebRTC: WEBRTC\_NOT\_SUPPORTED](#direct-webrtc-webrtc_not_supported)
* [Direct WebRTC: my bot hears the avatar](#direct-webrtc-my-bot-hears-the-avatar)

## Mouth barely moves, idle animation only, or the avatar jumps between utterances

🟢 **SDK-handled**

**Cause:** too little audio has arrived, or delivery has stalled. The minimum initial audio is **320 ms for Presence or 200 ms for Portrait**. A pause in your TTS or network can still interrupt playback.

**Fix:** start each turn with the recommended **500 ms for Presence or 400 ms for Portrait**, then stream in real time with the largest chunks you can (\~400 ms). See [Optimizing Performance → Feed audio](/guides/optimizing-performance#feed-audio-for-stable-low-latency-lip-sync). With `OjinSTVClient`, feed audio as your TTS produces it and let the SDK handle batching.

## Lip-sync drifts out of sync with the audio

🟢 **SDK-handled**

**Cause:** on the SDK path, you're adding your own A/V re-sync on top of an already-synced stream. On the raw API, you're playing your own copy of the TTS audio on its own clock instead of the audio that arrives with each frame, or frames were reordered during async decode.

**Fix:** with the SDK or Pipecat, `output_stream()` is already aligned at 25 fps. **don't re-sync it yourself**. Present each frame as it arrives, or pass each frame's `pts` to your media transport (e.g. WebRTC) and let it handle sync. If you build your own loop on the raw API, play the audio payload that arrived with each frame and render that frame's image at the same time. The server aligns them for you, so no audio master clock is needed. Keep decode order stable. If playback includes gaps, check that your TTS and network are delivering audio continuously. See [Audio and Video Synchronization](/models/introduction/api#audio-and-video-synchronization) in the API Reference.

## Choppy or crackling playback

🟢 **SDK-handled**

**Cause:** audio isn't playing at a steady rate, or the event loop is blocked.

**Fix:** the SDK emits exactly one audio frame every 40 ms tick (real audio or silence), so its output never starves on its own. Keep your frame handlers light: heavy synchronous work stalls the tick that paces them. On the raw API, play audio gaplessly at a steady rate and never stop it just because a video frame is late. See [Optimizing Performance → Play back at realtime](/guides/optimizing-performance#play-back-at-realtime).

## No video frames at all

🟢 **SDK-handled**

**Cause:** you haven't received `SESSION_READY` / `SessionReady` yet, or (SDK) you're using a `PassthroughDecoder`, which suppresses video frames entirely.

**Fix:** wait for the session-ready signal before sending audio. With the SDK, keep the default decoder: it populates `frame.rgb` and also carries the raw JPEG in `frame.source_bytes`, so you can relay without re-encoding. A `PassthroughDecoder` makes the client emit no video frames at all, so do not use it. See [Optimizing Performance → Relay frames](/guides/optimizing-performance#relay-frames-without-re-encoding).

## Growing latency over time

🟢 **SDK-handled** · 🟠 **Your setup** (deployment)

**Cause:** your buffer is too large, or frames backed up after a network stall. The model delivers at realtime 25 fps, so the buffer shouldn't grow on its own. Keep only a small jitter buffer.

**Fix:** the SDK keeps the buffer small and trims backed-up idle frames for you (`idle_buffer_target_frames`, default 6), so don't filter `output_stream()` by `frame_type` yourself. It fights the client's own catch-up. On the raw API, keep the buffer to a few frames and, if frames back up on a poor connection, trim idle frames (`frame_type == 0`); never drop speech, start-of-speech, or fade-out frames. Either way, run the client on a backend in **US East** over a stable connection. See [Optimizing Performance → Where to run](/guides/optimizing-performance#where-to-run).

## Frame lag during speech on the raw API

🟠 **Your setup** (raw-API tuning)

**Cause:** your playback buffer is larger than it needs to be, so every frame waits behind the ones ahead of it.

**Fix:** shrink the jitter buffer to the smallest size your network tolerates. Output smoothing itself is not caller-tunable: there is no parameter on the wire protocol that changes it. If the lag persists at a small buffer, contact support with a session id rather than trying to tune it from the client.

## No backend servers available

🟠 **Your setup**

**Cause:** inference capacity is momentarily exhausted.

**Fix:** retry shortly with backoff. On the SDK this surfaces as an `ERROR` event with code `NO_BACKEND_SERVER_AVAILABLE`. On the raw API it arrives either as an `ErrorResponse` with `BACKEND_UNAVAILABLE`, or as a bare plain-text frame with no code at all (`"No backend servers available. Please try again later."`). Handle non-JSON text frames too.

## Connection or authentication fails

🟠 **Your setup**

**Fix:**

* ✓ Verify your API key and `config_id`, and that the config exists in your [dashboard](https://ojin.ai/dashboard)
* ✓ The `Authorization` header must use the **raw API key** (no `Bearer` prefix)
* ✓ Ensure your network allows WebSocket connections on port 443

## ElevenLabs Agents: the avatar connects but does not respond

🟠 **Your setup** (ElevenLabs API key)

**Cause:** the key can read the ElevenLabs agent but lacks ElevenAgents Write (`convai_write`). Ojin's **Connection verified** check only confirms read access. ElevenLabs then rejects the request to start a conversation, so the avatar stays silent and the conversation panel stays empty.

**Fix:** give the key ElevenAgents Read and Write access in ElevenLabs. If you create a new key, enter it in the Ojin agent's provider settings. Start a new session to test it.

## Interruptions look abrupt or the avatar keeps speaking after a barge-in

🟢 **SDK-handled**

**Cause:** old TTS audio is still being sent, or frames already buffered keep playing after you cancel.

**Fix:** stop the old TTS producer and call the SDK's `interrupt()`. Call `start_turn()` before feeding the next reply. On the raw API, pick an interruption strategy for your latency/smoothness trade-off: clear the buffer for an instant cut, or keep playing video while stopping audio for a smoother look. See [Interruption Handling](/models/introduction/api#interruption-handling) in the API Reference.

## Direct WebRTC: the avatar's video is blank right after it joins

🟠 **Your setup** (viewer UI)

**Cause:** the avatar publishes its video track when it joins the room, before the model has rendered anything. Nothing is sent on that track until the first frame exists, so a viewer who subscribes in that window gets a track with no video. The wait is the model's startup: under a second on a warm persona, a few seconds on a cold one.

**Fix:**

* ✓ Reveal the avatar on the first decoded frame, or on `FIRST_FRAME`, not on track subscribe
* ✓ Show your own placeholder until then, such as a still image of the persona
* ✓ If the wait is longer than you expect, it is cold start. See [the session times out before it's ready](#direct-webrtc-the-session-times-out-before-its-ready)

A blank element here is the avatar not having started, not a dropped connection. See [Direct WebRTC → Events](/models/build-with-python-sdk/python-sdk-webrtc#events).

## Direct WebRTC: the avatar can't join the room

🟠 **Your setup** (credentials)

**Cause:** the room rejected the avatar. You get a fatal `ERROR` whose `code` names the cause: `WEBRTC_AUTH_FAILED` (the token doesn't match the room), `WEBRTC_NETWORK_FAILED` (Ojin couldn't reach the room), or `WEBRTC_INVALID_SETTINGS` (the room URL or provider was unusable).

**Fix:**

* ✓ **LiveKit:** `room_url` is your server URL (`wss://…`), and the token allows room join and publish for the right room, with the identity `ojin-avatar`
* ✓ **Daily:** `room_url` is the room URL and `token` is a meeting token for **that** room
* ✓ The token hasn't expired
* ✓ `WEBRTC_NETWORK_FAILED`: check that your LiveKit or Daily service is reachable and retry

See [Direct WebRTC → Prerequisites](/models/build-with-python-sdk/python-sdk-webrtc#prerequisites).

## Direct WebRTC: the session times out before it's ready

🟠 **Your setup**

**Cause:** the session wasn't ready within `webrtc_join_timeout_s` (default 10 s). The timeout covers both the room join and the model's cold start, so a cold start alone can exceed it. You get a fatal `WEBRTC_JOIN_TIMEOUT`.

**Fix:** raise `webrtc_join_timeout_s` to about **90 s** in production. A cold start alone can take more than 30 s. Retrying usually works too, because the server keeps starting after the client gives up.

## Direct WebRTC: the avatar drops out mid-session

🟠 **Your setup**

**Cause:** the avatar lost the room after joining it, and you get a fatal `WEBRTC_ROOM_LOST`. The client never rejoins on its own.

**Fix:** start a new session. If it recurs, check the room's lifetime and token expiry against your session length.

## Direct WebRTC: WEBRTC\_NOT\_SUPPORTED

🟠 **Your setup**

**Cause:** the server returned no room result, so this session can't be published into a room. The client doesn't fall back to the WebSocket; it emits a fatal `ERROR` and closes the session.

**Fix:** leave out `webrtc=` to use the WebSocket mode, or [contact support](/getting-started/support) with your `config_id`.

## Direct WebRTC: my bot hears the avatar

🟠 **Your setup**

**Cause:** your own voice agent is in the same room and subscribes to the avatar's microphone, so it transcribes the avatar's voice as user speech and replies to itself.

**Fix:** unsubscribe your bot from the avatar's audio. Identify the avatar with `is_avatar_participant()` (Daily) or `is_avatar_identity()` (LiveKit) from `ojin`. See [Direct WebRTC (LiveKit & Daily)](/models/build-with-python-sdk/python-sdk-webrtc).

***

Still stuck? [Contact support](/getting-started/support).


