Skip to content

Commit 720a32d

Browse files
committed
add api keys for urls
1 parent 1925059 commit 720a32d

File tree

6 files changed

+21
-60
lines changed

6 files changed

+21
-60
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ After this, you'll set up your files, start the container, hit a few routes and
2323
#### **Don't forget to forward port 443 on your router!**
2424

2525
I'll use `localhost`, `192.168.1.100` or `your.domain.com` as an examples, but fill these in with your domain or IP address.
26+
You can also add api keys if you need to. like `http://192.168.1.100:1234|api-key-here`.
2627

2728
### Files
2829

@@ -32,7 +33,7 @@ version: '3.6'
3233

3334
services:
3435
llmp:
35-
image: ghcr.io/j4ys0n/llm-proxy:1.2.1
36+
image: ghcr.io/j4ys0n/llm-proxy:1.5.0
3637
container_name: llmp
3738
hostname: llmp
3839
restart: unless-stopped
@@ -50,7 +51,7 @@ services:
5051
Here's what your `.env` file should look like:
5152
```bash
5253
PORT=8080 # node.js listen port. right now nginx is hard coded, so don't change this.
53-
TARGET_URLS=http://localhost:1234,http://192.168.1.100:1234 # list of api endpoints (don't add /v1)
54+
TARGET_URLS=http://localhost:1234,http://192.168.1.100:1234|api-key-here # list of api endpoints (don't add /v1)
5455
JWT_SECRET=randomly_generated_secret # secret for JWT token generation, change this!
5556
AUTH_USERNAME=admin
5657
AUTH_PASSWORD=secure_password # super basic auth credentials for the admin interface

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3.6'
22

33
services:
44
llmp:
5-
image: ghcr.io/j4ys0n/llm-proxy:1.2.1
5+
image: ghcr.io/j4ys0n/llm-proxy:1.5.0
66
container_name: llmp
77
hostname: llmp
88
restart: unless-stopped

example.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PORT=8080
2-
TARGET_URLS=http://localhost:1234/v1
2+
TARGET_URLS=http://localhost:1234/v1,http://192.168.1.100:1234|api-key-here
33
JWT_SECRET=your-jwt-secret-key-here
44
AUTH_USERNAME=admin
55
AUTH_PASSWORD=secure_password

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "llm-proxy",
3-
"version": "1.4.7",
3+
"version": "1.5.0",
44
"description": "Manages Nginx for reverse proxy to multiple LLMs, with TLS & Bearer Auth tokens",
55
"main": "dist/index.js",
66
"scripts": {

src/controllers/llm.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@ export interface ModelMap {
1313
[key: string]: { url: string; model: Model }
1414
}
1515

16+
const defaultContentType = 'application/json'
17+
1618
async function fetchModels(targetUrls: string[]): Promise<ModelMap> {
1719
const tmp: ModelMap = {}
18-
for (const url of targetUrls) {
20+
for (const urlAndToken of targetUrls) {
21+
const [url, apiKey] = urlAndToken.split('|').map(s => s.trim())
22+
const reqHeaders: { [key: string]: string } = {
23+
accept: defaultContentType,
24+
'Content-Type': defaultContentType
25+
}
26+
if (apiKey != null && apiKey !== '') {
27+
reqHeaders['Authorization'] = `Bearer ${apiKey}`
28+
}
1929
try {
2030
const response = await axios.get(`${url}/v1/models`)
2131
const models = response.data.data || []

yarn.lock

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"@types/qs" "*"
8383
"@types/serve-static" "*"
8484

85-
"@types/fs-extra@^11.2.0":
85+
"@types/fs-extra@^11.0.4":
8686
version "11.0.4"
8787
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-11.0.4.tgz#e16a863bb8843fba8c5004362b5a73e17becca45"
8888
integrity sha512-yTbItCNreRooED33qjunPthRcSjERP1r4MqCZc7wv0u2sUkzTFp45tgUfS5+r7FrZPdmCCNflLhVSP/o+SemsQ==
@@ -95,13 +95,6 @@
9595
resolved "https://registry.yarnpkg.com/@types/http-errors/-/http-errors-2.0.4.tgz#7eb47726c391b7345a6ec35ad7f4de469cf5ba4f"
9696
integrity sha512-D0CFMMtydbJAegzOyHjtiKPLlvnm3iTZyZRSZoLq2mRhDdmLfIWOCYPfQJ4cu2erKghU++QvjcUjp/5h7hESpA==
9797

98-
"@types/http-proxy@^1.17.8":
99-
version "1.17.14"
100-
resolved "https://registry.yarnpkg.com/@types/http-proxy/-/http-proxy-1.17.14.tgz#57f8ccaa1c1c3780644f8a94f9c6b5000b5e2eec"
101-
integrity sha512-SSrD0c1OQzlFX7pGu1eXxSEjemej64aaNPRhhVYUGqXh0BtldAAx37MG8btcumvpgKyZp1F5Gn3JkktdxiFv6w==
102-
dependencies:
103-
"@types/node" "*"
104-
10598
"@types/jsonfile@*":
10699
version "6.1.4"
107100
resolved "https://registry.yarnpkg.com/@types/jsonfile/-/jsonfile-6.1.4.tgz#614afec1a1164e7d670b4a7ad64df3e7beb7b702"
@@ -253,7 +246,7 @@ brace-expansion@^1.1.7:
253246
balanced-match "^1.0.0"
254247
concat-map "0.0.1"
255248

256-
braces@^3.0.3, braces@~3.0.2:
249+
braces@~3.0.2:
257250
version "3.0.3"
258251
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789"
259252
integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==
@@ -427,11 +420,6 @@ etag@~1.8.1:
427420
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
428421
integrity sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==
429422

430-
eventemitter3@^4.0.0:
431-
version "4.0.7"
432-
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f"
433-
integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==
434-
435423
express@^4.19.2:
436424
version "4.19.2"
437425
resolved "https://registry.yarnpkg.com/express/-/express-4.19.2.tgz#e25437827a3aa7f2a827bc8171bbbb664a356465"
@@ -489,7 +477,7 @@ [email protected]:
489477
statuses "2.0.1"
490478
unpipe "~1.0.0"
491479

492-
follow-redirects@^1.0.0, follow-redirects@^1.15.6:
480+
follow-redirects@^1.15.6:
493481
version "1.15.6"
494482
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b"
495483
integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==
@@ -614,26 +602,6 @@ [email protected]:
614602
statuses "2.0.1"
615603
toidentifier "1.0.1"
616604

617-
http-proxy-middleware@^2.0.6:
618-
version "2.0.6"
619-
resolved "https://registry.yarnpkg.com/http-proxy-middleware/-/http-proxy-middleware-2.0.6.tgz#e1a4dd6979572c7ab5a4e4b55095d1f32a74963f"
620-
integrity sha512-ya/UeJ6HVBYxrgYotAZo1KvPWlgB48kUJLDePFeneHsVujFaW5WNj2NgWCAE//B1Dl02BIfYlpNgBy8Kf8Rjmw==
621-
dependencies:
622-
"@types/http-proxy" "^1.17.8"
623-
http-proxy "^1.18.1"
624-
is-glob "^4.0.1"
625-
is-plain-obj "^3.0.0"
626-
micromatch "^4.0.2"
627-
628-
http-proxy@^1.18.1:
629-
version "1.18.1"
630-
resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.18.1.tgz#401541f0534884bbf95260334e72f88ee3976549"
631-
integrity sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==
632-
dependencies:
633-
eventemitter3 "^4.0.0"
634-
follow-redirects "^1.0.0"
635-
requires-port "^1.0.0"
636-
637605
638606
version "0.4.24"
639607
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
@@ -690,11 +658,6 @@ is-number@^7.0.0:
690658
resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b"
691659
integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==
692660

693-
is-plain-obj@^3.0.0:
694-
version "3.0.0"
695-
resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-3.0.0.tgz#af6f2ea14ac5a646183a5bbdb5baabbc156ad9d7"
696-
integrity sha512-gwsOE28k+23GP1B6vFl1oVh/WOzmawBrKwo5Ev6wMKzPkaXaCDIQKzLnvsA42DRlbVTWorkgTKIviAKCWkfUwA==
697-
698661
jsonfile@^6.0.1:
699662
version "6.1.0"
700663
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae"
@@ -792,14 +755,6 @@ methods@~1.1.2:
792755
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
793756
integrity sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==
794757

795-
micromatch@^4.0.2:
796-
version "4.0.7"
797-
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.7.tgz#33e8190d9fe474a9895525f5618eee136d46c2e5"
798-
integrity sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q==
799-
dependencies:
800-
braces "^3.0.3"
801-
picomatch "^2.3.1"
802-
803758
804759
version "1.52.0"
805760
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
@@ -893,7 +848,7 @@ [email protected]:
893848
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c"
894849
integrity sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==
895850

896-
picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.3.1:
851+
picomatch@^2.0.4, picomatch@^2.2.1:
897852
version "2.3.1"
898853
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
899854
integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==
@@ -940,11 +895,6 @@ readdirp@~3.6.0:
940895
dependencies:
941896
picomatch "^2.2.1"
942897

943-
requires-port@^1.0.0:
944-
version "1.0.0"
945-
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
946-
integrity sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==
947-
948898
resolve@^1.0.0:
949899
version "1.22.8"
950900
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.8.tgz#b6c87a9f2aa06dfab52e3d70ac8cde321fa5a48d"

0 commit comments

Comments
 (0)