# Local quickstart

Install mlx-lm, start its server with a model, and call http://127.0.0.1:8080/v1/chat/completions from curl, Python or JavaScript.

## Get a model running

:::steps
### Install mlx-lm
On a Mac with Apple silicon, install the package from PyPI:

```bash
pip install mlx-lm
```

### Start the server
Give it a local path or a Hugging Face repo. This is mlx-lm's own example:

```bash
mlx_lm.server --model mlx-community/Mistral-7B-Instruct-v0.3-4bit
```

The model is downloaded the first time, then the server listens on port `8080` of `localhost`. To check before downloading that a model fits your Mac's memory, see [Models](/local/models#will-it-fit).

### See every option
```bash
mlx_lm.server --help
```
:::

## Call it

The request is OpenAI-style chat JSON. `model` is optional: without it the server uses the model it was started with.

```endpoint
POST http://127.0.0.1:8080/v1/chat/completions
```

```bash tab=curl
curl localhost:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
     "messages": [{"role": "user", "content": "Say this is a test!"}],
     "temperature": 0.7
   }'
```

```python tab=Python
import json, urllib.request

body = {"messages": [{"role": "user", "content": "Say this is a test!"}], "temperature": 0.7}
req = urllib.request.Request(
    "http://127.0.0.1:8080/v1/chat/completions",
    data=json.dumps(body).encode(),
    headers={"Content-Type": "application/json"},
)
reply = json.load(urllib.request.urlopen(req))
print(reply["choices"][0]["message"])
```

```js tab=JavaScript
const res = await fetch("http://127.0.0.1:8080/v1/chat/completions", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ messages: [{ role: "user", content: "Say this is a test!" }], temperature: 0.7 }),
});
const reply = await res.json();
console.log(reply.choices[0].message);
```

`max_tokens` defaults to `512`, so ask for more when you want a long answer. Every field is on [Chat completions](/local/chat-completions).

## Stream the reply

Set `"stream": true` to get the answer as it is generated; each piece is a `chat.completion.chunk`.

```bash tab=curl
curl -N localhost:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
     "stream": true,
     "messages": [{"role": "user", "content": "Write a haiku about a Mac mini."}]
   }'
```

> [!NOTE]
> mlx-lm's server "only implements basic security checks" and is not recommended for production. It listens on `127.0.0.1` unless you pass `--host`.
