bots-garden/razorbillpublic Fork
⑂ v0.3.0
Commits
⬇ Clone ▾
git clone https://git.rickub.com/bots-garden/razorbill.git
git clone ssh://git@rickub.com/bots-garden/razorbill.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP
getting-started.md · 188 lines · 5.2 KBmarkdown
Blame HistoryOpen raw

Tutorial: your first requests to a local model

By the end of this tutorial, you will have a model running on your Mac's GPU behind an OpenAI-compatible API, and you will have talked to it twice: once with curl, once from a Python program that uses the official openai library.

No knowledge of MLX or of the OpenAI API is required.

Prerequisites

  • A Mac with Apple Silicon (M1 or later) and macOS 14 or later.

  • rzb built, as described in How to build rzb on the Mac. In this tutorial, rzb means .build/xcode/Build/Products/Release/rzb; to type it shorter, run this once in your terminal, from the repository root:

    alias rzb="$PWD/.build/xcode/Build/Products/Release/rzb"
    
  • About 400 MB of free disk space, and an internet connection for the first download.

  • uv for step 5 (brew install uv).

Step 1 — Download a small model

Type:

rzb models pull mlx-community/Qwen3-0.6B-4bit

A progress bar runs, then you should see:

mlx-community/Qwen3-0.6B-4bit is downloaded.

We now have a small model (0.6 billion parameters, 4-bit) in the Hugging Face cache on this Mac.

Step 2 — Start the server

Type:

rzb serve

You should see:

rzb 0.3.0 serving http://127.0.0.1:7920/v1 (no API key) — Ctrl-C to stop

The server is running and only accepts connections from this Mac. Leave this terminal open, and open a second terminal for the next steps.

Step 3 — Check that it answers

In the second terminal, type:

curl -s http://127.0.0.1:7920/health

You should see:

{"status":"ok"}

Now ask which models it can serve:

curl -s http://127.0.0.1:7920/v1/models | python3 -m json.tool

You should see a list that contains the model we downloaded:

{
    "data": [
        {
            "created": 1764096000,
            "id": "mlx-community/Qwen3-0.6B-4bit",
            "kind": "chat",
            "loaded": false,
            "object": "model",
            "owned_by": "razorbill"
        }
    ],
    "object": "list"
}

"loaded": false: the model is on disk but not in memory yet. It will be loaded by the first request.

Step 4 — Ask a question with curl

Type:

curl -s http://127.0.0.1:7920/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "mlx-community/Qwen3-0.6B-4bit",
    "messages": [{"role": "user", "content": "What is the capital of France? One sentence."}]
  }' | python3 -m json.tool

The first request takes a second or two longer: the model is being loaded. You should see an answer of this shape (the exact sentence may differ):

{
    "choices": [
        {
            "finish_reason": "stop",
            "index": 0,
            "logprobs": null,
            "message": {
                "content": "The capital of France is Paris.",
                "role": "assistant"
            }
        }
    ],
    "created": 1764096042,
    "id": "chatcmpl-3f9c2a…",
    "model": "mlx-community/Qwen3-0.6B-4bit",
    "object": "chat.completion",
    "usage": {
        "completion_tokens": 9,
        "prompt_tokens": 20,
        "total_tokens": 29
    }
}

In the first terminal, the server has logged the model load and the request, for example:

2026-11-25T19:20:41+0100 info rzb: [RazorbillServer] loaded mlx-community/Qwen3-0.6B-4bit in 0.43 seconds
2026-11-25T19:20:42+0100 info rzb: [RazorbillServer] POST /v1/chat/completions 200 812ms model=mlx-community/Qwen3-0.6B-4bit tokens=20+9

We have just run a model on the GPU through the same API as OpenAI's.

Step 5 — Use the openai Python library

Any program written for the OpenAI API can use the server by changing its base URL. Create a file first.py with this content:

from openai import OpenAI

client = OpenAI(base_url="http://127.0.0.1:7920/v1", api_key="unused")

