|
| 1 | +--- |
| 2 | +title: Proxy |
| 3 | +description: Setting up Proxy |
| 4 | +slug: "proxy" |
| 5 | +--- |
| 6 | + |
| 7 | +import Tabs from "@theme/Tabs"; |
| 8 | +import TabItem from "@theme/TabItem"; |
| 9 | + |
| 10 | +:::warning |
| 11 | +🚧 Cortex.cpp is currently under development. Our documentation outlines the intended behavior of Cortex, which may not yet be fully implemented in the codebase. |
| 12 | +::: |
| 13 | + |
| 14 | +# Proxy Configuration Guide |
| 15 | + |
| 16 | +This document describes how to configure proxy settings for Cortex to be able to work behind your proxy. |
| 17 | + |
| 18 | +## Command Line Interface (CLI) |
| 19 | + |
| 20 | +### Basic Usage |
| 21 | + |
| 22 | +```bash |
| 23 | +cortex config [OPTIONS] [COMMAND] |
| 24 | +``` |
| 25 | + |
| 26 | +### Commands |
| 27 | + |
| 28 | +- `status`: Display all current configurations |
| 29 | + |
| 30 | +```bash |
| 31 | +cortex config status |
| 32 | +``` |
| 33 | + |
| 34 | +Example Output: |
| 35 | + |
| 36 | +```bash |
| 37 | ++-----------------------+------------------------+ |
| 38 | +| Config name | Value | |
| 39 | ++-----------------------+------------------------+ |
| 40 | +| no_proxy | localhost,127.0.0.1 | |
| 41 | ++-----------------------+------------------------+ |
| 42 | +| proxy_password | | |
| 43 | ++-----------------------+------------------------+ |
| 44 | +| proxy_url | http://localhost:8080 | |
| 45 | ++-----------------------+------------------------+ |
| 46 | +| proxy_username | | |
| 47 | ++-----------------------+------------------------+ |
| 48 | +| verify_host_ssl | true | |
| 49 | ++-----------------------+------------------------+ |
| 50 | +| verify_peer_ssl | false | |
| 51 | ++-----------------------+------------------------+ |
| 52 | +| verify_proxy_host_ssl | true | |
| 53 | ++-----------------------+------------------------+ |
| 54 | +| verify_proxy_ssl | true | |
| 55 | ++-----------------------+------------------------+ |
| 56 | +``` |
| 57 | + |
| 58 | +### Options |
| 59 | + |
| 60 | +| Option | Description | Example | |
| 61 | +| ----------------------------------- | --------------------------- | ------------------------------------------------- | |
| 62 | +| `-h, --help` | Print help message and exit | |
| 63 | +| `--proxy_url <proxy_url>` | Set the proxy URL | `cortex config --proxy_url http://localhost:8080` | |
| 64 | +| `--proxy_username <proxy_username>` | Set the username for proxy | `cortex config --proxy_username my_username` | |
| 65 | +| `--proxy_password <proxy_password>` | Set the password for proxy | `cortex config --proxy_password my_password` | |
| 66 | +| `--no_proxy <no_proxy>` | Set the no_proxy list | `cortex config --no_proxy localhost,127.0.0.1` | |
| 67 | +| `--verify_proxy_ssl [on/off]` | Verify proxy SSL | `cortex config --verify_proxy_ssl on` | |
| 68 | +| `--verify_proxy_host_ssl [on/off]` | Verify proxy host SSL | `cortex config --verify_proxy_host_ssl on` | |
| 69 | +| `--verify_peer_ssl [on/off]` | Verify peer SSL | `cortex config --verify_peer_ssl off` | |
| 70 | +| `--verify_host_ssl [on/off]` | Verify host SSL | `cortex config --verify_host_ssl on` | |
| 71 | + |
| 72 | +## Proxy API Configuration |
| 73 | + |
| 74 | +### Endpoints |
| 75 | + |
| 76 | +#### Get Current Configuration |
| 77 | + |
| 78 | +```http |
| 79 | +GET /v1/configs |
| 80 | +``` |
| 81 | + |
| 82 | +Retrieves the current configuration settings. |
| 83 | + |
| 84 | +##### Response |
| 85 | + |
| 86 | +```json |
| 87 | +{ |
| 88 | + "allowed_origins": [ |
| 89 | + "http://localhost:39281", |
| 90 | + "http://127.0.0.1:39281", |
| 91 | + "http://0.0.0.0:39281" |
| 92 | + ], |
| 93 | + "cors": true, |
| 94 | + "no_proxy": "localhost,127.0.0.1", |
| 95 | + "proxy_password": "", |
| 96 | + "proxy_url": "http://localhost:8080", |
| 97 | + "proxy_username": "", |
| 98 | + "verify_host_ssl": true, |
| 99 | + "verify_peer_ssl": false, |
| 100 | + "verify_proxy_host_ssl": true, |
| 101 | + "verify_proxy_ssl": true |
| 102 | +} |
| 103 | +``` |
| 104 | + |
| 105 | +#### Update Configuration |
| 106 | + |
| 107 | +```http |
| 108 | +PATCH /v1/configs |
| 109 | +``` |
| 110 | + |
| 111 | +Updates proxy configuration settings. |
| 112 | + |
| 113 | +##### Request Headers |
| 114 | + |
| 115 | +``` |
| 116 | +Content-Type: application/json |
| 117 | +``` |
| 118 | + |
| 119 | +##### Request Body |
| 120 | + |
| 121 | +```json |
| 122 | +{ |
| 123 | + "no_proxy": "localhost", |
| 124 | + "proxy_url": "http://localhost:8080", |
| 125 | + "proxy_username": "my_username", |
| 126 | + "proxy_password": "my_password", |
| 127 | + "verify_host_ssl": false, |
| 128 | + "verify_peer_ssl": false, |
| 129 | + "verify_proxy_host_ssl": false, |
| 130 | + "verify_proxy_ssl": false |
| 131 | +} |
| 132 | +``` |
| 133 | + |
| 134 | +##### Parameters |
| 135 | + |
| 136 | +| Field | Type | Description | |
| 137 | +| ----------------------- | ------- | -------------------------------------------------------------------------------------- | |
| 138 | +| `no_proxy` | string | List of origins which request do not need to go through a proxy. Comma separated value | |
| 139 | +| `proxy_url` | string | Proxy URL | |
| 140 | +| `proxy_username` | string | Username for proxy authentication | |
| 141 | +| `proxy_password` | string | Password for proxy authentication | |
| 142 | +| `verify_host_ssl` | boolean | Verify host SSL | |
| 143 | +| `verify_peer_ssl` | boolean | Verify peer SSL | |
| 144 | +| `verify_proxy_host_ssl` | boolean | Verify proxy host SSL | |
| 145 | +| `verify_proxy_ssl` | boolean | Verify proxy SSL | |
| 146 | + |
| 147 | +##### Response |
| 148 | + |
| 149 | +```json |
| 150 | +{ |
| 151 | + "config": { |
| 152 | + "allowed_origins": [ |
| 153 | + "http://localhost:39281", |
| 154 | + "http://127.0.0.1:39281", |
| 155 | + "http://0.0.0.0:39281" |
| 156 | + ], |
| 157 | + "cors": true, |
| 158 | + "no_proxy": "localhost", |
| 159 | + "proxy_password": "my_password", |
| 160 | + "proxy_url": "http://localhost:8080", |
| 161 | + "proxy_username": "my_username", |
| 162 | + "verify_host_ssl": false, |
| 163 | + "verify_peer_ssl": false, |
| 164 | + "verify_proxy_host_ssl": false, |
| 165 | + "verify_proxy_ssl": false |
| 166 | + }, |
| 167 | + "message": "Configuration updated successfully" |
| 168 | +} |
| 169 | +``` |
| 170 | + |
| 171 | +## Testing proxy configuration |
| 172 | + |
| 173 | +You can test your proxy configuration using [mitmproxy](https://docs.mitmproxy.org/stable). This guide is written on macOS, but you can use it on any other platform. |
| 174 | + |
| 175 | +### Install mitmproxy |
| 176 | + |
| 177 | +```bash |
| 178 | +brew install mitmproxy |
| 179 | +``` |
| 180 | + |
| 181 | +### Start mitmproxy |
| 182 | + |
| 183 | +```bash |
| 184 | +mitmproxy --set stream_large_bodies=1m |
| 185 | +``` |
| 186 | + |
| 187 | +mitmproxy will start on port `8080`. After mitmproxy started, you can adding options by pressing `O`. mitmproxy will display an option screen. You can check their document to learn more about mitmproxy. But let's take a simple option for now by setting the `proxyauth` for our local proxy. Inside the option screen, search for `proxyauth` and hit enter. Then, type `username:password` and hit enter again. You will see your newly added option is red-colored. |
| 188 | + |
| 189 | +### Configuring Cortex to use that proxy |
| 190 | + |
| 191 | +Let's using CLI to configure Cortex to use that proxy. |
| 192 | + |
| 193 | +```bash |
| 194 | +cortex config --proxy_url http://localhost:8080 --proxy_username username --proxy_password password |
| 195 | +``` |
| 196 | + |
| 197 | +### Testing the proxy |
| 198 | + |
| 199 | +Now, let's test the proxy. If you are setting the username and password correctly (same with `proxyauth` in mitmproxy), you will see the request in mitmproxy. For example, command `cortex pull tinyllama` should be successfully and returns a list of selectable models. Also, you will see your request in mitmproxy CLI screen. |
| 200 | + |
| 201 | +Let's try to use a wrong authentication for your proxy. |
| 202 | + |
| 203 | +```bash |
| 204 | +cortex config --proxy_password wrong_pw |
| 205 | +``` |
| 206 | + |
| 207 | +Now, let's test the proxy again. You will see the request is failed and returns an error. |
0 commit comments