# SDKs (/docs/sdks)

Official TypeScript and Python clients for the codai gateway — zero dependencies, typed, with codai extensions built in.

Both SDKs are thin, dependency-free wrappers over the [gateway's HTTP API](../gateway/index.mdx). They exist so you do not have to hand-roll SSE parsing, tool-call assembly, retries or the `X-Codai-*` headers — and so codai extensions (sessions, agent mode, compaction, best-of) are one option away instead of a header you have to remember.

| | TypeScript | Python |
| --- | --- | --- |
| Package | [`codai-sdk`](https://www.npmjs.com/package/codai-sdk) 0.2.3 | [`codai-sdk`](https://pypi.org/project/codai-sdk/) 0.1.1 |
| Import | `import { Codai } from 'codai-sdk'` | `from codai import Codai` |
| Runtime | Node 18+, edge runtimes with `fetch` | Python 3.9+ |
| Dependencies | none | none (stdlib `urllib`) |
| Streaming | async iterator + `.final` metadata | generator of text deltas |
| Retries | `429` / `5xx`, exponential backoff, 2 by default | same |

## Install [#install]

<Tabs items={['pnpm', 'npm', 'pip', 'uv']}>
<Tab value="pnpm">

```bash
pnpm add codai-sdk
```

</Tab>
<Tab value="npm">

```bash
npm install codai-sdk
```

</Tab>
<Tab value="pip">

```bash
pip install codai-sdk
```

</Tab>
<Tab value="uv">

```bash
uv add codai-sdk
```

</Tab>
</Tabs>

## Thirty-second tour [#thirty-second-tour]

<Tabs items={['TypeScript', 'Python']}>
<Tab value="TypeScript">

```ts
import { Codai } from 'codai-sdk';

const codai = new Codai({ apiKey: process.env.CODAI_API_KEY!, sessionId: 'my-project' });

const res = await codai.chat({ messages: [{ role: 'user', content: 'hello' }] });
console.log(res.content, res.routedTo);

for await (const delta of codai.chatStream({ messages: [{ role: 'user', content: 'hi' }] })) {
  process.stdout.write(delta);
}

const run = await codai.agents.run({ task: 'Summarize the repo structure.' });
if (res.requestId) await codai.feedback(res.requestId, 1);
```

</Tab>
<Tab value="Python">

```python
import os
from codai import Codai

client = Codai(api_key=os.environ["CODAI_API_KEY"], session_id="my-project")

result = client.chat([{"role": "user", "content": "hello"}])
print(result.content, result.routed_to)

for delta in client.chat_stream([{"role": "user", "content": "hi"}]):
    print(delta, end="")

run = client.agents_run("Summarize the repo structure.")
if result.request_id:
    client.feedback(result.request_id, 1)
```

</Tab>
</Tabs>

## What both clients cover [#what-both-clients-cover]

| Surface | TypeScript | Python |
| --- | --- | --- |
| Chat (`/v1/chat/completions`) | `chat()` | `chat()` |
| Streaming chat | `chatStream()` | `chat_stream()` |
| Server-side agent (`/v1/agents/run`) | `agents.run()` | `agents_run()` |
| Feedback (`/v1/feedback`) | `feedback()` | `feedback()` |
| Models (`/v1/models`) | `models()` | `models()` |
| Ephemeral tokens (`/v1/tokens`) | `mintToken()` | `mint_token()` |
| Embeddings (`/v1/embeddings`) | `embeddings()` | `embeddings()` |
| Speech-to-text | `audio.transcribe()` | `transcribe()` |
| Text-to-speech | `audio.speech()` | `speech()` |

Anthropic Messages, the Responses API, realtime WebSockets, the receipt endpoint and the shared-sessions protocol are **not** wrapped yet — call them directly or through the OpenAI / Anthropic SDKs as shown in the [gateway quickstart](../gateway/index.mdx#already-using-an-sdk).

## Memory and skills are server-side [#memory-and-skills-are-server-side]

The memory tools (`memory_recall`, `memory_remember`) and skills (`use_skill`) are gateway-native: when you pass a stable `sessionId`, the model can invoke them during the request and the gateway executes them. There is nothing to call from the SDK beyond enabling a session.

<Cards>
  <Card title="TypeScript guide" href="./typescript.mdx" description="Configuration, streaming with .final, tool calls, agents, audio, errors, migrating from openai." />
  <Card title="Python guide" href="./python.mdx" description="Quickstart, every method, extensions table, error handling." />
</Cards>
