# Client libraries

The official TypeScript, Python and Go clients for the Core API: where to install each from, how they handle tokens, errors, retries and streaming, and the same calls over MCP.

Source: https://docs.omazy.ai/reference/core-api/client-libraries/

There is a client for TypeScript, Python and Go. Each covers every route on
this API under the same names, over HTTP and over the
[MCP server](/reference/core-api/mcp/). None has a dependency. The source is
public at [github.com/omazyai/omazy-sdk](https://github.com/omazyai/omazy-sdk)
under the MIT license.

You do not need one. Everything here is plain HTTP, the rest of this
reference shows it as `curl`, and the [API explorer](/explorer/) lets you send
a request from the browser. The API is also described as an
[OpenAPI document](/openapi/core-api.json), if you would rather generate a
client of your own. A client saves you the retry rules, the stream
parsing and the error handling.

## Install

### TypeScript

Runs on Node 18+, Bun, Deno and Cloudflare Workers. The package is
`@omazyai/sdk` on GitHub Packages. Add this to `.npmrc`, with a GitHub token
that can read packages:

```sh
@omazyai:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
```

```sh
npm install @omazyai/sdk
```

Without a GitHub token, install the same build from the release:

```sh
npm install https://github.com/omazyai/omazy-sdk/releases/download/v0.3.0/omazyai-sdk-0.3.0.tgz
```

### Python

Python 3.9+.

```sh
pip install https://github.com/omazyai/omazy-sdk/releases/download/v0.3.0/omazy-0.3.0-py3-none-any.whl
```

### Go

Go 1.22+.

```sh
go get github.com/omazyai/omazy-sdk/go@v0.3.0
```

## The token

A client takes one thing: a Core API token. A workspace owner creates it and
chooses its scopes, as [Authentication](/reference/core-api/authentication/)
describes. Keep it in your server's environment.

```ts
import { Omazy } from '@omazyai/sdk'

const omazy = new Omazy({ token: process.env.OMAZY_CORE_TOKEN! })
```

```python
import os
from omazy import Omazy

omazy = Omazy(os.environ["OMAZY_CORE_TOKEN"])
```

```go
import omazy "github.com/omazyai/omazy-sdk/go"

c := omazy.New(os.Getenv("OMAZY_CORE_TOKEN"))
```

## Check the account behind a token

`whoami` needs no scope. It says which workspace the token belongs to, what it
may do, when it expires, and what the workspace's plan allows.

```ts
const me = await omazy.whoami()

me.scopes                  // ['ai:complete', 'kb:search']
me.token                   // 'current', or 'previous' after a rotation
me.token_expires_at        // '2027-02-17T12:14:11Z'
me.plan?.rate_per_minute   // 60
me.plan?.ai_turns          // { used: 412, limit: 6000, resets_at: '2026-12-07T10:40:52Z' }
```

Python returns the same fields as a dictionary. Go returns them as a struct.

## A call

```ts
const answer = await omazy.ai.complete({
  system: 'You answer in one sentence.',
  messages: [{ role: 'user', content: 'What is a webhook?' }],
})
console.log(answer.text)
```

```python
answer = omazy.ai.complete(
    [{"role": "user", "content": "What is a webhook?"}],
    system="You answer in one sentence.",
)
print(answer["text"])
```

```go
res, err := c.AI.Complete(ctx, omazy.CompleteRequest{
	System:   "You answer in one sentence.",
	Messages: []omazy.Message{{Role: "user", Content: "What is a webhook?"}},
})
```

## Methods

The names below are the TypeScript ones. Python uses the same words in
`snake_case`, and Go in `PascalCase`. Each client's README lists its own.

| Method | Route | Scope |
|---|---|---|
| `whoami()` | `GET /whoami` | None |
| `ai.complete()`, `ai.stream()` | `POST /ai/complete` | `ai:complete` |
| `knowledge.search()` | `POST /knowledge/search` | `kb:search` |
| `knowledge.documents.list()`, `.get()` | `GET /knowledge/documents`, `GET /knowledge/documents/{id}` | `kb:read` |
| `knowledge.documents.create()`, `.update()`, `.delete()` | `POST`, `PATCH`, `DELETE /knowledge/documents` | `kb:write` |
| `knowledge.importFile()` | `POST /knowledge/import` | `kb:write` |
| `knowledge.sources.list()` | `GET /knowledge/sources` | `kb:read` |
| `knowledge.sources.create()`, `.crawl()` | `POST /knowledge/sources`, `POST /knowledge/sources/{id}/crawl` | `kb:write` |
| `knowledge.export()` | `GET /knowledge/export` | `kb:read` |
| `agent.turn()` | `POST /agent/turn` | `agent:run` |
| `voice.speak()`, `voice.transcribe()` | `POST /voice/speak`, `POST /voice/transcribe` | `voice:speech` |
| `voice.calls.place()`, `voice.calls.get()` | `POST /voice/calls`, `GET /voice/calls/{ref}` | `voice:calls` |
| `voice.jobs.create()`, `voice.jobs.get()` | `POST /voice/jobs`, `GET /voice/jobs/{id}` | `voice:tasks` |
| `customers.get()` | `GET /customers/{id}` | `core:read` |
| `customers.update()` | `PATCH /customers/{id}` | `memory:write` |
| `conversations.postMessage()` | `POST /conversations/{id}/messages` | `core:write` |
| `channels.linkedinPublish()` | `POST /channels/linkedin/publish` | `channels:publish` |
| `sessions.bindCredential()`, `sessions.unbindCredential()` | `PUT` and `DELETE /sessions/{sid}/mcp-credentials/{server}` | `sessions:credentials` |
| `mcp.listTools()`, `mcp.callTool()`, `mcp.config()` | `POST /mcp` | The tool's own |

## What a client does for you

**Errors.** A refusal is one error type with the HTTP status, the `code`, the
message, the request id and the `Retry-After` when there is one.

```ts
import { OmazyError } from '@omazyai/sdk'

try {
  await omazy.agent.turn({ message: 'hello' })
} catch (e) {
  if (e instanceof OmazyError && e.code === 'PLAN_LIMIT_REACHED') {
    // stop calling, and tell the workspace's owner
  }
  throw e
}
```

**Retries.** A `429`, `502`, `503`, `504` or a dropped connection is tried
again twice, with backoff, and only on routes that read or compute. Placing a
call, posting a message, publishing, running an agent turn and adding
knowledge are sent once. A `Retry-After` longer than 30 seconds is handed back
to you as an error and not waited out.

**Idempotency keys.** Give a request that changes something a key and the
client retries it the way it retries a read. The platform runs it once and
answers a repeat with the first answer. See
[Sending a request again](/reference/core-api/errors-and-limits/#sending-a-request-again).

```ts
await omazy.voice.calls.place(call, { idempotencyKey: 'delivery-48213-confirm' })
```

```python
omazy.voice.calls.place(to, "confirmation", "transaction", idempotency_key="delivery-48213-confirm")
```

```go
ctx := omazy.WithIdempotencyKey(ctx, "delivery-48213-confirm")
res, err := c.Voice.PlaceCall(ctx, call)
```

**Streaming.** A completion can be read as it is written. A stream that
reports an error, or stops before it is done, raises an error. You never get
half an answer that looks whole.

```ts
for await (const ev of omazy.ai.stream({ messages })) {
  if (ev.type === 'delta') process.stdout.write(ev.text)
}
```

**Response details.** After any call, `omazy.last` holds the request id, the
rate limit, the token's deadline and whether the answer was a replay, from the
response headers.

**MCP.** List and call the tools the token's scopes allow, or get the URL and
headers to hand to an MCP client of your own.

```ts
const tools = await omazy.mcp.listTools()
const hit = await omazy.mcp.callTool('knowledge_search', { query: 'opening hours' })
const server = omazy.mcp.config() // { type: 'http', url, headers }
```

**Signatures.** Each client verifies the `X-Omazy-Signature` on a request the
platform sends to your own server.

## Versions

The three clients share one version number. The current one is `0.3.0`. Their
changes are in the repository's
[CHANGELOG](https://github.com/omazyai/omazy-sdk/blob/main/CHANGELOG.md).
Changes to the API itself are in the [Changelog](/reference/core-api/changelog/).
