# 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 20+, Bun, Deno and Cloudflare Workers. Live speech needs a
runtime WebSocket that sends headers: Node 22+, Bun, Deno and Workers have
one, and the `webSocket` option takes another. 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.4.0/omazyai-sdk-0.4.0.tgz
```

### Python

Python 3.9+.

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

### Go

Go 1.22+.

```sh
go get github.com/omazyai/omazy-sdk/go@v0.4.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 |
| `contract()` | `GET /contract` | None, and no token: the route contract the live platform was built with, or its OpenAPI document with `{ format: 'openapi' }` |
| `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()`, `agent.stream()` | `POST /agent/turn` | `agent:run` |
| `agent.settings.get()`, `.update()` | `GET` and `PATCH /agent/settings` | `agent:configure` |
| `agent.mcpServers.list()`, `.get()`, `.create()`, `.update()`, `.delete()` | `/agent/mcp-servers` | `agent:tools` |
| `voice.speak()`, `voice.transcribe()` | `POST /voice/speak`, `POST /voice/transcribe` | `voice:speech` |
| `voice.transcribeStream()` | `GET /voice/transcribe/stream` (WebSocket) | `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` |
| `usage.get()` | `GET /usage` | `usage:read` |
| `mcp.listTools()`, `mcp.callTool()`, `mcp.config()` | `POST /mcp` | The tool's own |

## The Enterprise client

A product with one workspace per customer also uses `OmazyEnterprise`
(`omazy.NewEnterprise` in Go). It takes an account key, `eak_...`, and calls
the Enterprise API: it never calls a model.

| Method | Route | Scope |
|---|---|---|
| `account()` | `GET /enterprise/account` | None |
| `workspaces.create()` | `POST /enterprise/workspaces` | `workspaces:manage`, and `installs:manage` for the token |
| `workspaces.list()`, `.all()`, `.get()`, `.findByExternalId()` | `GET /enterprise/workspaces` | `workspaces:manage` |
| `workspaces.update()`, `.suspend()`, `.resume()` | `PATCH /enterprise/workspaces/{id}` | `workspaces:manage` |
| `workspaces.close()` | `DELETE /enterprise/workspaces/{id}` | `workspaces:manage` |
| `workspaces.rotateInstall()` | `POST /enterprise/workspaces/{id}/install/rotate` | `installs:manage` |
| `usage()` | `GET /enterprise/usage` | `usage:read` |
| `core(token)` | | The Core API client for one customer |

[Many customers](/build-on-omazy/many-customers/) walks through it.

## 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, on routes that read or compute and on changes the
API makes safe to repeat: changing or deleting a knowledge document, changing
the agent's settings, changing or removing one of its MCP servers. Placing a
call, posting a message, publishing, running an agent turn and adding
knowledge are sent once. A delete that is sent again after the first one went
through answers `NOT_FOUND`: the document or server is gone either way. 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.** Each response carries the request id, the rate limit,
the token's deadline and whether the answer was a replay. Read them for one
call like this:

```ts
const { result, response } = await omazy.withResponse((o) => o.ai.complete(req))
response.requestId
```

```python
with omazy.with_response() as response:
    answer = omazy.ai.complete(messages)
response.request_id
```

```go
var info omazy.ResponseInfo
res, err := c.AI.Complete(omazy.WithResponseInfo(ctx, &info), req)
info.RequestID
```

`omazy.last` (`Last()` in Go) holds the same for the client's most recent
response, whichever call it answered. When one client serves several requests
at once, as in a Worker or a server, it can belong to another request by the
time you read it. Use it only where one call runs at a time.

**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.4.0`. Their
changes are in the [SDK release notes](/build-on-omazy/release-notes/).
Changes to the API itself are in the [Changelog](/reference/core-api/changelog/).
