Skip to main content

Event Handlers

OdysseyEventHandlers

Event handlers for the Odyssey client class.
interface OdysseyEventHandlers {
  onConnected?: (mediaStream: MediaStream) => void;
  onDisconnected?: () => void;
  onStreamStarted?: (streamId: string) => void;
  onStreamEnded?: () => void;
  onInteractAcknowledged?: (prompt: string) => void;
  onStreamError?: (reason: string, message: string) => void;
  onError?: (error: Error, fatal: boolean) => void;
  onStatusChange?: (status: ConnectionStatus, message?: string) => void;
}
HandlerParametersDescription
onConnectedmediaStream: MediaStreamCalled when video stream is established
onDisconnected-Called when video stream is closed
onStreamStartedstreamId: stringCalled when interactive stream is ready (streamId can be used for recordings)
onStreamEnded-Called when interactive stream has ended
onInteractAcknowledgedprompt: stringCalled when interaction is processed
onStreamErrorreason: string, message: stringCalled on stream error (e.g., model crash)
onErrorerror: Error, fatal: booleanCalled on general error
onStatusChangestatus: ConnectionStatus, message?: stringCalled when connection status changes

UseOdysseyHandlers

Event handlers for the useOdyssey React hook. Same interface as OdysseyEventHandlers.
type UseOdysseyHandlers = OdysseyEventHandlers;

UseOdysseyOptions

Configuration for the useOdyssey React hook.
interface UseOdysseyOptions {
  /** API key for authentication (required) */
  apiKey: string;
  /** Event handlers (optional) */
  handlers?: UseOdysseyHandlers;
}
PropertyTypeRequiredDescription
apiKeystringYesYour Odyssey API key
handlersUseOdysseyHandlersNoEvent handlers

Configuration

ClientConfig

Configuration for the Odyssey client constructor.
interface ClientConfig {
  /** API key for authentication (required) */
  apiKey: string;
}
PropertyTypeDescription
apiKeystringAPI key for authentication

Status Types

ConnectionStatus

type ConnectionStatus =
  | 'authenticating'  // Authenticating with Odyssey API
  | 'connecting'      // Connecting to streaming server
  | 'reconnecting'    // Reconnecting after disconnect
  | 'connected'       // Connected and ready
  | 'disconnected'    // Disconnected (clean)
  | 'failed';         // Connection failed (fatal)

Recording Types

Recording types were added in v1.0.0

Recording

Recording data returned from getRecording().
interface Recording {
  stream_id: string;
  video_url: string | null;
  events_url: string | null;
  thumbnail_url: string | null;
  preview_url: string | null;
  frame_count: number | null;
  duration_seconds: number | null;
}
PropertyTypeDescription
stream_idstringThe stream ID (unique per startStream/endStream)
video_urlstring | nullPresigned URL for full recording video (MP4)
events_urlstring | nullPresigned URL for events log (JSONL)
thumbnail_urlstring | nullPresigned URL for thumbnail image (JPEG)
preview_urlstring | nullPresigned URL for preview video (MP4)
frame_countnumber | nullTotal frames in recording
duration_secondsnumber | nullRecording duration in seconds
URLs are valid for a limited time (typically 1 hour).

StreamRecordingSummary

Summary of a stream recording returned in listStreamRecordings().
interface StreamRecordingSummary {
  stream_id: string;
  width: number;
  height: number;
  started_at: string;
  ended_at: string | null;
  duration_seconds: number | null;
}
PropertyTypeDescription
stream_idstringUnique stream identifier (per startStream/endStream)
widthnumberStream resolution width
heightnumberStream resolution height
started_atstringISO timestamp when stream started
ended_atstring | nullISO timestamp when stream ended
duration_secondsnumber | nullStream duration in seconds

ListStreamRecordingsOptions

Options for listStreamRecordings().
interface ListStreamRecordingsOptions {
  limit?: number;
  offset?: number;
}
PropertyTypeDefaultDescription
limitnumber50Maximum recordings to return (max 100)
offsetnumber0Number of recordings to skip (pagination)

StreamRecordingsListResponse

Response from listStreamRecordings().
interface StreamRecordingsListResponse {
  recordings: StreamRecordingSummary[];
  total: number;
  limit: number;
  offset: number;
}
PropertyTypeDescription
recordingsStreamRecordingSummary[]Array of stream recording summaries
totalnumberTotal recordings available
limitnumberLimit used in request
offsetnumberOffset used in request

Simulate API Types

Simulate API types were added in v1.0.0

SimulationJobStatus

Status of a simulation job.
type SimulationJobStatus = 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
StatusDescription
pendingJob is queued and waiting to start
runningJob is currently executing
completedJob finished successfully
failedJob encountered an error
cancelledJob was cancelled by user

ScriptEntry

