# Local API Server (/desktop/api-server)

Jan provides a built-in, OpenAI-compatible API server that runs entirely on your computer, powered by `llama.cpp`. Use it as a drop-in replacement for cloud APIs to build private, offline-capable AI applications.

![Jan's Local API Server Settings UI](./_assets/local-api-server.png)

## Quick Start [#quick-start]

<Steps>
### Start the Server [#start-the-server]
1.  Navigate to **Settings** > **Local API Server**.
2.  Click **Start Server**.

The server is ready when the logs show `JAN API listening at http://127.0.0.1:1337`.

### Test with cURL [#test-with-curl]
Open a terminal and make a request. Replace `YOUR_MODEL_ID` with the ID of an available model in Jan.

```bash
curl http://127.0.0.1:1337/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer secret-key-123" \
  -d '{
    "model": "YOUR_MODEL_ID",
    "messages": [{"role": "user", "content": "Tell me a joke."}]
  }'
```
</Steps>

## Server Configuration [#server-configuration]

These settings control the network accessibility and basic behavior of your local server. Access them via the **Configuration** button in the top right.

![Server Configuration](./_assets/server-configuration.png)

### Server Host [#server-host]
The network address the server listens on.
- **`127.0.0.1`** (Default): The server is only accessible from your own computer. This is the most secure option for personal use.
- **`0.0.0.0`**: The server is accessible from other devices on your local network (e.g., your phone or another computer). Use this with caution.

### Server Port [#server-port]
The port number for the API server.
- **`1337`** (Default): A common alternative port.
- You can change this to any available port number (e.g., `8000`).

### API Prefix [#api-prefix]
The base path for all API endpoints.
- **`/v1`** (Default): Follows OpenAI's convention. The chat completions endpoint would be `http://127.0.0.1:1337/v1/chat/completions`.
- You can change this or leave it empty if desired.

### API Key [#api-key]
A secret key used to authenticate requests.
- Set any string (e.g., `a-secure-password`). If a key is configured, requests must include it in the `Authorization: Bearer YOUR_API_KEY` header.
- Leave the field empty to disable authentication (not recommended when binding to `0.0.0.0`).

### Trusted Hosts [#trusted-hosts]
A comma-separated list of hostnames allowed to access the server. This provides an additional layer of security when the server is exposed on your network.

### Request Timeout [#request-timeout]
How long (in seconds) the server waits for a response from the local model before giving up. Increase this if you are running large models on slow hardware and see request timeouts.

## Advanced Settings [#advanced-settings]

### Execute Tools on Server [#execute-tools-on-server]
- **(Disabled by default)** When enabled, MCP tool calls triggered through the `/v1/chat/completions` endpoint are executed server-side rather than being returned to the client to dispatch. Leave this off if your client app handles tool execution itself.

### Cross-Origin Resource Sharing (CORS) [#cross-origin-resource-sharing-cors]
- **(Enabled by default)** Allows web applications (like a custom web UI you are building) running on different domains to make requests to the API server.
- **Disable this** if your API will only be accessed by non-browser-based applications (e.g., scripts, command-line tools) for slightly improved security.

### Verbose Server Logs [#verbose-server-logs]
- **(Enabled by default)** Provides detailed, real-time logs of all incoming requests, responses, and server activity.
- This is extremely useful for debugging application behavior and understanding exactly what is being sent to the models.

## Troubleshooting [#troubleshooting]

<Callout>
Ensure **Verbose Server Logs** are enabled to get detailed error messages in the "Server Logs" view.
</Callout>

- **Connection Refused:** The server is not running, or your application is pointing to the wrong host or port.
- **401 Unauthorized:** Your API Key is missing from the `Authorization` header or is incorrect.
- **404 Not Found:**
    - The `model` ID in your request body does not match an available model in Jan.
    - Your request URL is incorrect (check the API Prefix).
- **CORS Error (in a web browser):** Ensure the CORS toggle is enabled in Jan's settings.
