Development using OpenWebUI API

OpenWebUI API Integration Questions and Issues

Current Behavior

When attempting to make an API request to the OpenWebUI endpoint, I receive a 301 Moved Permanently response from Cloudflare.

API Request Details

curl -X POST http://johnaic.pplus.ai/api/chat/completions \
-H "Authorization: Bearer MY-API-KEY" \
-H "Content-Type: application/json" \
-d '{"model": "llama3.1", "messages": [{"role": "user", "content": "Why is the sky blue?"}]}'

Response

<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>cloudflare</center>
</body>
</html>

Questions

1. API Integration Experience

Has anyone successfully implemented the API integration for development purposes? If so, could you share:

  • Your implementation approach
  • Any specific configurations needed
  • Common pitfalls to avoid

2. OpenAI API Compatibility

According to the documentation, the system is compatible with OpenAI API. But the documentation is not available of the same:
https://docs.openwebui.com/features/openai/

I’d appreciate insights on the following:

  • Experience using it as a standalone service
  • Integration success through LangChain
  • Any compatibility issues encountered

Reference Documentation

The official documentation indicates the following endpoints should be available:

2 Likes

Openwebui used to have proper swagger documentation. I think I might have to enable some environment variables to get this.

As for 301 response, that’s simple. You didn’t put in https:// in the URL. You can either change that or put in -L to follow redirects.

Please do try with this fix and let me know what you get.

Thanks for the suggestions! I’ve tried implementing the recommended fixes, and here’s what I found:

What I Tried

Following the previous suggestions, I modified my request by adding HTTPS protocol:

curl -L -X POST https://johnaic.pplus.ai/api/chat/completions \
-H "Authorization: Bearer MY-API-KEY" \
-H "Content-Type: application/json" \
-d '{"model": "llama3.1", "messages": [{"role": "user," "content": "Why is the sky blue?"}]}'

Current Status

The redirect issue is resolved, but I’m now getting a new error:

{"detail":"'llama3.1'"}

I have tried to edit the model names to verify it’s not the model name causing the issue. Following are the model names I tried:

"llama3.1-8b",  "llama3.1", "llama3.1:8B"

Also, please enable the swagger documentation. However, the best direction is to find implementation via the OpenAI API compatibility since this approach seems integrative.

I just added ENV=dev in the environment file and documentation is now enabled at https://johnaic.pplus.ai/docs

Please try this out. I think open-webui project removed the openai compatible API based links in their documentation. But I can still find OpenAI compatible API here: https://johnaic.pplus.ai/openai/docs

Please try it out and let me know how this works.

Progress Update

Thanks to the API documentation being enabled, I’ve successfully made a direct API call:

curl -X 'POST' \
  'https://johnaic.pplus.ai/openai/chat/completions?bypass_filter=false' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer MY-API-KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "neuralmagic/Meta-Llama-3.1-8B-Instruct-FP8",
    "messages": [
      {
        "role": "user",
        "content": "Why is the sky blue?"
      }
    ]
}'

The API returned a well-formed response with the expected format, confirming the basic API functionality is working.

It also works for endpoint:

https://johnaic.pplus.ai/api/chat/completions

Langchain Integration

I am also glad to share that the /openai endpoint is compatible with Langchain and working correctly.

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    openai_api_base="https://johnaic.pplus.ai/openai",
    api_key="MY-API-KEY",
    model_name="neuralmagic/Meta-Llama-3.1-8B-Instruct-FP8",
)

llm.invoke("Why is the sky blue?")

Maybe a tutorial on api keys are helpful. I got them but a tutorial will be helpful

Here’s how you get API keys. Go to account settings once you logged in at https://johnaic.pplus.ai/

Go to account

Create new API key

Copy the API key

And then you can use this in above langchain integration

1 Like

works well in curl but not via python request

import requests

url = 'https://johnaic.pplus.ai/openai/chat/completions?bypass_filter=false'

headers = {
    'accept': 'application/json',
    'Authorization': '', 
    'Content-Type': 'application/json'
}

# Define the payload
payload = {
    "model": "neuralmagic/Meta-Llama-3.1-8B-Instruct-FP8",
    "messages": [
        {
            "role": "user",
            "content": "Why is the sky blue?"
        }
    ]
}

response = requests.post(url, headers=headers, json=payload)

if response.status_code == 200:
    print(response.json())  
else:
    print(f"Error: {response.status_code}, {response.text}")

It just worked for me. I used the right bearer token in Authorization in the dict above. Here’s what I get printed

{'id': 'chat-4cc865431e6b4f8799a5b4a26dc9d6ac', 'object': 'chat.completion', 'created': 1736506464, 'model': 'neuralmagic/Meta-Llama-3.1-8B-Instruct-FP8', 'choices': [{'index': 0, 'message': {'role': 'assistant', 'content': "The sky appears blue because of a phenomenon called scattering, which is the way light interacts with the tiny molecules of gases in the atmosphere. Here's a simplified explanation:\n\n1. **Sunlight**: When the sun shines, it emits a wide range of electromagnetic radiation, including visible light, ultraviolet (UV) radiation, and infrared (IR) radiation.\n\n2. **Light scattering**: As sunlight enters the Earth's atmosphere, it encounters tiny molecules of gases such as nitrogen (N2) and oxygen (O2). These molecules are much smaller than the wavelength of light, so they scatter the light in all directions.\n\n3. **Blue light scattering**: The smaller molecules scatter the shorter (blue) wavelengths of light more than the longer (red) wavelengths. This is known as Rayleigh scattering, named after the British physicist Lord Rayleigh, who first described the effect in the late 19th century.\n\n4. **Our eyes see blue**: When we look at the sky, our eyes see the scattered blue light more than any other color. This is why the sky appears blue during the daytime, especially in the direction of the sun.\n\n5. **Other factors**: Other factors can affect the color of the sky, such as:\n\n* **Dust and water vapor**: Tiny particles in the atmosphere can scatter light in different ways, making the sky appear more hazy or milky.\n* **Sun's position**: The angle of the sun affects the amount of light that reaches our eyes, making the sky appear more intense or muted.\n* **Atmospheric conditions**: Weather conditions like clouds, fog, or pollution can alter the color of the sky.\n\nIn summary, the sky appears blue because of the scattering of sunlight by tiny molecules of gases in the atmosphere, which favors the shorter (blue) wavelengths of light.", 'tool_calls': []}, 'logprobs': None, 'finish_reason': 'stop', 'stop_reason': None}], 'usage': {'prompt_tokens': 41, 'total_tokens': 408, 'completion_tokens': 367}, 'prompt_logprobs': None}

Ensure to use Bearer <api-key> in the authorization header.

which container did you add the ENV variable to? I individually added it to ollama and open-webui. Did not see swagger documentation when i did https://chatllama.von-neumann.ai/docs

Gotta do it to open-webui container

1 Like

okie understood. Add it to the container and restart the application.

We updated the model to deepseek r1 distill 8b. You can access the API by changing the model id to JamAndTeaStudios/DeepSeek-R1-Distill-Llama-8B-FP8-Dynamic.

Here’s an example code in bash

# get the API key from johnaic.pplus.ai
MY_API_KEY=sk-xxxx
curl -X 'POST' \
  'https://johnaic.pplus.ai/openai/chat/completions?bypass_filter=false' \
  -H 'accept: application/json' \
  -H "Authorization: Bearer $MY_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "JamAndTeaStudios/DeepSeek-R1-Distill-Llama-8B-FP8-Dynamic",
    "messages": [
      {
        "role": "user",
        "content": "Why is the sky blue?"
      }
    ]
}'