|
| 1 | +--- |
| 2 | +title: Local API Server |
| 3 | +description: Learn how to run Jan's local API server. |
| 4 | + [ |
| 5 | + Jan, |
| 6 | + Customizable Intelligence, LLM, |
| 7 | + local AI, |
| 8 | + privacy focus, |
| 9 | + free and open source, |
| 10 | + private and offline, |
| 11 | + conversational AI, |
| 12 | + no-subscription fee, |
| 13 | + large language models, |
| 14 | + Jan Extensions, |
| 15 | + Extensions, |
| 16 | + ] |
| 17 | +--- |
| 18 | + |
| 19 | +import { Callout, Steps } from 'nextra/components' |
| 20 | +import { Settings, EllipsisVertical } from 'lucide-react' |
| 21 | + |
| 22 | +# Local API Server |
| 23 | + |
| 24 | +Jan includes a built-in API server that is compatible with OpenAI's API specification, allowing you to interact with AI models through a local HTTP interface. This means you can use Jan as a drop-in replacement for OpenAI's API, but running entirely on your computer. |
| 25 | + |
| 26 | +Jan uses **Cortex** as its core engine for running AI models. If you need a standalone API server without Jan's desktop interface (for example, in server environments or for command-line usage), you can use Cortex directly: https://cortex.so. |
| 27 | + |
| 28 | +<Callout> |
| 29 | +Full API documentation is available at [Cortex's API Reference](https://cortex.so/api-reference#tag/chat). |
| 30 | +</Callout> |
| 31 | + |
| 32 | +<br/> |
| 33 | + |
| 34 | +<br/> |
| 35 | + |
| 36 | +## Start Server |
| 37 | + |
| 38 | +<Steps> |
| 39 | + |
| 40 | +### Step 1: Start Server |
| 41 | +1. Navigate to the **Local API Server** |
| 42 | +2. Configure [Server Settings](/docs/api-server#server-settings) |
| 43 | +3. Click **Start Server** button |
| 44 | +4. Wait for the confirmation message in the logs panel, your server is ready when you see: `JAN API listening at: http://127.0.0.1:1337` |
| 45 | + |
| 46 | + |
| 47 | +### Step 2: Test Server |
| 48 | +The easiest way to test your server is through the API Playground: |
| 49 | +1. Click the **API Playground** button to open its testing interface |
| 50 | +2. Select a model from the dropdown menu in Jan interface |
| 51 | +3. Try a simple [chat completion](https://cortex.so/api-reference#tag/chat/post/v1/chat/completions) request |
| 52 | +4. View the response in real-time |
| 53 | + |
| 54 | +### Step 3: Use the API |
| 55 | +Navigate to [Cortex's API Reference](https://cortex.so/api-reference#tag/chat) to see full API endpoints for your use case. |
| 56 | +</Steps> |
| 57 | + |
| 58 | + |
| 59 | +## Server Settings |
| 60 | + |
| 61 | +#### Host Address Options |
| 62 | +- **127.0.0.1 (Recommended)**: |
| 63 | + - Only accessible from your computer |
| 64 | + - Most secure option for personal use |
| 65 | +- **0.0.0.0**: |
| 66 | + - Makes server accessible from other devices on your network |
| 67 | + - Use with caution and only when necessary |
| 68 | + |
| 69 | +#### Port Number |
| 70 | +- Default: `1337` |
| 71 | +- Can be any number between 1-65535 |
| 72 | +- Avoid common ports (80, 443, 3000, 8080) that might be used by other applications |
| 73 | + |
| 74 | +#### API Prefix |
| 75 | +- Default: `/v1` |
| 76 | +- Defines the base path for all API endpoints |
| 77 | +- Example: http://127.0.0.1:1337/v1/chat/completions |
| 78 | + |
| 79 | +#### Cross-Origin Resource Sharing (CORS) |
| 80 | +CORS controls which websites can access your API, which is important for web applications running in browsers. |
| 81 | + |
| 82 | +**When to enable:** |
| 83 | +- If you're building a web application that needs to access the API |
| 84 | +- If you're using browser extensions |
| 85 | + |
| 86 | +**When to leave disabled:** |
| 87 | +- If you're only using the API from your local applications |
| 88 | +- If you're concerned about security |
| 89 | + |
| 90 | +#### Verbose Server Logs |
| 91 | +Enable to show: |
| 92 | +- Detailed information about each API request |
| 93 | +- Error messages and debugging information |
| 94 | +- Server status updates |
| 95 | + |
| 96 | +## Troubleshooting Guide |
| 97 | + |
| 98 | +<Callout> |
| 99 | +Enable **Verbose Server Logs** for detailed error messages. |
| 100 | +</Callout> |
| 101 | + |
| 102 | +**1. Common Issues** |
| 103 | + - Confirm the server is running |
| 104 | + - Check if model is successfully loaded in Jan |
| 105 | + |
| 106 | + - Check if the port is already in use by another application |
| 107 | + - Verify you have admin/sudo rights if needed |
| 108 | + - Make sure your API endpoint matches your server settings. Example: Using `http://localhost:1337` when you set a different port. |
| 109 | + - Make sure the model name in your API request matches exactly what's shown in Jan. Example: If you selected "Llama 3.2 1B Instruct Q8" in Jan, use `llama3.2-1b-instruct` in your API request. |
| 110 | + - Verify your JSON request format is correct |
| 111 | + - Verify firewall settings |
| 112 | + - Look for detailed error messages in the logs |
| 113 | + |
| 114 | +**2. CORS Errors in Web Apps** |
| 115 | + - Enable CORS in server settings if using from a webpage |
| 116 | + - Verify the origin of the request |
| 117 | + - Verify your web app's request URL matches the server address exactly |
| 118 | + - Check browser console for specific error messages |
| 119 | + |
| 120 | +**3. Performance Issues** |
| 121 | + - Monitor system resources (CPU, RAM, and GPU usage) |
| 122 | + - Try to reduce the context length or `ngl` (number of GPU layers) |
| 123 | + - Check for other resource-intensive applications |
0 commit comments