Skip to main content
Web SDK

HappyOyster Web SDK API Reference

HappyOysterEngine configures the Open Platform host and model, updates the QwenCloud temporary API Key token, and creates Travel sessions. Travel is the session object returned by createTravel(); the session is entered and started only after calling travel.start(). Supports the adventure, directing, and acting modes.

HappyOysterEngine configures the Open Platform host, updates the QwenCloud temporary API-key token, and creates Travel sessions. Travel is the session object returned by createTravel(). The session is entered and started only after travel.start() is called.

Core Terminology

Term

Meaning

Notes

token

QwenCloud temporary API-key token: when calling QwenCloud services from untrusted environments such as browsers or mobile apps, generate a temporary API Key through a secure backend to avoid exposing a permanent API Key. The SDK sends this token to Open Platform as an HTTP Bearer credential.

Get authentication credentials

ticket

HappyOyster world Travel credential: your backend calls the credential API using AK authentication (gateway header) to obtain a short-lived Travel credential (ticket) that the client uses to enter a room. The API verifies world ownership but does not create an actual Travel record.

Get authentication credentials

Overview

The SDK provides the following primary objects:

HappyOysterEngine

API

Description

new HappyOysterEngine(config)

Creates an Engine instance.

updateToken(token)

Updates the QwenCloud temporary API-key token used by subsequent Open Platform API requests.

createTravel(config)

Creates a Travel session.

HappyOysterEngine.version

The current SDK version.

HappyOysterEngine.metadata

The current SDK package name, version, and package channel.

Travel

API

Description

start()

Starts the current Travel session.

on("statusChanged", handler)

Subscribes to session status changes.

on("firstFrameGenerated", handler)

Subscribes to first-frame URL notifications.

on("travelInfoReady", handler)

Subscribes to session metadata available immediately after enter-travel.

onError(handler)

Subscribes to session runtime errors.

can(action)

Checks whether the specified action can currently be called.

getInfo()

Gets available session metadata; returns null before it is available.

sendCommand(params)

Sends a real-time control command.

sendInstruct(params)

Sends Directing instructions or prompt content.

pause()

Pauses the current session.

resume()

Resumes a paused session.

rewind(params)

Rewinds a Directing session to the specified time.

end()

Ends the current session and releases its resources.

Other Exports

Export

Description

ErrorCode

The error-code constant object exported by the SDK.

isSdkError(error)

Checks whether an unknown error is a standard SDK error.

Types

Public types such as SDKConfig, Travel, StartTravelResult, and AdventureCommand.

Example

import { HappyOysterEngine, isSdkError } from '@happy-oyster/js-sdk'

const engine = new HappyOysterEngine({
  APIHost: 'open-platform.example.com',
  model: 'happyoyster-1.0-adventure', // Required; Adventure model shown as an example
  token: 'temporary-api-key-token',
  logLevel: 'warn',
  streamReadyTimeout: 15_000,
})

const videoElement = document.getElementById('player') as HTMLVideoElement
const travel = engine.createTravel({
  ticket: 'travel-ticket',
  videoElement,
  maxExperienceTimeSec: 90,
})

const unsubscribeStatus = travel.on('statusChanged', (status) => {
  console.log('Travel status:', status)
})

const unsubscribeFirstFrame = travel.on('firstFrameGenerated', (firstFrame) => {
  console.log('First frame URL:', firstFrame)
})

const unsubscribeInfo = travel.on('travelInfoReady', (info) => {
  console.log('Travel info is ready before RTC playback:', info)
})

const unsubscribeError = travel.onError((error) => {
  console.error('Travel error:', error)
})

try {
  const { encryptedTravelId, mode, creationModel, firstFrame, maxExperienceTimeSec, aspectRatio } = await travel.start()

  // Adventure (mode 1)
  await travel.sendCommand({
    translation: 'Front',
    rotation: 'Mouse_Left',
    interaction: 'Jump',
  })

  // Directing (mode 2) or Acting (mode 3; not scriptlist)
  await travel.sendInstruct({ content: 'Turn the camera toward the castle and have the protagonist start running' })

  await travel.pause()
  await travel.resume()
} catch (err) {
  if (isSdkError(err)) {
    console.error('SDK error:', err.code, err.message)
  } else {
    console.error('Unexpected error:', err)
  }
} finally {
  unsubscribeStatus()
  unsubscribeFirstFrame()
  unsubscribeInfo()
  unsubscribeError()
  await travel.end()
}

