Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.
Before submitting, make sure you've checked the following:
Target branch: Please verify that the pull request targets the dev branch.
Description: This PR introduces new OpenAI-compliant /v1/embeddings API endpoints for both OpenAI-compatible services (via /openai/v1/embeddings) and Ollama backends (via /ollama/v1/embeddings). It includes shared Pydantic schemas for consistent request/response structures and a utility for token estimation.
Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
Documentation: API documentation is managed by FastAPI /docs page.
Dependencies: No new dependencies added.
Testing: I used curl commands to verify new endpoints work as expected without breaking older existing embedding endpoints. See the gist for the various commands.
Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
Prefix: To clearly categorize this pull request, prefix the pull request title using one of the following:
BREAKING CHANGE: Significant changes that may affect compatibility
build: Changes that affect the build system or external dependencies
ci: Changes to our continuous integration processes or workflows
chore: Refactor, cleanup, or other non-functional code changes
docs: Documentation update or addition
feat: Introduces a new feature or enhancement to the codebase
fix: Bug fix or error correction
i18n: Internationalization or localization changes
perf: Performance improvement
refactor: Code restructuring for better maintainability, readability, or scalability
style: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.)
test: Adding missing tests or correcting existing tests
WIP: Work in progress, a temporary label for incomplete or ongoing work
Changelog Entry
Description
This pull request introduces standardized, OpenAI-compliant embedding generation capabilities through new API endpoints. It adds POST /openai/v1/embeddings to interface with various configured OpenAI-compatible services and POST /ollama/v1/embeddings to provide an OpenAI-compliant interface for Ollama's embedding models. This enhancement aims to provide a consistent API for embedding generation, regardless of the backend service.
The implementation includes:
Shared Pydantic models (OpenAIEmbeddingsRequest, OpenAIEmbeddingsResponse, etc.) in backend/open_webui/models/openai_schemas.py for consistent OpenAI-compliant request/response handling across the new endpoints.
A token estimation utility (estimate_embedding_tokens) in backend/open_webui/utils/misc.py for use by the Ollama endpoint to populate usage statistics.
The /ollama/v1/embeddings endpoint performs translation of OpenAI-formatted requests to Ollama's native embedding request format and translates Ollama's responses back to the OpenAI schema.
The /openai/v1/embeddings endpoint routes requests to the appropriate configured OpenAI-compatible backend (e.g., official OpenAI, Azure OpenAI, other generic providers).
Added
New API endpoint POST /openai/v1/embeddings in backend/open_webui/routers/openai.py for generating embeddings using configured OpenAI-compatible services.
New API endpoint POST /ollama/v1/embeddings in backend/open_webui/routers/ollama.py for generating embeddings via Ollama, using an OpenAI-compliant interface.
New shared Pydantic models for OpenAI embedding schemas (OpenAIEmbeddingsRequest, OpenAIEmbeddingData, OpenAIUsage, OpenAIEmbeddingsResponse) in backend/open_webui/models/openai_schemas.py.
New utility function estimate_embedding_tokens in backend/open_webui/utils/misc.py to help estimate token counts for embedding inputs, primarily for Ollama.
New helper function _generate_ollama_embeddings_native (or similar) within backend/open_webui/routers/ollama.py to centralize Ollama's native embedding call logic.)*
Changed
Refactored existing Ollama native embedding logic within backend/open_webui/routers/ollama.py to utilize a new internal helper function. This improves code structure and reusability for calls to Ollama's /api/embed or /api/embeddings.)*
Utilizes existing model configuration mechanisms to fetch API keys, base URLs, and other parameters for OpenAI-compatible embedding models.
Deprecated
No functionality is deprecated by this PR. (Note: /ollama/api/embed is already marked as deprecated in the codebase prior to this work).
Removed
No functionality or files are removed by this PR.
Fixed
N/A (This PR is primarily a new feature).
Security
New endpoints adhere to existing authentication and authorization mechanisms within Open WebUI. User context is utilized for requests.
Breaking Changes
No breaking changes are introduced. Existing Ollama embedding endpoints (/ollama/api/embed and /ollama/api/embeddings) remain functional and unaffected.
Additional Information
[Insert any additional context, notes, or explanations for the changes]
[Reference any related issues, commits, or other relevant information]
Screenshots or Videos
N/A (Backend API changes). curl commands for testing have been successfully executed against a local development instance.
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 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/13898
**Author:** [@pranitl](https://github.com/pranitl)
**Created:** 5/15/2025
**Status:** ❌ Closed
**Base:** `dev` ← **Head:** `feature/openai-embeddings-schema`
---
### 📝 Commits (1)
- [`512cef2`](https://github.com/open-webui/open-webui/commit/512cef2c57c6e2e1ff53522cd79cf49dd7aeb26b) Add OpenAI embeddings schema support and update routers
### 📊 Changes
**6 files changed** (+450 additions, -264 deletions)
<details>
<summary>View changed files</summary>
📝 `backend/open_webui/main.py` (+93 -25)
➕ `backend/open_webui/models/embeddings.py` (+25 -0)
➕ `backend/open_webui/routers/local.py` (+99 -0)
📝 `backend/open_webui/routers/ollama.py` (+132 -225)
📝 `backend/open_webui/routers/openai.py` (+66 -2)
📝 `backend/open_webui/utils/models.py` (+35 -12)
</details>
### 📄 Description
# Pull Request Checklist
### Note to first-time contributors: Please open a discussion post in [Discussions](https://github.com/open-webui/open-webui/discussions) and describe your changes before submitting a pull request.
**Before submitting, make sure you've checked the following:**
- [X] **Target branch:** Please verify that the pull request targets the `dev` branch.
- [X] **Description:** This PR introduces new OpenAI-compliant /v1/embeddings API endpoints for both OpenAI-compatible services (via /openai/v1/embeddings) and Ollama backends (via /ollama/v1/embeddings). It includes shared Pydantic schemas for consistent request/response structures and a utility for token estimation.
- [x] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description.
- [x] **Documentation:** API documentation is managed by FastAPI /docs page.
- [x] **Dependencies:** No new dependencies added.
- [X] **Testing:** I used curl commands to verify new endpoints work as expected without breaking older existing embedding endpoints. See the [gist](https://gist.github.com/pranitl/0284c121e0b580b6e095a4a25f570f0b) for the various commands.
- [X] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
- [X] **Prefix:** To clearly categorize this pull request, prefix the pull request title using one of the following:
- **BREAKING CHANGE**: Significant changes that may affect compatibility
- **build**: Changes that affect the build system or external dependencies
- **ci**: Changes to our continuous integration processes or workflows
- **chore**: Refactor, cleanup, or other non-functional code changes
- **docs**: Documentation update or addition
- **feat**: Introduces a new feature or enhancement to the codebase
- **fix**: Bug fix or error correction
- **i18n**: Internationalization or localization changes
- **perf**: Performance improvement
- **refactor**: Code restructuring for better maintainability, readability, or scalability
- **style**: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.)
- **test**: Adding missing tests or correcting existing tests
- **WIP**: Work in progress, a temporary label for incomplete or ongoing work
# Changelog Entry
### Description
This pull request introduces standardized, OpenAI-compliant embedding generation capabilities through new API endpoints. It adds `POST /openai/v1/embeddings` to interface with various configured OpenAI-compatible services and `POST /ollama/v1/embeddings` to provide an OpenAI-compliant interface for Ollama's embedding models. This enhancement aims to provide a consistent API for embedding generation, regardless of the backend service.
The implementation includes:
- Shared Pydantic models (`OpenAIEmbeddingsRequest`, `OpenAIEmbeddingsResponse`, etc.) in `backend/open_webui/models/openai_schemas.py` for consistent OpenAI-compliant request/response handling across the new endpoints.
- A token estimation utility (`estimate_embedding_tokens`) in `backend/open_webui/utils/misc.py` for use by the Ollama endpoint to populate usage statistics.
- The `/ollama/v1/embeddings` endpoint performs translation of OpenAI-formatted requests to Ollama's native embedding request format and translates Ollama's responses back to the OpenAI schema.
- The `/openai/v1/embeddings` endpoint routes requests to the appropriate configured OpenAI-compatible backend (e.g., official OpenAI, Azure OpenAI, other generic providers).
### Added
- New API endpoint `POST /openai/v1/embeddings` in `backend/open_webui/routers/openai.py` for generating embeddings using configured OpenAI-compatible services.
- New API endpoint `POST /ollama/v1/embeddings` in `backend/open_webui/routers/ollama.py` for generating embeddings via Ollama, using an OpenAI-compliant interface.
- New shared Pydantic models for OpenAI embedding schemas (`OpenAIEmbeddingsRequest`, `OpenAIEmbeddingData`, `OpenAIUsage`, `OpenAIEmbeddingsResponse`) in `backend/open_webui/models/openai_schemas.py`.
- New utility function `estimate_embedding_tokens` in `backend/open_webui/utils/misc.py` to help estimate token counts for embedding inputs, primarily for Ollama.
- New helper function `_generate_ollama_embeddings_native` (or similar) within `backend/open_webui/routers/ollama.py` to centralize Ollama's native embedding call logic.)*
### Changed
- Refactored existing Ollama native embedding logic within `backend/open_webui/routers/ollama.py` to utilize a new internal helper function. This improves code structure and reusability for calls to Ollama's `/api/embed` or `/api/embeddings`.)*
- Utilizes existing model configuration mechanisms to fetch API keys, base URLs, and other parameters for OpenAI-compatible embedding models.
### Deprecated
- No functionality is deprecated by this PR. (Note: `/ollama/api/embed` is already marked as deprecated in the codebase prior to this work).
### Removed
- No functionality or files are removed by this PR.
### Fixed
- N/A (This PR is primarily a new feature).
### Security
- New endpoints adhere to existing authentication and authorization mechanisms within Open WebUI. User context is utilized for requests.
### Breaking Changes
- No breaking changes are introduced. Existing Ollama embedding endpoints (`/ollama/api/embed` and `/ollama/api/embeddings`) remain functional and unaffected.
---
### Additional Information
- [Insert any additional context, notes, or explanations for the changes]
- [Reference any related issues, commits, or other relevant information]
### Screenshots or Videos
- N/A (Backend API changes). `curl` commands for testing have been successfully executed against a local development instance.
### Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms.
---
<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/13898
Author: @pranitl
Created: 5/15/2025
Status: ❌ Closed
Base:
dev← Head:feature/openai-embeddings-schema📝 Commits (1)
512cef2Add OpenAI embeddings schema support and update routers📊 Changes
6 files changed (+450 additions, -264 deletions)
View changed files
📝
backend/open_webui/main.py(+93 -25)➕
backend/open_webui/models/embeddings.py(+25 -0)➕
backend/open_webui/routers/local.py(+99 -0)📝
backend/open_webui/routers/ollama.py(+132 -225)📝
backend/open_webui/routers/openai.py(+66 -2)📝
backend/open_webui/utils/models.py(+35 -12)📄 Description
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.
Before submitting, make sure you've checked the following:
devbranch.Changelog Entry
Description
This pull request introduces standardized, OpenAI-compliant embedding generation capabilities through new API endpoints. It adds
POST /openai/v1/embeddingsto interface with various configured OpenAI-compatible services andPOST /ollama/v1/embeddingsto provide an OpenAI-compliant interface for Ollama's embedding models. This enhancement aims to provide a consistent API for embedding generation, regardless of the backend service.The implementation includes:
OpenAIEmbeddingsRequest,OpenAIEmbeddingsResponse, etc.) inbackend/open_webui/models/openai_schemas.pyfor consistent OpenAI-compliant request/response handling across the new endpoints.estimate_embedding_tokens) inbackend/open_webui/utils/misc.pyfor use by the Ollama endpoint to populate usage statistics./ollama/v1/embeddingsendpoint performs translation of OpenAI-formatted requests to Ollama's native embedding request format and translates Ollama's responses back to the OpenAI schema./openai/v1/embeddingsendpoint routes requests to the appropriate configured OpenAI-compatible backend (e.g., official OpenAI, Azure OpenAI, other generic providers).Added
POST /openai/v1/embeddingsinbackend/open_webui/routers/openai.pyfor generating embeddings using configured OpenAI-compatible services.POST /ollama/v1/embeddingsinbackend/open_webui/routers/ollama.pyfor generating embeddings via Ollama, using an OpenAI-compliant interface.OpenAIEmbeddingsRequest,OpenAIEmbeddingData,OpenAIUsage,OpenAIEmbeddingsResponse) inbackend/open_webui/models/openai_schemas.py.estimate_embedding_tokensinbackend/open_webui/utils/misc.pyto help estimate token counts for embedding inputs, primarily for Ollama._generate_ollama_embeddings_native(or similar) withinbackend/open_webui/routers/ollama.pyto centralize Ollama's native embedding call logic.)*Changed
backend/open_webui/routers/ollama.pyto utilize a new internal helper function. This improves code structure and reusability for calls to Ollama's/api/embedor/api/embeddings.)*Deprecated
/ollama/api/embedis already marked as deprecated in the codebase prior to this work).Removed
Fixed
Security
Breaking Changes
/ollama/api/embedand/ollama/api/embeddings) remain functional and unaffected.Additional Information
Screenshots or Videos
curlcommands for testing have been successfully executed against a local development instance.Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.