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. Package names and entry points live in the package table on the landing page; the sections below show the same thing as runnable code.

Set up first

Every quickstart below needs a credential, and the recommended way to get one is the CLI:

curl -fsSL https://platform.askcosmo.ai/docs/install.sh | sh
cosmo init

That signs you in through the browser, stores a key the SDKs find on their own, and equips your coding agent — see Set up with the CLI for the whole picture, or API keys for creating a key by hand instead. Either way the key scopes your workspace server-side, with no project ID to pass.

TypeScript / React

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

const client = new RealtimeClient({ apiKey });
const session = await client
  .agent({ instructions: 'You are a terse voice assistant.' })
  .start();

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

Full TypeScript quickstart →

Python

pip install cosmo-ai-sdk
async with RealtimeClient(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)

let client = RealtimeClient(apiKey: apiKey)
let agent = try client.agent(instructions: "You are a terse voice assistant.")
let session = try await agent.start()

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

Full Swift quickstart →

On this page