feat: add LiteLLM as AI gateway provider#4644
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Introduces a new Plumbs LiteLLM through the UI/state layer: provider model syncing ( Reviewed by Cursor Bugbot for commit b4268ec. Bugbot is set up for automated code reviews on this repo. Configure here. |
Greptile SummaryThis PR adds LiteLLM as a new AI gateway provider, enabling access to 100+ LLM backends through a LiteLLM proxy server. It follows the existing vLLM pattern throughout: OpenAI SDK with a custom
Confidence Score: 3/5Safe to merge for server-side execution, but end-to-end model discovery in the UI is broken without additional files that were not included in this PR. The server-side execution path (initialize, executeRequest, tool loop, streaming) is complete and correct. However, the client-side model discovery pipeline is entirely absent: no API route, no contract, no query hook case, and no ProviderModelsLoader entry for litellm. Without these, users can type in a model name manually but the model selector will show nothing for LiteLLM, making the feature appear non-functional in the UI. The four files that need to be added or updated to complete the frontend pipeline: apps/sim/app/api/providers/litellm/models/route.ts (new), apps/sim/lib/api/contracts/providers.ts, apps/sim/hooks/queries/providers.ts, and apps/sim/app/workspace/[workspaceId]/providers/provider-models-loader.tsx. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client as Browser (ProviderModelsLoader)
participant API as /api/providers/litellm/models ❌ missing
participant Init as litellmProvider.initialize()
participant Proxy as LiteLLM Proxy (/v1/models)
participant Exec as litellmProvider.executeRequest()
Note over Client,API: Frontend model discovery (NOT implemented)
Client--xAPI: GET /api/providers/litellm/models (no route exists)
Note over Init,Proxy: Server-side initialization (works correctly)
Init->>Proxy: GET /v1/models
Proxy-->>Init: "{ data: [{ id: 'anthropic/claude-...' }] }"
Init->>Init: "this.models = ['litellm/anthropic/...']"
Init->>Init: setProviderModels('litellm', models)
Note over Client,Exec: Execution flow (works correctly)
Client->>Exec: "POST /api/providers { provider: 'litellm', model: 'litellm/...' }"
Exec->>Proxy: "chat.completions.create (OpenAI SDK, baseURL=LITELLM_BASE_URL/v1)"
Proxy-->>Exec: ChatCompletion / Stream
Exec-->>Client: ProviderResponse / StreamingExecution
Reviews (1): Last reviewed commit: "fix: add litellm to attachments, provide..." | Re-trigger Greptile |
| name: 'LiteLLM', | ||
| icon: LitellmIcon, | ||
| description: 'LiteLLM proxy with an OpenAI-compatible API', | ||
| defaultModel: 'litellm/generic', |
There was a problem hiding this comment.
The
defaultModel value 'litellm/generic' is not a real model ID and will produce a confusing error when it is used as the initial default before any models are discovered (e.g. if the proxy is unreachable). Aligning with the vLLM pattern of leaving defaultModel as an empty string avoids sending a bogus model ID to the proxy.
| defaultModel: 'litellm/generic', | |
| defaultModel: '', |
Add API route, contract, query hook case, and ProviderModelsLoader entry so litellm models are fetched and synced to the store on workspace load, matching the vllm/ollama/openrouter/fireworks pattern. Also fixes defaultModel to empty string and adds litellm/ prefix early-return in blocks/utils.ts (reviewer feedback).
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 475820a. Configure here.
Copy-paste artifact from vLLM provider. LiteLLM should only use LITELLM_BASE_URL, not fall back to azureEndpoint which could cause requests to be routed to the wrong server.
- byok.ts: add litellm branch to getApiKeyWithBYOK so workflow block execution can resolve the proxy key instead of throwing "API key is required for litellm ..." - check-api-validation-contracts.ts: bump route baseline 755 -> 756 to account for the new /api/providers/litellm/models route - .env.example: document LITELLM_BASE_URL / LITELLM_API_KEY - copilot edit-workflow validation: include LiteLLM in the list of user-configured prefixed providers shown to the model - providers/utils.ts: drop stray optional-chain on providers.litellm to match the vllm pattern - lint: apply biome formatting fixes (multi-line if, SVG path, multi-line DYNAMIC_MODEL_PROVIDERS)
- byok.ts: add litellm branch to getApiKeyWithBYOK so workflow block execution can resolve the proxy key instead of throwing "API key is required for litellm ..." - check-api-validation-contracts.ts: bump route baseline 755 -> 756 to account for the new /api/providers/litellm/models route - .env.example: document LITELLM_BASE_URL / LITELLM_API_KEY - copilot edit-workflow validation: include LiteLLM in the list of user-configured prefixed providers shown to the model - providers/utils.ts: drop stray optional-chain on providers.litellm to match the vllm pattern - lint: apply biome formatting fixes (multi-line if, SVG path, multi-line DYNAMIC_MODEL_PROVIDERS)
* feat: add LiteLLM as AI gateway provider * fix: add litellm to attachments, provider store, utils, and block guards * fix: add frontend model discovery pipeline for litellm provider Add API route, contract, query hook case, and ProviderModelsLoader entry so litellm models are fetched and synced to the store on workspace load, matching the vllm/ollama/openrouter/fireworks pattern. Also fixes defaultModel to empty string and adds litellm/ prefix early-return in blocks/utils.ts (reviewer feedback). * fix: remove azureEndpoint fallback from LiteLLM provider Copy-paste artifact from vLLM provider. LiteLLM should only use LITELLM_BASE_URL, not fall back to azureEndpoint which could cause requests to be routed to the wrong server. * fix(litellm): close audit gaps from PR #4644 - byok.ts: add litellm branch to getApiKeyWithBYOK so workflow block execution can resolve the proxy key instead of throwing "API key is required for litellm ..." - check-api-validation-contracts.ts: bump route baseline 755 -> 756 to account for the new /api/providers/litellm/models route - .env.example: document LITELLM_BASE_URL / LITELLM_API_KEY - copilot edit-workflow validation: include LiteLLM in the list of user-configured prefixed providers shown to the model - providers/utils.ts: drop stray optional-chain on providers.litellm to match the vllm pattern - lint: apply biome formatting fixes (multi-line if, SVG path, multi-line DYNAMIC_MODEL_PROVIDERS) * fix(litellm): final parity gaps from second audit - blocks/utils.ts getModelOptions(): include litellm models in the combined model dropdown — was previously dropping any proxy-discovered models from the agent block model picker. - get-blocks-metadata-tool.ts mockProvidersState: add litellm bucket so the server-side copilot block-metadata fallback can render model options when the providers store is not initialized. - blocks/utils.test.ts: add litellm to mock providers state (initial + beforeEach reset) and add a parallel store-bucket guard test mirroring the vLLM case. - providers/utils.test.ts: add parallel getApiKey test for litellm. * feat(litellm): use official LiteLLM brand icon and color - icons.tsx: replace the placeholder letterform with the official LiteLLM brand mark embedded as a PNG data URI in an SVG image. - models.ts: set color: #040229 on the litellm provider definition to match the brand background. * chore(litellm): validate /v1/models response with shared schema in initialize() Match the API route handler — both code paths now run the same vllmUpstreamResponseSchema.parse() over the upstream /v1/models JSON instead of a raw type-cast, so malformed upstream payloads surface a descriptive ZodError instead of a downstream TypeError. Addresses Greptile review feedback on PR #4739. --------- Co-authored-by: RheagalFire <arishalam121@gmail.com>

Summary
Adds LiteLLM as a provider, enabling access to 100+ LLM backends through a LiteLLM proxy server. Follows the vLLM provider pattern (OpenAI SDK with custom baseURL, dynamic model discovery via
/v1/models).Fixes #2859
Type of Change
Testing
Model discovery:
Basic completion through LiteLLM proxy:
Streaming:
Tool calling:
All tests use OpenAI SDK with
baseURL: http://localhost:4000/v1pointing at a LiteLLM proxy, which is exactly what the provider does.Deep-dive bugs found and fixed:
attachments.ts:formatMessagesForProvidermissing litellm (would hit exhaustivenevercheck at runtime)blocks/utils.ts: litellm not excluded from API key requirement check (dynamic providers don't need pre-configured keys)providers/utils.ts: missing metadata,getBaseModelProvidersexclusion, andgetApiKeyhandlerstores/providers: missingProviderNametype and store defaultsChecklist