Fetch the complete documentation index at https://www.nativecluster.com/llms.txt

# How do I call NativeCluster's models from code?

> NativeCluster speaks OpenAI's format. On a Mac running NativeCluster, call `http://localhost:8487/v1` with the key `nativecluster env` writes. From another computer on the office network, call the main at its `.local` name on port 8485, over TLS, with a Developer key. Swap the base URL and the key, and nothing else changes.

## Two places, two credentials

| Where your code runs | Base URL | Credential |
|---|---|---|
| On a Mac running NativeCluster (the main, or a Mac that joined it) | `http://localhost:8487/v1` | the session `nativecluster env` writes (`nct_…`), made for you and good only on that Mac; or a Developer key (`nck_…`) |
| On another computer on the office network (a Windows PC, a Linux server, a Mac without NativeCluster) | `https://<the main's .local name>:8485/v1` | a Developer key (`nck_…`) |

An `nct_` session never works from another computer: it answers only at the local address on the Mac where it was made. Keep the two apart.

## On a Mac running NativeCluster: the local address

```sh
nativecluster env
. '<the path it printed>'
```

That sets `OPENAI_BASE_URL` to `http://localhost:8487/v1`, and `OPENAI_API_KEY` and `NATIVECLUSTER_API_KEY` to a session made from the command's own sign-in. See [The nativecluster command](https://www.nativecluster.com/docs/cli.md) for `env`.

- **Plain HTTP, on this Mac only.** It answers connections from `127.0.0.1` and `[::1]` alone, and only a `Host` of `localhost`, `127.0.0.1` or `[::1]` (anything else is `403` `local_only`). There's no certificate to install, and no CORS: a web page can't call it.
- **The same on every Mac running NativeCluster.** On the main it answers itself. On a Mac that joined a main, it passes each call on to the main, which answers it as its own.
- **The session is yours.** Its calls wait in the same line as everyone's, and Usage shows them with your name. An owner or administrator can switch the nativecluster command's models off for a person on Members; then every call is `403` `not_given`.
- **Its model list is the models that code.** With an `nct_` session, `GET /v1/models` lists the chat models that can code (they use tools and have a coding score), the best coder first, and nothing of another kind. Every other model the cluster has still answers when a call names it: `nativecluster models list` shows them all.

## From another computer: the main's API door

A computer without NativeCluster reaches the main directly, on the office network:

- **Address:** the main's `.local` name, port **8485**, never an IP address. It answers only the office network: loopback, private and link-local ranges. On a network shared with strangers, such as a coworking space's Wi-Fi, that is everyone on it: they still need a key.
- **TLS 1.3**, under the main's own certificate authority. The client trusts that certificate itself (**Download certificate** in the API app): give it to the tool or script that calls the API, rather than trusting it for the whole computer, and never turn certificate checks off to make it work.
- **Open only while the API is on** on the main and a live key exists; otherwise nothing listens there.
- **A Developer key**, below.

Reaching the cluster from the internet or a cloud server is not built: today your code runs on one of the cluster's Macs, or on the office network.

## Developer keys