engine.updateToken('new-temporary-api-key-token')

HappyOysterEngine

HappyOysterEngine is the Web SDK entry point. It configures the Open Platform host, manages the QwenCloud temporary API-key token used by subsequent requests, and creates Travel sessions.
An Engine instance currently manages only one active Travel at a time. End the current Travel before starting a new session.After a token is set either in the constructor or through updateToken(), the SDK internally fetches Feature Gate configuration. This allows the platform to remotely disable the SDK or require older versions to upgrade. If the request fails, the SDK fails open and does not block the normal experience.

API

Description

new HappyOysterEngine(config)

Creates an Engine instance with the required API host and model, and optional token and log level.

updateToken(token)

Updates the QwenCloud temporary API-key token used by subsequent Open Platform requests.

createTravel(config)

Creates a Travel session that has not yet started.

new HappyOysterEngine

Creates a HappyOysterEngine instance.

Signature

new HappyOysterEngine(config: SDKConfig)

Parameters

SDKConfig

Field

Type

Required

Description

APIHost

string

Yes

Open Platform API host. It must be a bare host, such as open-platform.example.com, without https://, a scheme, or a path.

model

string

Yes

Identifier of the Open Platform model to use. Required, with no default. Fixed for this Engine and shared by all its Travels.

token

string

No

QwenCloud temporary API-key token set during construction. It can also be set later with updateToken().

logLevel

LogLevel

No

SDK log level. Defaults to none.

streamReadyTimeout

number

No

Timeout for waiting for <video> to become playable, stop, or resume, in milliseconds. Defaults to 15000.

Set model to a model identifier, such as happyoyster-1.0-adventure, an Adventure model. Use the model identifier for your target service environment. The SDK does not choose a model from the experience mode or infer it from the ticket. An Engine has a fixed APIHost + model. Reuse it for successive Travels targeting the same service and model. Before switching either value, end the active Travel and use an Engine configured for the new target. Create the world and issue its ticket against the same service target.

Returns

Returns a HappyOysterEngine instance.

Errors

If config is missing, or if APIHost, model, token, logLevel, or streamReadyTimeout has an invalid type or value, an SdkError with code ErrorCode.INVALID_ARGUMENT (10010001) is thrown synchronously. Passing a full URL, an empty string, or a value with a path as APIHost is invalid. model is required and must be a non-empty string after trimming; null, non-string values, and whitespace-only strings are invalid. Omitting it or passing undefined also raises an argument error; the SDK has no default model.

HappyOysterEngine.updateToken

Updates the QwenCloud temporary API-key token used by subsequent Open Platform API requests.

Signature

updateToken(token: string): void

Parameters

Field

Type

Required

Description

token

string

Yes

QwenCloud temporary API-key token. Passing a blank string clears the current token.

Returns

Returns nothing.

Errors

If token is not a string, an SdkError with code ErrorCode.INVALID_ARGUMENT (10010001) is thrown synchronously.

HappyOysterEngine.createTravel

Creates a Travel session instance without starting it.

Signature

createTravel(config: CreateTravelConfig): Travel

Parameters

CreateTravelConfig

Field

Type

Required

Description

ticket

string

Yes

Ticket used to start the Travel later.

videoElement

HTMLVideoElement

Yes

The <video> element used to render session video. It must be provided when creating the Travel.

maxExperienceTimeSec

60 | 90 | 120

No

Maximum Adventure experience duration, in seconds. Directing and Acting sessions ignore this field. When omitted, the server applies its default.

Returns

Returns a created but not yet started Travel session. The caller must then run await travel.start() to enter the session and wait for the video to become playable. Each HappyOysterEngine instance may have only one active Travel at a time. Call await travel.end() before creating another Travel.

Errors