stream = client.chat.completions.create(
    model="mlx-community/Qwen3-0.6B-4bit",
    messages=[{"role": "user", "content": "Write a haiku about the sea."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
print()

Run it:

uv run --with openai python first.py

You should see a haiku appear word by word, for example:

Waves fold into foam,
salt wind carries gull voices—
the tide keeps its time.

The server does not check api_key because we did not set one; the library still requires a value.

Step 6 — Stop the server

In the first terminal, press Ctrl-C. The server unloads the model and exits.

What now?

You have downloaded a model, served it on your Mac, and called it with curl and with the openai library, streaming included. To go further:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# Tutorial: your first requests to a local model

By the end of this tutorial, you will have a model running on your Mac's GPU behind an OpenAI-compatible API, and you will have talked to it twice: once with `curl`, once from a Python program that uses the official `openai` library.

No knowledge of MLX or of the OpenAI API is required.

## Prerequisites

- A Mac with Apple Silicon (M1 or later) and macOS 14 or later.
- `rzb` built, as described in [How to build rzb on the Mac](../how-to/build-on-the-mac.md). In this tutorial, `rzb` means `.build/xcode/Build/Products/Release/rzb`; to type it shorter, run this once in your terminal, from the repository root:

  ```bash
  alias rzb="$PWD/.build/xcode/Build/Products/Release/rzb"
  ```

- About 400 MB of free disk space, and an internet connection for the first download.
- [`uv`](https://docs.astral.sh/uv/) for step 5 (`brew install uv`).

## Step 1 — Download a small model

Type:

```bash
rzb models pull mlx-community/Qwen3-0.6B-4bit
```

A progress bar runs, then you should see:

```
mlx-community/Qwen3-0.6B-4bit is downloaded.
```

We now have a small model (0.6 billion parameters, 4-bit) in the Hugging Face cache on this Mac.

## Step 2 — Start the server

Type:

```bash
rzb serve
```

You should see:

```
rzb 0.3.0 serving http://127.0.0.1:7920/v1 (no API key) — Ctrl-C to stop
```

The server is running and only accepts connections from this Mac. Leave this terminal open, and **open a second terminal** for the next steps.

## Step 3 — Check that it answers

In the second terminal, type:

```bash
curl -s http://127.0.0.1:7920/health
```

You should see:

```json
{"status":"ok"}
```

Now ask which models it can serve:

```bash
curl -s http://127.0.0.1:7920/v1/models | python3 -m json.tool
```

You should see a list that contains the model we downloaded:

```json
{
    "data": [
        {
            "created": 1764096000,
            "id": "mlx-community/Qwen3-0.6B-4bit",
            "kind": "chat",
            "loaded": false,
            "object": "model",
            "owned_by": "razorbill"
        }
    ],
    "object": "list"
}
```

`"loaded": false`: the model is on disk but not in memory yet. It will be loaded by the first request.

## Step 4 — Ask a question with curl

Type:

```bash
curl -s http://127.0.0.1:7920/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "mlx-community/Qwen3-0.6B-4bit",
    "messages": [{"role": "user", "content": "What is the capital of France? One sentence."}]
  }' | python3 -m json.tool
```

The first request takes a second or two longer: the model is being loaded. You should see an answer of this shape (the exact sentence may differ):

```json
{
    "choices": [
        {
            "finish_reason": "stop",
            "index": 0,
            "logprobs": null,
            "message": {
                "content": "The capital of France is Paris.",
                "role": "assistant"
            }
        }
    ],
    "created": 1764096042,
    "id": "chatcmpl-3f9c2a…",
    "model": "mlx-community/Qwen3-0.6B-4bit",
    "object": "chat.completion",
    "usage": {
        "completion_tokens": 9,
        "prompt_tokens": 20,
        "total_tokens": 29
    }
}
```

In the first terminal, the server has logged the model load and the request, for example:

```
2026-11-25T19:20:41+0100 info rzb: [RazorbillServer] loaded mlx-community/Qwen3-0.6B-4bit in 0.43 seconds
2026-11-25T19:20:42+0100 info rzb: [RazorbillServer] POST /v1/chat/completions 200 812ms model=mlx-community/Qwen3-0.6B-4bit tokens=20+9
```

We have just run a model on the GPU through the same API as OpenAI's.

## Step 5 — Use the openai Python library

Any program written for the OpenAI API can use the server by changing its base URL. Create a file `first.py` with this content:

```python
from openai import OpenAI

client = OpenAI(base_url="http://127.0.0.1:7920/v1", api_key="unused")

stream = client.chat.completions.create(
    model="mlx-community/Qwen3-0.6B-4bit",
    messages=[{"role": "user", "content": "Write a haiku about the sea."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
print()
```

Run it:

```bash
uv run --with openai python first.py
```

You should see a haiku appear word by word, for example:

```
Waves fold into foam,
salt wind carries gull voices—
the tide keeps its time.
```

The server does not check `api_key` because we did not set one; the library still requires a value.

## Step 6 — Stop the server

In the first terminal, press **Ctrl-C**. The server unloads the model and exits.

## What now?

You have downloaded a model, served it on your Mac, and called it with `curl` and with the `openai` library, streaming included. To go further:

- Give your models short names, defaults and limits: [How to configure the server](../how-to/configure-the-server.md).
- Get JSON that follows a schema: [How to get structured output](../how-to/get-structured-output.md).
- Let the model call your functions: [How to use function calling](../how-to/use-function-calling.md).
- Every endpoint and field: [HTTP API reference](../reference/http-api.md).
- How the server works inside: [Architecture](../explanation/architecture.md).