Ticos Realtime API
Official WebSocket-based Realtime API SDK for Ticos. This SDK provides real-time communication capabilities for building interactive AI applications.
Features
- 🚀 Real-time bidirectional communication
- 🎯 Support for text, audio, and image messages
- 🛠️ Function calling and tool registration
- 🔄 Session management
- 💬 Conversation state tracking
- 🔒 Enhanced error handling and type safety
- 📦 TypeScript support out of the box
Quick Start
The fastest way to see the SDK in action is to run the demo project:
git clone https://github.com/tiwater/ticos-realtime-api.git
cd ticos-realtime-api
pnpm install
pnpm build
cd examples/realtime-chat
pnpm install
echo "NEXT_PUBLIC_TICOS_API_KEY=your_api_key_here" > .env.local
echo "NEXT_PUBLIC_TICOS_API_URL=wss://stardust.ticos.cn/realtime" >> .env.local
pnpm dev
Then open http://localhost:3000 with your browser to see the chat demo in action.
Installation
To use the SDK in your own project:
pnpm add @ticos/realtime-api
npm install @ticos/realtime-api
yarn add @ticos/realtime-api
Basic Usage
import { RealtimeClient } from '@ticos/realtime-api';
const client = new RealtimeClient();
await client.connect();
client.sendUserMessageContent([{ type: 'text', text: 'Hello, Ticos!' }]);
client.on('conversation.updated', (event) => {
if (event.item.role === 'assistant') {
console.log('Assistant response:', event.item.formatted.text);
}
});
const { item } = await client.waitForNextCompletedItem();
console.log('Completed response:', item);
Documentation
API documentation is automatically generated using TypeDoc. To generate the documentation, run:
pnpm docs:generate
This will generate HTML documentation in the docs directory.
To convert the TypeDoc HTML documentation to Nextra-compatible Markdown format:
pnpm docs:convert
To generate documentation and convert it to Nextra format in one step:
pnpm docs:nextra
To serve the generated documentation locally:
pnpm docs:serve
Core Functionality
Real-time Communication
The Ticos Realtime API enables real-time bidirectional communication between your application and Ticos AI models through WebSockets.
Function Calling and Tool Registration
Register custom tools that can be called by the AI:
client.registerTool(
{
name: 'search',
description: 'Search for information',
parameters: {
type: 'object',
properties: {
query: { type: 'string', description: 'Search query' },
},
required: ['query'],
},
},
async (parameters) => {
const result = await yourSearchImplementation(parameters.query);
return result;
}
);
client.on('conversation.item.completed', (event) => {
console.log('Item completed:', event.item);
});
Audio Support
Send and receive audio messages:
const audioBuffer = new Int16Array([
]);
client.sendUserMessageContent([{ type: 'audio', audio: audioBuffer }]);
client.appendInputAudio(audioBuffer);
client.createResponse();
client.on('conversation.updated', (event) => {
if (event.item.formatted?.audio) {
const audioData = event.item.formatted.audio;
}
});
Development
pnpm install
pnpm build
pnpm test
pnpm documentation
pnpm dev
License
MIT