LiteLLM Gateway
Connect ChatJS to a LiteLLM proxy, use its model aliases for chat and titles, and verify model discovery from a generated app.
The LiteLLM gateway routes chat requests through your proxy. The proxy owns the upstream provider credentials. ChatJS needs its API base URL, a model alias, and a proxy key if authentication is enabled.
Setup
- Configure a model on the proxy. In this example, the upstream OpenAI credential belongs in the proxy environment. ChatJS will use the alias
chat-main. LiteLLM proxy setup
model_list:
- model_name: chat-main
litellm_params:
model: openai/gpt-4o-mini
api_key: os.environ/OPENAI_API_KEY
- Select LiteLLM during app creation, or switch the gateway in an existing app. Run the command that matches your starting point.
# New app
npx chat-js@alpha create my-chat --gateway litellm
# Existing app, from its root
npx chat-js@alpha add --gateway litellm --replace
- Set the API base URL in the app’s
.env.local. For a proxy serving chat completions at/v1/chat/completions, include/v1. If the proxy requires authentication, also setLITELLM_API_KEYto a valid proxy key.
LITELLM_BASE_URL=http://localhost:4000/v1
- In the existing
ai.workflowsblock ofchat.config.ts, setchatandtitleto"chat-main". Use your own proxy aliases for any other workflow overrides. If you restrict the web picker, include an available alias in its model list.
Verify discovery and chat
With the proxy running, start the app, open the model picker, select chat-main, and send a message. Discovery requests /v1/models. Chat requests append /chat/completions to the configured base URL. If discovery succeeds but chat returns 404, compare that resulting chat path with the proxy route.
Image Generation
The stock LiteLLM gateway has no default image model in its registry metadata. The CLI therefore rejects the built-in generate-image tool with this gateway, even if the proxy exposes an image endpoint. To use that endpoint, install an external image tool that calls it, or package a custom gateway with image capability and an image model in defaults.roles.image.