- A key looks like `nck_<id>_<secret>`. NativeCluster keeps only a fingerprint of the secret, never the key itself.
- **Who makes them** (since 0.4.23): owners and admins always; Developers too, and Users once an owner or admin turns it on. Settings › Members › Roles has an **API** switch for each role, Developer on and User off at first. They make keys in the API app on Apps or with `nativecluster keys create <name>`, from a computer on the office network. (Before 0.4.23, each computer's Mac owner made them.) The command writes the secret to a file only you can read and prints the path. The API app shows it once.
- A key belongs to a person (it stops while they're turned off) or to a service account. It expires in 30 days unless chosen otherwise, 90 at most, and `keys revoke` stops it at once. Since 0.4.19, a key revoked on a Mac lent to the main is refused on that Mac at once, and never passed on to the main.
- **Keys work only while the API is on, and while their maker's role can use it.** `nativecluster keys on` turns it on once the person confirms it with Touch ID or the Mac's password (since 0.4.17). Turning a role's API off keeps its people's keys: their calls are refused, `403` `no_api`, until it's on again (since 0.4.23). The apps your groups give, such as a coding tool that signs in as you, and the nativecluster command don't need it. `nativecluster keys off` turns it off.
- A key reaches the models and nothing else: no app's data and no people.
- Handing a key to someone else, such as a teammate on a Windows PC, is the person's to do, through a channel they trust. An agent never prints, pastes or sends a key.

## Routes

| Route | For |
|---|---|
| `GET /v1/models` | the models you may use |
| `POST /v1/chat/completions` | chat, with `messages`, `tools`, `tool_choice`, `stream`, `stream_options`, `max_tokens`, `temperature`, `top_p`, `stop`, `seed`, `response_format`, `user` |
| `POST /v1/embeddings` | search (embedding) models |
| `POST /v1/audio/transcriptions` | speech to text |
| `POST /v1/audio/speech` | text to speech |
| `POST /v1/audio/diarizations` | who spoke when |
| `POST /v1/images/generations` | pictures |

Each route other than chat answers only where the cluster has a model of that kind. At the local address any other path is `404`. At the main's port 8485 any other path is `401`, the same as a bad key, so check the path as well as the key.

### `GET /v1/models`

```json
{"object":"list","data":[{"id":"qwen3.8:27b","object":"model","created":0,"owned_by":"nativecluster","kind":"chat", …}]}
```

- With a Developer key: the chat models first, then every model of another kind the cluster holds, each with its `kind` (`embedding`, `stt`, `tts`, `image`).
- Each chat model also says `context_length` (its window on the Mac that runs it, which a prompt and its answer share), `max_output_tokens` (the answer a tool should ask for so its calls run beside others), `capabilities` (`completion`, `tools`, `thinking`, `vision`) and, when the cluster measured it, `good_for: ["coding"]`.
- A model nobody has downloaded is never listed.

### `POST /v1/chat/completions`

- `model` must be a chat model the cluster has; another is `404` `model_not_found`, naming the ones you may use.
- `think`: `true` or `false` on a model whose `capabilities` name `thinking`.
- `num_ctx`, `images` and `keep_alive` are refused (`400` `unsupported_parameter`). Other fields, such as `frequency_penalty` or `reasoning_effort`, are dropped.
- Message content is text, or parts of type `text` and `image_url` (a `data:` URI, for a model that reads pictures).
- Streaming: while a call waits its turn, an SSE comment `: waiting` arrives every 10 seconds (since 0.4.23 it says why and about how long, such as `: waiting: 1 call ahead on the Mac Studio, about 20 s`, then `: waiting: reading the prompt, about 12 s left`; a client passes over comments); the answer ends with its finish chunk (`stop`, `tool_calls`, or `length`), the usage chunk if you asked for it, and `data: [DONE]`. A tool call arrives whole, in one chunk.

## Errors you can act on

| Status and code | What it means, and what to do |
|---|---|
| `401` `invalid_api_key` | Any failed key, and the same answer for all: no key, a wrong, revoked or expired one, or its person turned off. Check the key, or make a new one. |
| `404` `model_not_found` | Name a model `GET /v1/models` or `nativecluster models list` shows. |
| `400` `context_length_exceeded` | The prompt leaves no room to answer: shorten the conversation, or start a new one. |
| `429` `rate_limit_exceeded` | Past a key's limit (below): wait the `Retry-After` seconds. |
| `503` `model_unavailable` | The Macs that have the model take no new work now (on battery, or short of memory). Its words name them. |
| `503` `engine_unavailable` | The main is restarting, something other than the cluster's own requests (such as other programs) holds the memory a computer needs, or (since 0.4.19) the Mac running the call is too busy to take it: retry after `Retry-After`. Since 0.4.23, a request that needs memory the cluster's own requests hold waits in line for them instead. |
| `400` `stopped_by_administrator` | An administrator stopped this work on Usage. |
| `409` `not_in_cluster` | This Mac isn't in a cluster yet, or hasn't finished joining. |
| `503` `main_unreachable` | A joined Mac can't reach its main: it may be asleep, or the API may be off there. |
| `503` `cluster_away` | An `nct_` session away from its cluster's network that this Mac doesn't answer itself. Since 0.4.20 a computer turned on for inference answers its administrator's sessions from its own models: see [Away from the office](https://www.nativecluster.com/docs/cluster.md#away-from-the-office). |
| `403` `not_given` | This person isn't given that tool on Members, or isn't one of the group's people now. |
| `503` `no_model_fits` | None of the cluster's computers can run a model that codes (`nct_` sessions). |
| `403` `developer_keys_off` | The API is off on the main: its Mac owner turns it on with `nativecluster keys on`, or in Settings › Developer. |

Errors use OpenAI's shape: `{"error": {"message", "type", "code"}}`.

## Limits

- Per key: one call running on each Mac that runs its model, and up to 8 waiting beside them. Past that, `429` with `Retry-After`. There is no quota: no calls a minute, and no minutes a day.
- A request body is at most 8 MiB.
- A client that stops reading holds the Mac at most 30 seconds before its call is cancelled.

## Sharing the Macs

A key's calls wait in the main's one fair line with people's requests and apps' background work, with no ranking between them: the app or key that has used the least of the Mac's time lately goes next, weighted by its share (a key's Priority: Low, Normal or High). A call runs beside others when its Mac has room, and once it runs, it runs to its end. See [Usage: one line](https://www.nativecluster.com/docs/usage.md).

## What stays

Nothing a call sends is stored or logged, at the main or a joined Mac: no body, no word, no key. Each call leaves one row of numbers (the key, the person who answers for it, the route, the model, how long it waited and ran, its token counts), which Usage shows as the key's name, model, requests and minutes. Whoever controls the group's Macs controls that hardware: see [Privacy](https://www.nativecluster.com/docs/privacy.md).

## Examples

```sh
curl -s "$OPENAI_BASE_URL/chat/completions" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "qwen3.8:27b", "messages": [{"role": "user", "content": "Say hello in five words."}]}'
```

```python
from openai import OpenAI

client = OpenAI()  # reads OPENAI_BASE_URL and OPENAI_API_KEY
reply = client.chat.completions.create(
    model="qwen3.8:27b",
    messages=[{"role": "user", "content": "Say hello in five words."}],
)
print(reply.choices[0].message.content)
```

Use a model your cluster has: `nativecluster models list` shows them.