An entry in a simulation script.
interface ScriptEntry {
  timestamp_ms: number;           // When this action occurs (milliseconds from start)
  start?: {                       // Begin a new stream
    prompt: string;
    image?: File | Blob | string; // Optional image for image-to-video
  };
  interact?: {                    // Send an interaction
    prompt: string;
  };
  end?: Record<string, never>;    // End the stream (empty object)
}
PropertyTypeDescription
timestamp_msnumberWhen this action occurs (milliseconds from start)
start{ prompt: string; image?: File | Blob | string }Begin a new stream with initial prompt
interact{ prompt: string }Send an interaction prompt
end{}End the current stream (empty object)

SimulateOptions

Options for simulate().
interface SimulateOptions {
  script: ScriptEntry[];
  portrait?: boolean;  // true for portrait (704x1280), false for landscape (1280x704)
}
PropertyTypeDescription
scriptScriptEntry[]Array of script entries to execute
portraitbooleanPortrait mode (default: true)

SimulationStream

Information about a stream within a simulation.
interface SimulationStream {
  stream_id: string;
  status: 'pending' | 'running' | 'completed' | 'failed';
  error_message: string | null;
}
PropertyTypeDescription
stream_idstringUnique stream identifier
statusstringStatus of this stream
error_messagestring | nullError message if failed

SimulationJob

Response from simulate().
interface SimulationJob {
  job_id: string;
  status: SimulationJobStatus;
  priority: string;
  created_at: string;
  estimated_wait_minutes: number | null;
}
PropertyTypeDescription
job_idstringUnique identifier for the job
statusSimulationJobStatusCurrent job status
prioritystringJob priority
created_atstringISO timestamp when job was created
estimated_wait_minutesnumber | nullEstimated wait time in minutes

SimulationJobDetail

Detailed information about a simulation job from getSimulateStatus().
interface SimulationJobDetail {
  job_id: string;
  status: SimulationJobStatus;
  priority: string;
  created_at: string;
  started_at: string | null;
  completed_at: string | null;
  error_message: string | null;
  streams: SimulationStream[];
}
PropertyTypeDescription
job_idstringUnique identifier for the job
statusSimulationJobStatusCurrent job status
prioritystringJob priority
created_atstringISO timestamp when job was created
started_atstring | nullISO timestamp when job started running
completed_atstring | nullISO timestamp when job completed
error_messagestring | nullError message if job failed
streamsSimulationStream[]Streams created during simulation

SimulationJobInfo

Summary information for a simulation job in a list.
interface SimulationJobInfo {
  job_id: string;
  status: SimulationJobStatus;
  priority: string;
  created_at: string;
  completed_at: string | null;
  error_message: string | null;
}
PropertyTypeDescription
job_idstringUnique identifier for the job
statusSimulationJobStatusCurrent job status
prioritystringJob priority
created_atstringISO timestamp when job was created
completed_atstring | nullISO timestamp when job completed
error_messagestring | nullError message if job failed

ListSimulationsOptions

Options for listSimulations().
interface ListSimulationsOptions {
  limit?: number;
  offset?: number;
}
PropertyTypeDefaultDescription
limitnumber50Maximum jobs to return (max 100)
offsetnumber0Number of jobs to skip (pagination)

SimulationJobsList

Response from listSimulations().
interface SimulationJobsList {
  jobs: SimulationJobInfo[];
  total: number;
  limit: number;
  offset: number;
}
PropertyTypeDescription
jobsSimulationJobInfo[]Array of simulation job summaries
totalnumberTotal jobs available
limitnumberLimit used in request
offsetnumberOffset used in request

Error Handling

Fatal vs Non-Fatal Errors

The onError handler receives a fatal boolean parameter:
FatalDescriptionAction Required
trueConnection cannot continueReturn user to connect page
falseRecoverable errorMay retry or notify user

Common Error Messages

ErrorDescription
Odyssey: config object is required...Constructor called without a config object
Odyssey: apiKey is required and must be a string...API key is missing, undefined, or not a string
Odyssey: apiKey cannot be empty...API key is an empty string
Invalid API keyThe provided API key is invalid (401)
Invalid API key format...API key format is malformed (422)
API key access deniedThe API key is valid but access is denied (403, e.g., suspended account)
Maximum concurrent sessions (N) reachedConcurrent session quota exceeded (429)
No available sessionsNo streamers available, try again later
Streamer not availableAssigned streamer is not responding
Streamer disconnectedStreamer disconnected during session
Timed out waiting for a streamerQueue timeout expired while waiting for a streamer

TypeScript Exports

// Main entry point (@odysseyml/odyssey)
export { Odyssey } from './odyssey';
export type { OdysseyEventHandlers, ConnectionStatus, ClientConfig, OdysseyClient } from './types';

// React entry point (@odysseyml/odyssey/react)
export { useOdyssey } from './useOdyssey';
export type { UseOdysseyHandlers, OdysseyClient } from './types';

Browser Compatibility

BrowserMinimum Version
Chrome/Edge90+
Firefox88+
Safari14.1+
Requires WebRTC support (RTCPeerConnection, RTCDataChannel)