createTravel() throws an SdkError synchronously in the following cases:

ErrorCode

Description

10010001

config, ticket, videoElement, or maxExperienceTimeSec is invalid

10010101

A Travel is already active; call travel.end() first

Startup errors are exposed by travel.start().

Travel

Travel represents a session created by HappyOysterEngine.createTravel(). It is initially inactive. After travel.start() is called, the SDK enters the session and waits for the video to become playable. Travel supports starting, pausing, resuming, rewinding, and ending a session; sending real-time controls and prompts; and subscribing to status changes and runtime errors.

Methods

Method

Description

start()

Starts the current Travel session.

on("statusChanged", handler)

Subscribes to session status changes.

on("firstFrameGenerated", handler)

Subscribes to first-frame URL notifications.

on("travelInfoReady", handler)

Subscribes to session metadata available immediately after enter-travel.

onError(handler)

Subscribes to session runtime errors.

can(action)

Checks whether the specified action can currently be called.

getInfo()

Gets available session metadata; returns null before it is available.

sendCommand(params)

Sends a real-time control command.

sendInstruct(params)

Sends Directing instructions or prompt content.

pause()

Pauses the current session.

resume()

Resumes a paused session.

rewind(params)

Rewinds the current session to the specified time.

end()

Ends the current session and releases its resources.

Status

Status

Description

idle

The session has not started.

prepare

The session is starting and waiting for the video to become playable.

running

The session is running.

paused

The session is paused and can be resumed or rewound.

completed

The session has ended normally and its resources have been released.

Events

Subscribe to events with travel.on(event, handler). The method returns an unsubscribe function.

Event

Callback

Description

statusChanged

(status: TravelStatus) => void

The session status changed.

firstFrameGenerated

(firstFrame: string) => void

Emitted during start() when Open Platform returns a non-empty first-frame URL; before start() resolves and the video becomes playable.

travelInfoReady

(info: TravelInfo) => void

Emitted after enter-travel returns and before RTC connects. getInfo() returns the same data; if a first frame exists, firstFrameGenerated follows.

error

(error: unknown) => void

A session runtime error.

Travel.can

Checks whether an action is available for the current status and session capability.

Signature

can(action: TravelAction): boolean

Parameters

Field

Type

Required

Description

action

TravelAction

Yes

Action to check: start / sendCommand / sendInstruct / pause / resume / rewind / end.

Returns

Returns a boolean. true means the action is currently available; false means the current status, mode, or session capability does not meet its preconditions.

Availability

action

Availability

start

Travel is still idle, has not been closed, and has never been started.

sendCommand

running, with Travel mode set to Adventure (1).

sendInstruct

running or paused, with mode set to Directing (2) or Acting (3), and not scriptlist.

pause

running, and the current session supports pausing.

resume

paused, and the current session supports resuming.

rewind

paused in a Directing session that supports rewind; Acting does not support it.

end

Travel has not been closed.

Errors

This method does not throw business errors. Unknown actions return false.

Travel.start

Starts the current Travel session.

Signature

start(): Promise<StartTravelResult>

Parameters

No parameters.

Returns

Returns a Promise<StartTravelResult>, which resolves after the session starts and the video becomes playable. After enter-travel returns, the SDK emits travelInfoReady before connecting RTC. Late subscribers can call travel.getInfo(); it returns null before the metadata is available. If the response includes a non-empty firstFrame, firstFrameGenerated still follows.

StartTravelResult

Field

Type

Description

encryptedTravelId

string

Current Travel session ID.

mode

number

Session mode: 1 = Adventure (world exploration), 2 = Directing (real-time Directing), 3 = Acting.

creationModel

string

World creation model; common values are simple and scriptlist.

firstFrame

string | null

First-frame image URL; null if the server does not return one.

maxExperienceTimeSec

60 | 90 | 120 | null

Maximum Adventure experience duration, in seconds. null for Directing and Acting sessions or when the server does not return this field.

aspectRatio

"9:16" | "16:9" | null

Acting aspect ratio; null for other modes or when the server does not return it.

Errors

