issue: Chat metadata missing with openai compliant backends #4262

Closed
opened 2025-11-11 15:49:51 -06:00 by GiteaMirror · 2 comments
Owner

Originally created by @tylerwmarrs on GitHub (Mar 5, 2025).

Check Existing Issues

  • I have searched the existing issues and discussions.

Installation Method

Docker

Open WebUI Version

v0.5.7

Ollama Version (if applicable)

No response

Operating System

Ubuntu 22.04

Browser (if applicable)

No response

Confirmation

  • I have read and followed all instructions in README.md.
  • I am using the latest version of both Open WebUI and Ollama.
  • I have checked the browser console logs.
  • I have checked the Docker container logs.
  • I have listed steps to reproduce the bug in detail.

Expected Behavior

When creating a custom OpenAI compliant backend the chat_id and possibly other metadata should be handed off to the compliant API. This ensures that the chat session remains in context instead of a new chat session per prompt.

Actual Behavior

In the open-webui backend code all metadata is removed from the backend request to the OpenAI compliant API.

incoming form_data:
https://github.com/open-webui/open-webui/blob/main/backend/open_webui/routers/openai.py#L577

metadata is popped from payload removing it from later request:
https://github.com/open-webui/open-webui/blob/main/backend/open_webui/routers/openai.py#L587

request is made to API without metadata:
https://github.com/open-webui/open-webui/blob/main/backend/open_webui/routers/openai.py#L684

Steps to Reproduce

This is a code issue.

Logs & Screenshots

This is a code issue.

Additional Information

My team worked on an AWS Bedrock Agent model and interfaced with Open WebUI based on the AWS Bedrock Gateway code:
https://github.com/aws-samples/bedrock-access-gateway

While that source does not completely handle agents, we leveraged it as a starting point to make a compatible backend. In the source code above they always generate a new session instead of leveraging an existing chat_id. Adding the chat_id will make the user experience better.

Originally created by @tylerwmarrs on GitHub (Mar 5, 2025). ### Check Existing Issues - [x] I have searched the existing issues and discussions. ### Installation Method Docker ### Open WebUI Version v0.5.7 ### Ollama Version (if applicable) _No response_ ### Operating System Ubuntu 22.04 ### Browser (if applicable) _No response_ ### Confirmation - [x] I have read and followed all instructions in `README.md`. - [x] I am using the latest version of **both** Open WebUI and Ollama. - [x] I have checked the browser console logs. - [x] I have checked the Docker container logs. - [x] I have listed steps to reproduce the bug in detail. ### Expected Behavior When creating a custom OpenAI compliant backend the chat_id and possibly other metadata should be handed off to the compliant API. This ensures that the chat session remains in context instead of a new chat session per prompt. ### Actual Behavior In the open-webui backend code all metadata is removed from the backend request to the OpenAI compliant API. incoming form_data: https://github.com/open-webui/open-webui/blob/main/backend/open_webui/routers/openai.py#L577 metadata is popped from payload removing it from later request: https://github.com/open-webui/open-webui/blob/main/backend/open_webui/routers/openai.py#L587 request is made to API without metadata: https://github.com/open-webui/open-webui/blob/main/backend/open_webui/routers/openai.py#L684 ### Steps to Reproduce This is a code issue. ### Logs & Screenshots This is a code issue. ### Additional Information My team worked on an AWS Bedrock Agent model and interfaced with Open WebUI based on the AWS Bedrock Gateway code: https://github.com/aws-samples/bedrock-access-gateway While that source does not completely handle agents, we leveraged it as a starting point to make a compatible backend. In the source code above they always generate a new session instead of leveraging an existing chat_id. Adding the chat_id will make the user experience better.
GiteaMirror added the bug label 2025-11-11 15:49:51 -06:00
Author
Owner

@Classic298 commented on GitHub (Mar 5, 2025):

When creating a custom OpenAI compliant backend the chat_id and possibly other metadata should be handed off to the compliant API. This ensures that the chat session remains in context instead of a new chat session per prompt.

You need to call the chat_completed() endpoint (or something like that, i forgot the actual endpoint name, but it is something with 'complet') -> this will create a chat for the respective user and user's API key in OpenWebUI.

But when using the API, you are responsible on your own to handle the 'chat' and 'chat history' and so forth.
A simple completion request to the AI is just that. A completion based on what you send to the AI.
Whenever you send a completion request YOU need to send the entire chat history!
LLMs are stateless, and OpenWebUI does exactly what it needs to do. Which is completions, if you call the completions endpoint.
Either handle the chat and chat history yourself or use the completed endpoint to then create a chat within OpenWebUI itself - you'd then use OpenWebUI to handle the chat history.

Steps to Reproduce
This is a code issue.

Either you provide an explanation of what you are doing and what you want to do or it will be hard to help you with your specific issue.
I do not think this is a code issue. Please first tell the people what you are trying to do and what steps you are doing and what you expect to happen.
What API endpoint(s) are you using? Are you creating a chat in OpenWebUI via the API? Yes or no? Without steps to reproduce, it is impossible to tell.

Edit: The function you need to call is called chat_completed() - the API endpoint for it is /api/chat/completed - Assuming I understood correctly what you want to do.

@Classic298 commented on GitHub (Mar 5, 2025): > When creating a custom OpenAI compliant backend the chat_id and possibly other metadata should be handed off to the compliant API. This ensures that the chat session remains in context instead of a new chat session per prompt. You need to call the chat_completed() endpoint (or something like that, i forgot the actual endpoint name, but it is something with 'complet') -> this will create a chat for the respective user and user's API key in OpenWebUI. But when using the API, you are responsible on your own to handle the 'chat' and 'chat history' and so forth. A simple completion request to the AI is just that. A completion based on what you send to the AI. Whenever you send a completion request __**YOU**__ need to send the entire chat history! LLMs are stateless, and OpenWebUI does exactly what it needs to do. Which is completions, if you call the completions endpoint. Either handle the chat and chat history yourself or use the completed endpoint to then create a chat within OpenWebUI itself - you'd then use OpenWebUI to handle the chat history. > Steps to Reproduce > This is a code issue. Either you provide an explanation of what you are doing and what you want to do or it will be hard to help you with your specific issue. I do not think this is a code issue. Please first tell the people what you are trying to do and what steps you are doing and what you expect to happen. What API endpoint(s) are you using? Are you creating a chat in OpenWebUI via the API? Yes or no? Without steps to reproduce, it is impossible to tell. Edit: The function you need to call is called chat_completed() - the API endpoint for it is /api/chat/completed - Assuming I understood correctly what you want to do.
Author
Owner

@tjbck commented on GitHub (Mar 5, 2025):

You should use Functions for this

@tjbck commented on GitHub (Mar 5, 2025): You should use Functions for this
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#4262