# Core API

Call models, knowledge, your agent, speech and phone calls from your own backend, with one scoped token and spend recorded against your workspace.

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

The Core API is how your own server uses Omazy. One token reaches the model
gateway, your knowledge base, your agent, speech in both directions and
outbound phone calls.

```
https://mw.omazy.ai/api/v1/core
```

It is called over HTTP with JSON. There is no client library to install, and
none is needed: every example on these pages is `curl` or `fetch`.

## What it is for

You are building something of your own (a back office, a mobile app's server, a
nightly job) and it needs an answer from a model, a passage from your knowledge
base, or your agent's reply to a question. Without this API you would put a
model vendor's key in your own server and lose sight of what it spends.

With it, your server holds one Omazy token and no vendor key. Every model call
is recorded against your workspace as Core API usage under that token. It counts
toward the same budgets and passes the same guards as your agent's own traffic,
so one place shows what was spent and one place can stop it.

| You want | Call | Page |
|---|---|---|
| A model's answer, streamed or whole | `POST /ai/complete` | [Completions](/reference/core-api/completions/) |
| Passages from your knowledge base | `POST /knowledge/search` | [Knowledge and agent](/reference/core-api/knowledge-and-agent/) |
| Your agent's reply to a message | `POST /agent/turn` | [Knowledge and agent](/reference/core-api/knowledge-and-agent/) |
| Your agent moved to another model, or its switches changed | `GET` and `PATCH /agent/settings` | [Agent settings](/reference/core-api/agent-settings/) |
| Your knowledge base written from your backend | `POST /knowledge/documents` and others | [Knowledge documents](/reference/core-api/knowledge-documents/) |
| Text read aloud, or a recording as text | `POST /voice/speak`, `POST /voice/transcribe` | [Speech and calls](/reference/core-api/speech-and-calls/) |
| A phone call placed by your agent | `POST /voice/calls` | [Speech and calls](/reference/core-api/speech-and-calls/) |
| A long recording transcribed, or meeting notes | `POST /voice/jobs` | [Speech and calls](/reference/core-api/speech-and-calls/) |
| Customer records and messages into a conversation | `GET /customers/{id}` and others | [Data and messages](/reference/core-api/data-and-messages/) |
| The same verbs as tools, for an MCP client | `POST /mcp` | [MCP](/reference/core-api/mcp/) |

## How it differs from the console API and the widget

Omazy has three doors. They are easy to confuse because all three end up
talking to the same agent.

| | Console API | Widget | Core API |
|---|---|---|---|
| Who calls it | A signed-in person, or the CLI on their behalf | A visitor's browser | Your server |
| Credential | That person's access token | A public key that is safe in page source | A `cai_` token that must stay on a server |
| What it may do | Whatever the person's role allows | Hold one conversation as a visitor | Only what the token's scopes name |
| Where it lives | [API](/reference/api/) | [Widget](/how-to/widget/) | These pages |

The console API manages a workspace: it is what the console and the
[CLI](/reference/cli/) use to edit a brief or read a report. The Core API does
not manage anything. It uses what you have already set up.

If you were looking for "the SDK for my app", this is it, with one correction:
it is an HTTP API, not a package. The [SDK](/reference/sdk/) section documents
something else, the Python SDK for writing plugins.

## Quickstart

Five minutes, assuming you have a token. If you do not, read
[Authentication](/reference/core-api/authentication/) first: a workspace owner
creates one.

### 1. Put the token in your server's environment

```sh
export OMAZY_CORE_TOKEN="cai_<prefix>.<the-rest-of-your-token>"
```

### 2. Check the token

`/whoami` needs no scope, so it works with any valid token. It is the cheapest
way to find out which workspace a token belongs to and what it may do.

```sh
curl https://mw.omazy.ai/api/v1/core/whoami \
  -H "Authorization: Bearer $OMAZY_CORE_TOKEN"
```

```json
{
  "success": true,
  "data": {
    "install_id": "0d6c3a7e-3f3f-4b1b-9d0c-1f5a2f1c9a11",
    "workspace_id": "5b0c1c5e-8f0e-4a55-9a51-2f6d1f3f6a10",
    "app_slug": "backoffice",
    "scopes": ["ai:complete", "kb:search"],
    "status": "active",
    "token": "current"
  }
}
```

### 3. Ask a model something

This needs the `ai:complete` scope.

```sh
curl https://mw.omazy.ai/api/v1/core/ai/complete \
  -H "Authorization: Bearer $OMAZY_CORE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "system": "You answer in one sentence.",
    "messages": [{ "role": "user", "content": "What is a webhook?" }]
  }'
```

```json
{
  "success": true,
  "data": {
    "text": "A webhook is an HTTP request one system sends another when something happens.",
    "stop_reason": "stop",
    "model": "openai/gpt-4o",
    "usage": { "input_tokens": 24, "output_tokens": 17, "cached_input_tokens": 0 }
  }
}
```

You did not choose a model. Left alone, a completion runs on the model your
agent answers on, so changing the agent's model in the console changes this
too. [Completions](/reference/core-api/completions/#which-model-runs) explains
how to pick another.

### 4. The same call from code

```ts
const res = await fetch('https://mw.omazy.ai/api/v1/core/ai/complete', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.OMAZY_CORE_TOKEN}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    system: 'You answer in one sentence.',
    messages: [{ role: 'user', content: 'What is a webhook?' }],
  }),
})

const body = await res.json()
if (!body.success) throw new Error(`${body.error.code}: ${body.error.message}`)

console.log(body.data.text)
```

Check `success` and read `error.code`. Every JSON response on this API has the
same outer shape, described in
[Errors and limits](/reference/core-api/errors-and-limits/).

## Which app a call runs against

A workspace holds one or more apps, and each app has its own agent, knowledge
and voice. A token belongs to the workspace, not to one app.

When the workspace has exactly one active app, you never name it. When it has
more than one, every call that touches an app must say which, with the app's
handle in an `app` field (or an `app` query parameter on routes that take no
JSON body). Leave it out and you get a `400` telling you to name it.

This is deliberate. A guess that is right today becomes a wrong answer on the
day somebody adds a second app, and nothing would tell you.

## Next

- [Authentication](/reference/core-api/authentication/): the token and its scopes
- [Completions](/reference/core-api/completions/): tools, model choice, streaming
- [API explorer](/explorer/): every route with its request and response, and a console to send a request from the browser
- [Client libraries](/reference/core-api/client-libraries/): TypeScript, Python and Go
- [Changelog](/reference/core-api/changelog/): what changed, and what a client has to do about it
- [Call Omazy from your own backend](/guides/call-omazy-from-your-backend/): a worked path from token to a grounded, streamed answer
