feat(chat): add CHAT_PROVIDER env var for OpenAI/LangGraph fallback when Anthropic key is unavailable
Describe the issue After the recent migration of the chat agent to Anthropic native API, self-hosters who don't have an Anthropic API key can no longer use the AI chat feature at all. The backend crashes on startup or at request time with an authentication error because ANTHROPIC_API_KEY is required but not present.
I have implemented a fix that restores OpenAI/LangGraph as an optional fallback backend.
To Reproduce Steps to reproduce the behavior:
- Fork/clone the repository and self-host the backend
- Configure your .env with an OPENAI_API_KEY but no ANTHROPIC_API_KEY
- Start the backend: uvicorn main:app --host 0.0.0.0 --port 8080
- Send a chat message via the app
- See error
Current behavior The chat agent fails because anthropic_client requires ANTHROPIC_API_KEY. There is no fallback — the entire chat feature is unusable without an Anthropic account.
Screenshots -
When the user does not have Anthropic API keys -
Terminal error -
Mobile Application cahtbot response -
Expected behavior Self-hosters should be able to opt into the previous OpenAI/LangGraph backend using a single environment variable, with Anthropic remaining the default for all standard deployments.
Screenshots-
Using the switch between OpenAI (ChatGPT) API keys assuming you dont have anthropic API keys -
Mobile Application response using OpenAI API keys-
Proposed Solution (Already Implemented) I identified the minimal change needed and implemented it:
- CHAT_PROVIDER=anthropic (default) —> existing Anthropic behavior, zero breaking change
- CHAT_PROVIDER=openai — >falls back to LangGraph ReAct agent with OpenAI GPT
Changes touch only two files:
- backend/utils/retrieval/agentic.py — both implementations side by side, same public API
- backend/utils/llm/clients.py — exposes llm_agent / llm_agent_stream for the OpenAI path
The _ANTHROPIC_ONLY_FEATURES guard in clients.py is intentionally left untouched — the new OpenAI clients sit outside that system.
I have already changed the necessary code into my forked repo if you want to preview it I am attaching the link below I can create a PR on after reviews.
👉 Branch with fix: hellKing-Diablo/Void-AI:feature/multi-provider-chat-agent
Device / Environment
- OS: Linux / Windows / macOS (affects all self-hosted deployments)
- Backend: Python 3.11, FastAPI
- App Version: latest main
Additional context This does not affect Omi's hosted deployment in any way ,CHAT_PROVIDER defaults to anthropic and the variable doesn't need to be set unless you're self-hosting without Anthropic credentials. The tool list, safety guards, streaming protocol, and all public function signatures are identical between providers.