0% found this document useful (0 votes)
99 views5 pages

Open WebUI API Endpoints Guide

This document serves as a guide for interacting with the Open WebUI API endpoints, detailing authentication methods and notable endpoints for retrieving models, chat completions, and utilizing Retrieval Augmented Generation (RAG). It includes examples in both curl and Python for various operations such as uploading files and referencing them in chat completions. Additionally, it highlights the advantages of using Open WebUI as a unified LLM provider and provides links to Swagger documentation for further reference.

Uploaded by

Bertony Quemasda
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views5 pages

Open WebUI API Endpoints Guide

This document serves as a guide for interacting with the Open WebUI API endpoints, detailing authentication methods and notable endpoints for retrieving models, chat completions, and utilizing Retrieval Augmented Generation (RAG). It includes examples in both curl and Python for various operations such as uploading files and referencing them in chat completions. Additionally, it highlights the advantages of using Open WebUI as a unified LLM provider and provides links to Swagger documentation for further reference.

Uploaded by

Bertony Quemasda
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

---

sidebar_position: 400
title: "🔗 API Endpoints"
---

This guide provides essential information on how to interact with the API endpoints
effectively to achieve seamless integration and automation using our models. Please
note that this is an experimental setup and may undergo future updates for
enhancement.

## Authentication

To ensure secure access to the API, authentication is required . You can


authenticate your API requests using the Bearer Token mechanism. Obtain your API
key from **Settings > Account** in the Open WebUI, or alternatively, use a JWT
(JSON Web Token) for authentication.

## Notable API Endpoints

### 📜 Retrieve All Models

- **Endpoint**: `GET /api/models`


- **Description**: Fetches all models created or added via Open WebUI.
- **Example**:

```bash
curl -H "Authorization: Bearer YOUR_API_KEY" [Link]
```

### 💬 Chat Completions

- **Endpoint**: `POST /api/chat/completions`


- **Description**: Serves as an OpenAI API compatible chat completion endpoint for
models on Open WebUI including Ollama models, OpenAI models, and Open WebUI
Function models.

- **Curl Example**:

```bash
curl -X POST [Link] \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "llama3.1",
"messages": [
{
"role": "user",
"content": "Why is the sky blue?"
}
]
}'
```

- **Python Example**:
```python
import requests

def chat_with_model(token):
url = '[Link]
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}
data = {
"model": "granite3.1-dense:8b",
"messages": [
{
"role": "user",
"content": "Why is the sky blue?"
}
]
}
response = [Link](url, headers=headers, data=data)
return [Link]()
```

### 🧩 Retrieval Augmented Generation (RAG)

The Retrieval Augmented Generation (RAG) feature allows you to enhance responses by
incorporating data from external sources. Below, you will find the methods for
managing files and knowledge collections via the API, and how to use them in chat
completions effectively.

#### Uploading Files

To utilize external data in RAG responses, you first need to upload the files. The
content of the uploaded file is automatically extracted and stored in a vector
database.

- **Endpoint**: `POST /api/v1/files/`


- **Curl Example**:

```bash
curl -X POST -H "Authorization: Bearer YOUR_API_KEY" -H "Accept:
application/json" \
-F "file=@/path/to/your/file" [Link]
```

- **Python Example**:

```python
import requests

def upload_file(token, file_path):


url = '[Link]
headers = {
'Authorization': f'Bearer {token}',
'Accept': 'application/json'
}
files = {'file': open(file_path, 'rb')}
response = [Link](url, headers=headers, files=files)
return [Link]()
```

#### Adding Files to Knowledge Collections

After uploading, you can group files into a knowledge collection or reference them
individually in chats.
- **Endpoint**: `POST /api/v1/knowledge/{id}/file/add`
- **Curl Example**:

```bash
curl -X POST [Link] \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"file_id": "your-file-id-here"}'
```

- **Python Example**:

```python
import requests

def add_file_to_knowledge(token, knowledge_id, file_id):


url = f'[Link]
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}
data = {'file_id': file_id}
response = [Link](url, headers=headers, json=data)
return [Link]()
```

#### Using Files and Collections in Chat Completions

You can reference both individual files or entire collections in your RAG queries
for enriched responses.

##### Using an Individual File in Chat Completions

This method is beneficial when you want to focus the chat model's response on the
content of a specific file.

- **Endpoint**: `POST /api/chat/completions`


- **Curl Example**:

```bash
curl -X POST [Link] \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4-turbo",
"messages": [
{"role": "user", "content": "Explain the concepts in this document."}
],
"files": [
{"type": "file", "id": "your-file-id-here"}
]
}'
```

- **Python Example**:

```python
import requests
def chat_with_file(token, model, query, file_id):
url = '[Link]
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}
payload = {
'model': model,
'messages': [{'role': 'user', 'content': query}],
'files': [{'type': 'file', 'id': file_id}]
}
response = [Link](url, headers=headers, json=payload)
return [Link]()
```

##### Using a Knowledge Collection in Chat Completions

Leverage a knowledge collection to enhance the response when the inquiry may
benefit from a broader context or multiple documents.

- **Endpoint**: `POST /api/chat/completions`


- **Curl Example**:

```bash
curl -X POST [Link] \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4-turbo",
"messages": [
{"role": "user", "content": "Provide insights on the historical
perspectives covered in the collection."}
],
"files": [
{"type": "collection", "id": "your-collection-id-here"}
]
}'
```

