Cosmo Realtime SDK
Quickstart

Quickstart

Pick your language and have a working voice session in under five minutes.

All three SDKs speak the same wire protocol and follow the same three-tier model: a client holds your credential, an agent is a reusable persona (instructions, voice, tools), and a session is one live run.

PackageLanguageEntry point
cosmo-aiTypeScript / Reactnew RealtimeClient({...})client.agent({...}).start()
cosmo-ai-sdkPython (asyncio)CosmoRealtime(api_key=...)client.agent(...).start()
CosmoRealtimeSwiftRealtimeSession.start(.init(apiKey:baseURL:), config:)

Every quickstart needs a workspace API key with the realtime:use scope — see API keys. The key scopes your workspace server-side; there is no project ID to pass.

TypeScript / React

npm install cosmo-ai
import { RealtimeClient } from 'cosmo-ai';

const client = new RealtimeClient({ baseUrl: 'https://app.askcosmo.ai', apiKey });
const session = await client
  .agent({ instructions: 'You are a terse voice assistant.' })
  .start();

session.on('transcript', (item) => {
  if (item.isFinal) console.log(`[${item.role}] ${item.text}`);
});

Full TypeScript quickstart →


Python

pip install cosmo-ai-sdk
async with CosmoRealtime(api_key=os.environ["COSMO_API_KEY"]) as client:
    agent = client.agent(instructions="You are a terse voice assistant.")
    async with agent.start() as session:
        await session.set_microphone_enabled(True)
        await session.set_speaker_enabled(True)
        async for event in session:
            ...

Full Python quickstart →


Swift (macOS / iOS)

// Package.swift dependency:
// .package(url: "https://github.com/socratic-ai/cosmo-swift-sdk", from: "0.1.0")
let session = try await RealtimeSession.start(
    .init(apiKey: apiKey, baseURL: URL(string: "https://app.askcosmo.ai")!),
    config: SessionConfig(instructions: "You are a terse voice assistant.")
)

for try await event in session.events {
    // .ready, .transcript, .error, .sessionEnded, …
}

Full Swift quickstart →

On this page