start() rejects and emits an error event in the following cases. Use isSdkError(err) to check the error and read err.code and err.message.

ErrorCode

Description

10010002

SDK feature is disabled (SDK_FEATURE_DISABLED)

10020101

Unable to start: the current status does not allow it, Open Platform is not configured, or entering the session failed

10020102

Unable to start: the session configuration returned by the server is incomplete

10020103

Unable to start: video stream connection failed or the SDK feature-flag request failed

10020104

Unable to start: timed out waiting for the video stream (uses the greater of streamReadyTimeout and the server's noStreamAutoEndTimeoutSec)

10020105

Unable to start: timed out waiting for the video to become playable (controlled by streamReadyTimeout; default: 15 seconds)

1000000110000012

Open Platform parameter, resource, or server error

Travel.on("statusChanged")

Subscribes to session status changes.

Signature

on("statusChanged", handler: (status: TravelStatus) => void): () => void

Parameters

Field

Type

Required

Description

handler

(status: TravelStatus) => void

Yes

Callback invoked when the status changes.

Returns

Returns an unsubscribe function. TravelStatus is one of idle / prepare / running / paused / completed.

Errors

This method does not throw business errors.

Travel.on("firstFrameGenerated")

Subscribes to first-frame URL notifications.

Signature

on("firstFrameGenerated", handler: (firstFrame: string) => void): () => void

Parameters

Field

Type

Required

Description

handler

(firstFrame: string) => void

Yes

Callback invoked when the first-frame URL is available.

Returns

Returns an unsubscribe function.

Behavior

Emitted only during travel.start(). After the SDK calls Open Platform enter-travel and receives a non-empty firstFrame, it emits the event immediately—usually after statusChanged("prepare") but before start() resolves and the video becomes playable. The event is not emitted if the response contains no first-frame URL.

Errors

This method does not throw business errors.

Travel.onError

Subscribes to session runtime errors.

Signature

onError(handler: (error: unknown) => void): () => void

Parameters

Field

Type

Required

Description

handler

(error: unknown) => void

Yes

Callback invoked when a runtime error occurs.

Returns

Returns an unsubscribe function. Use isSdkError to narrow the error object to SdkError.

Errors

This method does not throw business errors.

Travel.sendCommand

Sends a real-time control command.

Signature

sendCommand(params: AdventureCommand): Promise<void>

Parameters

AdventureCommand

Field

Type

Required

Description

translation

string

No

Movement direction. Defaults to None when omitted.

rotation

string

No

View rotation. Defaults to None when omitted.

interaction

string

No

Interaction action. Defaults to None when omitted.

Control Command Reference

translation — Movement Direction
Describes character movement, supporting eight directions and combinations.

Value

Direction

"Front"

Forward

"Back"

Backward

"Left"

Left

"Right"

Right

"Front_Left"

Forward-left

"Front_Right"

Forward-right

"Back_Left"

Backward-left

"Back_Right"

Backward-right

"None"

Stationary

rotation — View Rotation
Simulates mouse-based view rotation in eight directions.

Value

Direction

"Mouse_Up"

Up

"Mouse_Down"

Down

"Mouse_Left"

Left

"Mouse_Right"

Right

"Mouse_Up_Left"

Up-left

"Mouse_Up_Right"

Up-right

"Mouse_Down_Left"

Down-left

"Mouse_Down_Right"

Down-right

"None"

None

interaction — Interaction Action

Value

Action

"Jump"

Jump

"Attack"

Attack

"Crouch"

Crouch

"Sprint"

Sprint

"None"

None

Returns

Returns a Promise<void> that resolves after the command is submitted.

Errors

sendCommand() rejects in the following cases:

ErrorCode

Description

10010001

params or a movement, rotation, or interaction parameter is invalid

10020501

The current status or session mode does not allow commands, or the video-stream command failed

Travel.sendInstruct

Sends Directing instructions or prompt content.

Signature

sendInstruct(params: InstructData): Promise<void>

Parameters

InstructData

Field

Type

Required

Description

content

string

Yes

Prompt content to send.

Returns

Returns a Promise<void> that resolves after Open Platform receives and processes the instruction.

Errors

sendInstruct() rejects and emits an error event in the following cases:

ErrorCode

Description

10020101

The session has not started

10020601

Failed to send the Directing instruction

1000000110000012

Open Platform parameter, resource, or server error

Travel.pause

Pauses the current session.

Signature

pause(): Promise<void>

Parameters

No parameters.

Returns

Returns a Promise<void> that resolves after video playback stops.

Errors

pause() rejects in the following cases:

ErrorCode

Description

10020201

The current status, session mode, or session capability does not allow pausing, or the pause request failed

10020202

Timed out waiting for the backend to report the video stream as paused (15 seconds)

1000000110000012

Open Platform parameter, resource, or server error

Travel.resume

Resumes a paused session.

Signature

resume(): Promise<void>

Parameters

No parameters.

Returns

Returns a Promise<void> that resolves after the video becomes playable again.

Errors

resume() rejects in the following cases:

ErrorCode

Description

10020301

The current status, session mode, or session capability does not allow resuming, or the resume request failed

10020302

Timed out waiting for the video to become playable again (15 seconds)

1000000110000012

Open Platform parameter, resource, or server error

Travel.rewind

Rewinds the current session to the specified time.

Signature

rewind(params: RewindTravelParams): Promise<RewindTravelResult>

Parameters

RewindTravelParams

Field

Type

Required

Description

rewindToSec

number

Yes

Target time in seconds. Only multiples of 4 are supported (for example, 4, 8, or 12). The server rounds other values down (for example, 7 becomes 4).

Returns

Returns a Promise<RewindTravelResult> that resolves after rewind completes and playback resumes.

RewindTravelResult

Field

Type

Description

resumedAtSec

number

The actual time in seconds at which the server resumed playback.

Errors

rewind() rejects and emits an error event in the following cases:

ErrorCode

Description

10020101

The session has not started

10020401

Unable to rewind: the session must first be paused and video playback stopped, or the rewind request or RTC reconnection failed

10020402

Timed out waiting for video to resume after rewind (15 seconds)

1000000110000012

Open Platform parameter, resource, or server error

Travel.end

Ends the current session and releases its resources.

Signature

end(): Promise<void>

Parameters

No parameters.

Returns

Returns a Promise<void> that resolves after cleanup finishes.

Errors

Cleanup errors are not thrown to the caller; end() makes a best effort to release resources.

Error Handling

The SDK exposes runtime errors through Promise rejections or error events. Errors are SdkError objects; use isSdkError(err) and read err.code and err.message. Recognized Open Platform errors map to the 1000000110000012 range, and err.message contains the platform message. See each Travel API's Errors section for method-specific codes.

ErrorCode Reference

Error-code ranges:
  • 100000xx: Mapped Open Platform errors
  • 1001xxxx: Engine client errors
  • 1002xxxx: Travel client errors

code

name

Description

10000001

OPEN_PLATFORM_PARAM_INVALID

Invalid request parameters (returned by Open Platform)

10000002

OPEN_PLATFORM_RESOURCE_NOT_FOUND

Resource not found (Travel missing, not owned, in another workspace, or artifact not ready)

10000003

OPEN_PLATFORM_WORLD_NOT_OWNED

World does not exist, was deleted, or does not belong to the current developer

10000004

OPEN_PLATFORM_SYSTEM_ERROR

System error

10000005

OPEN_PLATFORM_TICKET_INVALID

Ticket is invalid or expired

10000006

OPEN_PLATFORM_TICKET_USED

Ticket has already been used (one-time credential)

10000007

OPEN_PLATFORM_WORLD_NOT_READY

World is not ready and cannot be entered

10000008

OPEN_PLATFORM_INFERENCE_ALLOCATE_FAILED

Inference resource allocation failed (insufficient capacity, stream creation failure, session initialization failure, etc.)

10000009

OPEN_PLATFORM_MAIN_API_KEY_REQUIRED

This API accepts only the primary API Key (temporary API Keys are not supported)

10000010

OPEN_PLATFORM_CONTENT_MODERATION

Input rejected by content moderation

10000011

OPEN_PLATFORM_CONTENT_COPYRIGHT

Input image violates copyright or IP policy

10000012

OPEN_PLATFORM_STATE_CONFLICT

Request conflicts with the current resource state

10010001

INVALID_ARGUMENT

SDK client argument validation failed (not mapped from Open Platform)

10010002

SDK_FEATURE_DISABLED

SDK feature is disabled

10010101

ACTIVE_TRAVEL_EXISTS

A Travel is already active

10020001

STREAM_DISCONNECTED_WHILE_PLAYING

Video stream disconnected during playback

10020101

START_REQUEST_FAILED

Session start request failed

10020102

START_RTC_CONFIG_MISSING

Video stream configuration missing during startup

10020103

START_JOIN_CHANNEL_FAILED

Video stream connection failed

10020104

START_REMOTE_USER_TIMEOUT

Timed out waiting for the video stream

10020105

START_STREAM_TIMEOUT

Timed out waiting for the video to become playable

10020201

PAUSE_REQUEST_FAILED

Pause request failed

10020202

PAUSE_STREAM_TIMEOUT

Timed out waiting for video to pause

10020301

RESUME_REQUEST_FAILED

Resume request failed

10020302

RESUME_STREAM_TIMEOUT

Timed out waiting for video to resume

10020401

REWIND_REQUEST_FAILED

Rewind request failed

10020402

REWIND_STREAM_TIMEOUT

Timed out waiting for video to resume after rewind

10020501

SEND_COMMAND_FAILED

Failed to send the real-time control command

10020601

INSTRUCT_REQUEST_FAILED

Failed to send the Directing instruction

10020701

END_REQUEST_FAILED

Session end request failed

Other Exports

Runtime exports

Export

Type

Description

HappyOysterEngine

class

SDK client that configures Open Platform, updates the token, and creates Travel sessions.

HappyOysterEngine.version

string

The current SDK version.

HappyOysterEngine.metadata

SDKMetadata

The current SDK package name, version, and package channel.

ErrorCode

const

The error-code constant object exported by the SDK.

isSdkError

function

Checks whether an unknown error is a standard SDK error.

ErrorCode

The error-code constant object exported by the SDK. Compare it with SdkError.code instead of scattering numeric literals through application code.
import { ErrorCode } from '@happy-oyster/js-sdk'

isSdkError

Checks whether an unknown error is a standard SDK error. When it returns true, TypeScript narrows the error to SdkError, allowing safe access to code and message.
isSdkError(error: unknown): error is SdkError
try {
  await travel.start()
} catch (err) {
  if (isSdkError(err) && err.code === ErrorCode.OPEN_PLATFORM_TICKET_INVALID) {
    // Request a new Travel ticket, then create a new Travel.
  }
}

Public Types

The following types are exported from the package entry point and can be imported directly from @happy-oyster/js-sdk. They exist only at TypeScript compile time and produce no runtime code.

Type

Description

SDKConfig

HappyOysterEngine constructor parameter type.

LogLevel

SDK log levels: verbose / debug / info / warn / error / none.

SDKMetadata

SDK package metadata: version, packageName, packageChannel.

SDKPackageChannel

SDK package channels: internal / public / unknown.

CreateTravelConfig

createTravel(config) parameter type.

StartTravelResult

start() session metadata returned when the Promise resolves.

TravelInfo

Session metadata used by travelInfoReady, getInfo(), and StartTravelResult.

TravelAspectRatio

Acting aspect ratio: "9:16" / "16:9".

Travel

createTravel() public session contract returned by the method.

TravelStatus

Local SDK session states: idle / prepare / running / paused / completed.

TravelAction

can(action) supported action names.

AdventureCommand

sendCommand(params) parameter type.

InstructData

sendInstruct(params) parameter type.

RewindTravelParams

rewind(params) parameter type.

RewindTravelResult

rewind(params) data returned when the Promise resolves.

SDKError

SDK error shape containing code and message.

SdkError

Error type combining runtime Error and SDKError.

ErrorCodeValue

Union of all error-code values in the ErrorCode object.

HappyOyster Web SDK API Reference - QwenCloud