Session API Reference

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

Base URL

https://{region}.agents.ojin.ai

The agents.ojin.ai domain uses geoproximity routing to direct requests to the nearest regional endpoint.

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

Body:

{
  "agent_id": "your-agent-id",
  "client_user_ref": "optional-user-identifier"
}
Field
Type
Required
Description

agent_id

string

Yes

The ID of the agent to start a session with

client_user_ref

string

No

An opaque identifier for your end user. Appears in call history for analytics and tracking. Max 256 characters.

Response (200 OK)

Field
Type
Description

session_id

string

Unique identifier for this session

room_url

string

WebRTC room URL to connect to

token

string

Authentication token for joining the room

Use room_url and token to connect to the WebRTC room from your client. If you're building a web application, you can use the Daily JavaScript SDK to join the room.

Error Responses

All errors return a JSON body with error_code and message:

For concurrency_limit errors, the response includes an additional retry_after_seconds field indicating how long to wait before retrying:

Error Code
HTTP Status
Description

agent_not_found

404

Agent ID does not exist or is not visible to the caller

agent_unpublished

403

Agent exists but status is unpublished

auth_failed

403

Hostname allowlist validation failed

concurrency_limit

429

Max concurrency reached. Response includes retry_after_seconds

room_creation_failed

502

WebRTC room could not be created

orchestrator_error

502

Agent orchestrator is unreachable or returned an error

internal_error

500

Unexpected server error

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:

  • If the origin matches an allowed hostname, the request proceeds

  • If no hostnames are configured, all requests are rejected (agent is private)

  • If * is configured, all origins are accepted

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

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.

Examples

curl

Python

JavaScript

Connecting to the Room

After receiving the room_url and token from the Session API, connect to the WebRTC room using the Daily JavaScript SDK:

This is only needed for custom integrations. If you're using the widget, it handles the room connection automatically.

Last updated

Was this helpful?