- **Python Example**:

```python
import requests

def chat_with_collection(token, model, query, collection_id):


url = '[Link]
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}
payload = {
'model': model,
'messages': [{'role': 'user', 'content': query}],
'files': [{'type': 'collection', 'id': collection_id}]
}
response = [Link](url, headers=headers, json=payload)
return [Link]()
```
These methods enable effective utilization of external knowledge via uploaded files
and curated knowledge collections, enhancing chat applications' capabilities using
the Open WebUI API. Whether using files individually or within collections, you can
customize the integration based on your specific needs.

## Advantages of Using Open WebUI as a Unified LLM Provider

Open WebUI offers a myriad of benefits, making it an essential tool for developers
and businesses alike:

- **Unified Interface**: Simplify your interactions with different LLMs through a


single, integrated platform.
- **Ease of Implementation**: Quick start integration with comprehensive
documentation and community support.

## Swagger Documentation Links

:::important
Make sure to set the `ENV` environment variable to `dev` in order to access the
Swagger documentation for any of these services. Without this configuration, the
documentation will not be available.
:::

Access detailed API documentation for different services provided by Open WebUI:

| Application | Documentation Path |


|-------------|-------------------------|
| Main | `/docs` |

By following these guidelines, you can swiftly integrate and begin utilizing the
Open WebUI API. Should you encounter any issues or have questions, feel free to
reach out through our Discord Community or consult the FAQs. Happy coding! 🌟

Common questions

Powered by AI

Open WebUI provides several advantages as a unified LLM provider: a unified interface simplifies interactions with different Large Language Models (LLMs) through a single platform, easing the overall implementation process with comprehensive documentation and community support. This allows developers to quickly start integration, reducing development time and resources while ensuring support for troubleshooting and innovation. Businesses benefit by having a versatile and efficient tool that streamlines AI process integration, making it suitable for diverse applications and potentially lowering operational costs .

To efficiently integrate and utilize the Open WebUI API, developers should begin by setting the `ENV` variable to `dev` to access Swagger documentation. They should obtain an API key or JWT for authentication, review available endpoints like retrieving models or managing RAG, and utilize example code snippets for implementing API calls such as chat completions or file uploads. Connecting with community resources and consulting FAQs on the Open WebUI platform can further aid in resolving any integration issues and optimize the utilization process effectively .

Future updates to the Open WebUI API could refine and possibly broaden the capabilities of API integrations, impacting existing systems. Potential enhancements might include more streamlined authentication procedures, expanded model support, improved data processing capabilities, and refined documentation. These updates could lead to more efficient and versatile integration processes, reducing overhead and improving the adaptability of systems using Open WebUI. Such changes may necessitate review and adjustment of current implementations to continue leveraging the most advanced features and maintaining compatibility .

The RAG feature in Open WebUI enhances chat completions by allowing integration of external data sources into responses. Files can be uploaded, converted into vectors, and stored in a database. These files or knowledge collections can then be referenced in chat completions, enriching responses with data-driven insights. This augmentation supports more informed and contextually aware AI interactions by utilizing specific document contents or broad contextual collections, making responses more relevant to user queries .

Developers can manage API requests securely on Open WebUI by utilizing the Bearer Token mechanism or JWT for authentication. Using JWT allows for secure, token-based authentication that can support more complex security requirements, such as specific user roles and scopes. It essentially enhances security by ensuring that each request is authenticated using a token representing user credentials, validating identity, and possibly establishing authorization levels, reducing risk of unauthorized access .

A unified interface like Open WebUI simplifies interactions with multiple models by consolidating processes into a single platform, creating efficiencies not readily available in ad-hoc or multiple platform approaches. This reduces the complexity associated with managing various LLM systems, notably improving user experience by standardizing operations and enhancing innovation through consistent API methods. Compared to other integration methods, this unified interface lowers the barrier of entry for developers and businesses, decreasing the time and resources needed while maintaining high flexibility and scalability in implementing diverse AI solutions .

Files can be uploaded by using the `POST /api/v1/files/` endpoint. After uploading, to incorporate an individual file into a RAG query for a targeted response, you can reference the file using its ID at the `POST /api/chat/completions` endpoint. Here, the file's content enhances the response contextually, ensuring that the information provided is more precise and relevant to the document in focus .

A developer using a knowledge collection in a chat completion might input the collection ID at the `POST /api/chat/completions` endpoint to leverage broader insights from multiple documents. This approach is beneficial when a query benefits from a wide context or multifaceted perspective. Conversely, referencing an individual file using its specific ID is advantageous for queries that require focused information from a particular document. This method is ideal for precise, in-depth responses with specific document content driving the accuracy of the information provided .

The `ENV` environment variable must be set to `dev` to enable access to the Swagger documentation for Open WebUI services. This setting is crucial for developers as it ensures the availability of detailed documentation needed to understand and use various API services effectively. Without setting this variable to `dev`, developers may be unable to access this necessary resource, hindering development processes and troubleshooting efforts .

Authentication with the Open WebUI API is conducted using the Bearer Token mechanism. Users can obtain the necessary API key from the 'Settings > Account' section in the Open WebUI. Additionally, users can authenticate using a JSON Web Token (JWT), offering flexibility in secure API access .

You might also like