-
Notifications
You must be signed in to change notification settings - Fork 3.6k
feat(litellm): add LiteLLM as AI gateway provider #4739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
98926c5
feat: add LiteLLM as AI gateway provider
RheagalFire a991d5c
fix: add litellm to attachments, provider store, utils, and block guards
RheagalFire ae429a8
fix: add frontend model discovery pipeline for litellm provider
RheagalFire 72d9a9a
fix: remove azureEndpoint fallback from LiteLLM provider
RheagalFire 3f1b94b
fix(litellm): close audit gaps from PR #4644
waleedlatif1 b35606d
fix(litellm): final parity gaps from second audit
waleedlatif1 4185090
feat(litellm): use official LiteLLM brand icon and color
waleedlatif1 b965f70
chore(litellm): validate /v1/models response with shared schema in in…
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { createLogger } from '@sim/logger' | ||
| import { getErrorMessage } from '@sim/utils/errors' | ||
| import { type NextRequest, NextResponse } from 'next/server' | ||
| import { | ||
| providerModelsResponseSchema, | ||
| vllmUpstreamResponseSchema, | ||
| } from '@/lib/api/contracts/providers' | ||
| import { env } from '@/lib/core/config/env' | ||
| import { withRouteHandler } from '@/lib/core/utils/with-route-handler' | ||
| import { filterBlacklistedModels, isProviderBlacklisted } from '@/providers/utils' | ||
|
|
||
| const logger = createLogger('LiteLLMModelsAPI') | ||
|
|
||
| export const GET = withRouteHandler(async (_request: NextRequest) => { | ||
| if (isProviderBlacklisted('litellm')) { | ||
| logger.info('LiteLLM provider is blacklisted, returning empty models') | ||
| return NextResponse.json({ models: [] }) | ||
| } | ||
|
|
||
| const baseUrl = (env.LITELLM_BASE_URL || '').replace(/\/$/, '') | ||
|
|
||
| if (!baseUrl) { | ||
| logger.info('LITELLM_BASE_URL not configured') | ||
| return NextResponse.json({ models: [] }) | ||
| } | ||
|
|
||
| try { | ||
| logger.info('Fetching LiteLLM models', { baseUrl }) | ||
|
|
||
| const headers: Record<string, string> = { | ||
| 'Content-Type': 'application/json', | ||
| } | ||
|
|
||
| if (env.LITELLM_API_KEY) { | ||
| headers.Authorization = `Bearer ${env.LITELLM_API_KEY}` | ||
| } | ||
|
|
||
| const response = await fetch(`${baseUrl}/v1/models`, { | ||
| headers, | ||
| next: { revalidate: 60 }, | ||
| }) | ||
|
|
||
| if (!response.ok) { | ||
| logger.warn('LiteLLM service is not available', { | ||
| status: response.status, | ||
| statusText: response.statusText, | ||
| }) | ||
| return NextResponse.json({ models: [] }) | ||
| } | ||
|
|
||
| const data = vllmUpstreamResponseSchema.parse(await response.json()) | ||
| const allModels = data.data.map((model) => `litellm/${model.id}`) | ||
| const models = filterBlacklistedModels(allModels) | ||
|
|
||
| logger.info('Successfully fetched LiteLLM models', { | ||
| count: models.length, | ||
| filtered: allModels.length - models.length, | ||
| models, | ||
| }) | ||
|
|
||
| return NextResponse.json(providerModelsResponseSchema.parse({ models })) | ||
| } catch (error) { | ||
| logger.error('Failed to fetch LiteLLM models', { | ||
| error: getErrorMessage(error, 'Unknown error'), | ||
| baseUrl, | ||
| }) | ||
|
|
||
| return NextResponse.json({ models: [] }) | ||
| } | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.