https://github.com/armandris/gpt-broker
Keeps your OpenAi token safe and your frontend GPT'ed.
https://github.com/armandris/gpt-broker
authentication docker jwt koa microservice openai prometheus rate-limiting rest-api security supabase
Last synced: 3 months ago
JSON representation
Keeps your OpenAi token safe and your frontend GPT'ed.
- Host: GitHub
- URL: https://github.com/armandris/gpt-broker
- Owner: ArmanDris
- Created: 2024-07-28T08:43:52.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-08T11:27:46.000Z (over 1 year ago)
- Last Synced: 2025-02-08T12:20:17.584Z (over 1 year ago)
- Topics: authentication, docker, jwt, koa, microservice, openai, prometheus, rate-limiting, rest-api, security, supabase
- Language: JavaScript
- Homepage:
- Size: 127 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GPT Broker 💼
GPT Broker keeps your OpenAI token out of frontend code and ensures only authenticated users access sensitive endpoints.
For Prometheus integration a /metrics endpoint with basic traffic information is exposed. Make sure public requests are denied from accessing it.
## Endpoints:
### /stream
```sh
# Streams a chat completion back to the user as it arrives
# Method:
POST
# Request Header:
Authorization: Bearer
# Request Body:
{
"messages": , # eg. `[ { "role": "system", "content": "Write me a poem" }, ... ]`
"temperature": ,
"model": # either "gpt-4o" or "gpt-4o-mini"
}
```
### /gpt-4o
```sh
# Simple endpoint for 4o, supports temperature.
# Method:
POST
# Request Header:
Authorization: Bearer
# Request Body:
{
"messages": ,
"temperature":
}
```
### /v2/advanced-gpt-4o-mini-complete
```sh
# v2 has small syntax tweaks and lets the caller specify a temperature to pass to gpt
# Method:
POST
# Request Header:
Authorization: Bearer
# Request Body:
{
"messages": , # eg. `[ { "role": "system", "content": "Write me a poem" }, ... ]`
"temperature":
}
```
### /advanced-gpt-4o-mini-complete
```sh
# More complicated but allows full control over the prompts passed to ChatGPT.
# Does not support temperature, for that look for the v2 version of this endpoint.
# Method:
POST
# Request Header:
Authorization: Bearer
# Request Body:
{
"messages": , # eg. `[ { "role": "system", "content": "Write me a poem" }, ... ]`
}
```
### /simple-gpt-4o-mini-complete
```sh
# For simple requests that fit in a query param.
# Method:
GET
# Request Parameters:
prompt= # eg. "Write me a poem"
# Request Header:
Authorization: Bearer
```
### /metrics
```sh
# Method:
GET
```
## Setup:
Place two .env files in the root directory of this project. The first should have the information for the
**SkillSyncDev** supabase project and it should have the name `.env.sksndev`. The second should have the
information for the **techskillsync** supabase project and it should have the name `.env.techsksn`.
Both .env files should have the following fields:
```
OPENAI_API_KEY=your-openai-api-key-here
SUPABASE_URL=your-supabase-url-here
SUPABASE_SERVICE_KEY=your-supabase-service-key-here
REDIS_URL=redis://:@redis-stack:6379
DAILY_LIMIT=50
ID_WHITE_LIST=[]
```
Now run `./both_up` to boot up both containers and `./both_down` to stop both containers.
## Testing:
There is a testing suite for both containers as well as the production endpoints. See the project in `test-gpt-broker` for more info.