The backend uses the ENV as a simple key:value store, so to store an array of compatible APIs, I stored them as a ; separated list like: localhost1;localhost2;localhost3
The backend/frontend implementations for OpenAI Compat are mostly copy pastes of the original OpenAI implemenation, with the changes:
Compat needs model labels because we don't have a provider to query them from
Removed anything that looks specific/proprietary to OpenAI (e.g. sound/vision)
I decided to add a 3rd pathway for OPENAI_COMPAT instead of augmenting OPENAI because we probably want to allow the original OPENAI pathway to be easily extended for any changes to the proprietary API / features.
There's probably other ways this could have been built, but this was what came to me as I was reading the code for the first time + have never touched Svelte before.
Check
backend logs
INFO: 127.0.0.1:42702 - "GET /api/v1/ HTTP/1.1" 200 OK
INFO: 127.0.0.1:42718 - "GET /themes/rosepine-dawn.css HTTP/1.1" 304 Not Modified
INFO: 127.0.0.1:42674 - "GET /themes/rosepine.css HTTP/1.1" 304 Not Modified
INFO: 127.0.0.1:42702 - "GET /api/v1/auths/ HTTP/1.1" 200 OK
INFO: 127.0.0.1:42702 - "GET /api/v1/modelfiles/ HTTP/1.1" 200 OK
INFO: 127.0.0.1:42702 - "GET /api/v1/prompts/ HTTP/1.1" 200 OK
INFO: 127.0.0.1:42702 - "GET /api/v1/documents/ HTTP/1.1" 200 OK
INFO: 127.0.0.1:42702 - "GET /api/v1/chats/tags/all HTTP/1.1" 200 OK
INFO: 127.0.0.1:42674 - "GET /ollama/api/version HTTP/1.1" 200 OK
INFO: 127.0.0.1:42702 - "GET /ollama/api/tags HTTP/1.1" 200 OK
INFO: 127.0.0.1:42702 - "GET /user.png HTTP/1.1" 304 Not Modified
INFO: 127.0.0.1:42702 - "GET /api/v1/chats/e20e5d8f-321a-4134-b75f-0dcc29ad5303 HTTP/1.1" 200 OK
INFO: 127.0.0.1:42674 - "GET /api/v1/chats/ HTTP/1.1" 200 OK
https://api.openai.com/v1/models <KEY_REDACTED>
Error loading request body into a dictionary: Expecting value: line 1 column 1 (char 0)
INFO: 127.0.0.1:42718 - "GET /openai/api/models HTTP/1.1" 200 OK
INFO: 127.0.0.1:42702 - "GET /assets/fonts/Arimo-Variable.ttf HTTP/1.1" 304 Not Modified
INFO: 127.0.0.1:42674 - "GET /api/v1/chats/e20e5d8f-321a-4134-b75f-0dcc29ad5303/tags HTTP/1.1" 200 OK
INFO: 127.0.0.1:42702 - "GET /openai_compat/api/label HTTP/1.1" 200 OK
Getting model from JSON body: llama.cpp
Found model at index: 0
URL List: ['http://localhost:8000/v1', 'http://localhost:8001/v1']
Hitting OpenAI compat URL: http://localhost:8000/v1/chat/completions
INFO: 127.0.0.1:60694 - "POST /openai_compat/api/chat/completions HTTP/1.1" 200 OK
INFO: 127.0.0.1:60694 - "POST /api/v1/chats/e20e5d8f-321a-4134-b75f-0dcc29ad5303 HTTP/1.1" 200 OK
INFO: 127.0.0.1:60694 - "GET /api/v1/chats/ HTTP/1.1" 200 OK
INFO: 127.0.0.1:60694 - "GET /api/v1/chats/ HTTP/1.1" 200 OK
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/open-webui/open-webui/pull/697
**Author:** [@NinjaPerson24119](https://github.com/NinjaPerson24119)
**Created:** 2/10/2024
**Status:** ❌ Closed
**Base:** `dev` ← **Head:** `openai-compatible-APIs`
---
### 📝 Commits (10+)
- [`4087cae`](https://github.com/open-webui/open-webui/commit/4087caea9d6df65310b7f0ac26cc40aa0a2b6261) feat: backend
- [`e4d2e8e`](https://github.com/open-webui/open-webui/commit/e4d2e8e5ef01ba24ba641f4b70ec04bb18618a61) feat: frontend
- [`f3e140f`](https://github.com/open-webui/open-webui/commit/f3e140f8b1c05c9751b1ed776953b60a56ee7d30) feat: Dockerfile args
- [`38f8b92`](https://github.com/open-webui/open-webui/commit/38f8b92beb542a36fe3f0a902cc38955894c30e4) feat: example.env
- [`0d14d50`](https://github.com/open-webui/open-webui/commit/0d14d50f42be25de207a9ff7923b66c9207c4470) fix: backend
- [`4da6332`](https://github.com/open-webui/open-webui/commit/4da63327508ca9801f9b6131a65ff943ba10610e) fix: duplicated openAI (official) settings section
- [`05d6c42`](https://github.com/open-webui/open-webui/commit/05d6c42bd523bd6732625980c806d420cf073d15) fix: frontend
- [`bddb80b`](https://github.com/open-webui/open-webui/commit/bddb80bbd510065771e28a1c040b60d990a7f08e) fix: clean backend logs, don't write keys
- [`3a884b2`](https://github.com/open-webui/open-webui/commit/3a884b2b8b94a7179df010d87a1c3e76936ced0b) fix: stop printing oapi creds to logs
- [`52e94a5`](https://github.com/open-webui/open-webui/commit/52e94a57561aa5eb34432fe742c35739ac736dc3) chore: clean-up
### 📊 Changes
**16 files changed** (+513 additions, -19 deletions)
<details>
<summary>View changed files</summary>
📝 `Dockerfile` (+5 -1)
📝 `backend/apps/openai/main.py` (+1 -1)
➕ `backend/apps/openai_compat/main.py` (+135 -0)
📝 `backend/config.py` (+8 -0)
📝 `backend/main.py` (+2 -0)
📝 `example.env` (+5 -1)
➕ `src/lib/apis/openai_compat/index.ts` (+257 -0)
📝 `src/lib/components/chat/MessageInput/Models.svelte` (+1 -1)
📝 `src/lib/components/chat/Settings/External.svelte` (+57 -2)
📝 `src/lib/components/chat/SettingsModal.svelte` (+7 -1)
📝 `src/lib/components/common/Modal.svelte` (+1 -1)
📝 `src/lib/constants.ts` (+1 -0)
📝 `src/lib/utils/index.ts` (+1 -0)
📝 `src/routes/(app)/+layout.svelte` (+9 -1)
📝 `src/routes/(app)/+page.svelte` (+8 -5)
📝 `src/routes/(app)/c/[id]/+page.svelte` (+15 -5)
</details>
### 📄 Description
Adds support for hitting OpenAI compatible UIs.
The backend uses the ENV as a simple key:value store, so to store an array of compatible APIs, I stored them as a `;` separated list like: `localhost1;localhost2;localhost3`
The backend/frontend implementations for OpenAI Compat are mostly copy pastes of the original OpenAI implemenation, with the changes:
- Compat needs model labels because we don't have a provider to query them from
- Removed anything that looks specific/proprietary to OpenAI (e.g. sound/vision)
I decided to add a 3rd pathway for `OPENAI_COMPAT` instead of augmenting `OPENAI` because we probably want to allow the original `OPENAI` pathway to be easily extended for any changes to the proprietary API / features.
There's probably other ways this could have been built, but this was what came to me as I was reading the code for the first time + have never touched Svelte before.
# Check



backend logs
```
INFO: 127.0.0.1:42702 - "GET /api/v1/ HTTP/1.1" 200 OK
INFO: 127.0.0.1:42718 - "GET /themes/rosepine-dawn.css HTTP/1.1" 304 Not Modified
INFO: 127.0.0.1:42674 - "GET /themes/rosepine.css HTTP/1.1" 304 Not Modified
INFO: 127.0.0.1:42702 - "GET /api/v1/auths/ HTTP/1.1" 200 OK
INFO: 127.0.0.1:42702 - "GET /api/v1/modelfiles/ HTTP/1.1" 200 OK
INFO: 127.0.0.1:42702 - "GET /api/v1/prompts/ HTTP/1.1" 200 OK
INFO: 127.0.0.1:42702 - "GET /api/v1/documents/ HTTP/1.1" 200 OK
INFO: 127.0.0.1:42702 - "GET /api/v1/chats/tags/all HTTP/1.1" 200 OK
INFO: 127.0.0.1:42674 - "GET /ollama/api/version HTTP/1.1" 200 OK
INFO: 127.0.0.1:42702 - "GET /ollama/api/tags HTTP/1.1" 200 OK
INFO: 127.0.0.1:42702 - "GET /user.png HTTP/1.1" 304 Not Modified
INFO: 127.0.0.1:42702 - "GET /api/v1/chats/e20e5d8f-321a-4134-b75f-0dcc29ad5303 HTTP/1.1" 200 OK
INFO: 127.0.0.1:42674 - "GET /api/v1/chats/ HTTP/1.1" 200 OK
https://api.openai.com/v1/models <KEY_REDACTED>
Error loading request body into a dictionary: Expecting value: line 1 column 1 (char 0)
INFO: 127.0.0.1:42718 - "GET /openai/api/models HTTP/1.1" 200 OK
INFO: 127.0.0.1:42702 - "GET /assets/fonts/Arimo-Variable.ttf HTTP/1.1" 304 Not Modified
INFO: 127.0.0.1:42674 - "GET /api/v1/chats/e20e5d8f-321a-4134-b75f-0dcc29ad5303/tags HTTP/1.1" 200 OK
INFO: 127.0.0.1:42702 - "GET /openai_compat/api/label HTTP/1.1" 200 OK
Getting model from JSON body: llama.cpp
Found model at index: 0
URL List: ['http://localhost:8000/v1', 'http://localhost:8001/v1']
Hitting OpenAI compat URL: http://localhost:8000/v1/chat/completions
INFO: 127.0.0.1:60694 - "POST /openai_compat/api/chat/completions HTTP/1.1" 200 OK
INFO: 127.0.0.1:60694 - "POST /api/v1/chats/e20e5d8f-321a-4134-b75f-0dcc29ad5303 HTTP/1.1" 200 OK
INFO: 127.0.0.1:60694 - "GET /api/v1/chats/ HTTP/1.1" 200 OK
INFO: 127.0.0.1:60694 - "GET /api/v1/chats/ HTTP/1.1" 200 OK
```
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/697
Author: @NinjaPerson24119
Created: 2/10/2024
Status: ❌ Closed
Base:
dev← Head:openai-compatible-APIs📝 Commits (10+)
4087caefeat: backende4d2e8efeat: frontendf3e140ffeat: Dockerfile args38f8b92feat: example.env0d14d50fix: backend4da6332fix: duplicated openAI (official) settings section05d6c42fix: frontendbddb80bfix: clean backend logs, don't write keys3a884b2fix: stop printing oapi creds to logs52e94a5chore: clean-up📊 Changes
16 files changed (+513 additions, -19 deletions)
View changed files
📝
Dockerfile(+5 -1)📝
backend/apps/openai/main.py(+1 -1)➕
backend/apps/openai_compat/main.py(+135 -0)📝
backend/config.py(+8 -0)📝
backend/main.py(+2 -0)📝
example.env(+5 -1)➕
src/lib/apis/openai_compat/index.ts(+257 -0)📝
src/lib/components/chat/MessageInput/Models.svelte(+1 -1)📝
src/lib/components/chat/Settings/External.svelte(+57 -2)📝
src/lib/components/chat/SettingsModal.svelte(+7 -1)📝
src/lib/components/common/Modal.svelte(+1 -1)📝
src/lib/constants.ts(+1 -0)📝
src/lib/utils/index.ts(+1 -0)📝
src/routes/(app)/+layout.svelte(+9 -1)📝
src/routes/(app)/+page.svelte(+8 -5)📝
src/routes/(app)/c/[id]/+page.svelte(+15 -5)📄 Description
Adds support for hitting OpenAI compatible UIs.
The backend uses the ENV as a simple key:value store, so to store an array of compatible APIs, I stored them as a
;separated list like:localhost1;localhost2;localhost3The backend/frontend implementations for OpenAI Compat are mostly copy pastes of the original OpenAI implemenation, with the changes:
I decided to add a 3rd pathway for
OPENAI_COMPATinstead of augmentingOPENAIbecause we probably want to allow the originalOPENAIpathway to be easily extended for any changes to the proprietary API / features.There's probably other ways this could have been built, but this was what came to me as I was reading the code for the first time + have never touched Svelte before.
Check
backend logs
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.