# LiteLLM

**LiteLLM** 是一个开源 AI 网关和 Python SDK，由贝里AI公司（Berri AI Incorporated，简称BerriAI）构建，让应用能够通过一个兼容 OpenAI 的 API 调用 140 多家大语言模型提供商，并在其上叠加路由、负载均衡、预算、速率限制、护栏和访问控制。<sup>[1](https://www.litellm.ai/about)</sup> 它以两种形式提供：一种是从代码中直接调用提供商的 Python SDK；另一种是自托管的代理服务器（LLM 网关），供平台团队运行以管理整个组织的 LLM 访问。<sup>[2](https://docs.litellm.ai/docs/)</sup>

| 关键事实 | 详情 |
|---|---|
| 是什么 | 开源 AI 网关和 Python SDK；140 多家 LLM 提供商、MCP 服务器和智能体统一在一个兼容 OpenAI 的 API 之后<sup>[1](https://www.litellm.ai/about)</sup> |
| 开发者 | 贝里AI公司（Berri AI Incorporated），旧金山一家 Y Combinator 2023 年冬季批次公司；创始人克里什·多拉基亚（Krrish Dholakia，CEO）和伊尚·贾弗（Ishaan Jaffer，CTO）<sup>[1](https://www.litellm.ai/about)</sup> |
| 首次发布 | 2023 年 7 月 27 日；此后已在 GitHub、PyPI 和 ghcr.io/berriai/litellm 上发布 1,400 多个版本<sup>[1](https://www.litellm.ai/about)</sup> |
| 规模 | PyPI 月下载量超过 9,500 万次；GitHub 星标超过 4 万，提交超过 3 万次<sup>[3](https://www.itpro.com/security/litellm-pypi-compromise-everything-we-know-so-far)</sup> |
| 许可证 | 核心部分采用 MIT 许可证；`enterprise/` 目录在生产环境需要付费许可证<sup>[1](https://www.litellm.ai/about)</sup> |
| 2026 年 3 月入侵事件 | PyPI 1.82.7 和 1.82.8 版本携带收集凭据的后门约 40 分钟；两个版本均被移除<sup>[4](https://www.endorlabs.com/learn/teampcp-isnt-done)</sup><sup> • </sup><sup>[5](https://www.itpro.com/security/cyber-attacks/the-litellm-supply-chain-attack-this-year-could-be-the-biggest-ever)</sup> |
| 重要 CVE | CVE-2026-42208，预认证 SQL 注入，CVSS 9.3，在 1.83.7 中修复<sup>[6](https://github.com/advisories/GHSA-r75f-5x8p-qvmc)</sup> |

## 起源与公司

LiteLLM 源于创始人在 [Y Combinator](https://www.edgepedia.org/zh/y-combinator) 2023 年冬季批次之后遇到的一个实际问题。克里什·多拉基亚和伊尚·贾弗为一个聊天机器人接入了微软 Azure（Azure）和 Cohere；Azure 调用经常失败，于是他们添加了从 Azure 到 Cohere 再到 OpenAI 的回退链，而针对每个提供商的代码变成了冗长且难以调试的 if/else 块。他们把全部 LLM 调用封装进一个包中，并于 2023 年 7 月 27 日以 LiteLLM 发布。<sup>[1](https://www.litellm.ai/about)</sup> 贾弗于 2023 年 7 月写下第一个提交，至今仍是提交次数最多的贡献者。<sup>[1](https://www.litellm.ai/about)</sup>

公司从 Y Combinator、Gravity Fund 和 [Pioneer Fund](https://www.edgepedia.org/zh/pioneer-fund) 筹集了 160 万美元种子轮，并以开放方式构建网关，拥有 1,700 多名 GitHub 贡献者。<sup>[1](https://www.litellm.ai/about)</sup> 发布工程流程异常严密：每个容器镜像都带有 cosign 签名，稳定标签只有在 12 小时负载测试之后才会发布。<sup>[1](https://www.litellm.ai/about)</sup>

## SDK 与网关的功能

Python SDK 提供统一函数，例如 `litellm.completion()`、`litellm.embedding()` 和 `image_generation()`，将各提供商的错误映射为 OpenAI 异常类型，如 `AuthenticationError` 和 `RateLimitError`，并支持通过 `stream=True` 进行流式传输。<sup>[2](https://docs.litellm.ai/docs/)</sup>

代理服务器位于应用与提供商之间。在其文档描述的请求流程中，用户请求首先通过虚拟密钥验证（先查 Redis 或内存缓存，再查数据库）以及服务器、密钥、用户和团队级别的限流；然后到达 LiteLLM 路由器，该路由器负责负载均衡、回退和重试，之后由 `litellm.completion()` 发起实际的提供商调用。支出日志、限流计数和日志回调作为异步后台任务运行，因此请求路径中没有任何数据库写入。<sup>[7](https://docs.litellm.ai/docs/proxy/architecture)</sup>

**路由。** 模型组由多个共享同一 `model_name` 的 LLM API 部署组成，请求可以在组内各部署之间进行均衡。重试留在失败的模型组内；回退则离开该组，转向回退配置中的下一个组。路由策略包括加权选择、限流感知、最不繁忙、基于延迟和基于成本。<sup>[7](https://docs.litellm.ai/docs/proxy/architecture)</sup><sup> • </sup><sup>[8](https://docs.litellm.ai/docs/routing)</sup> `RetryPolicy` 可以按错误类型设置重试次数，例如 `RateLimitErrorRetries` 或 `NotFoundErrorRetries`，并用 `DefaultRetries` 字段处理其他所有情况。<sup>[8](https://docs.litellm.ai/docs/routing)</sup>

网关还提供 MCP 网关，为 MCP 工具暴露固定端点，访问由密钥和团队控制；提供虚拟密钥，支持按密钥、团队和用户设置预算；以及集中式日志、护栏、缓存和管理界面。<sup>[9](https://docs.litellm.ai/docs/mcp/)</sup><sup> • </sup><sup>[2](https://docs.litellm.ai/docs/)</sup> 开源 AI 项目和智能体框架，包括 [OpenAI Agents SDK](https://www.edgepedia.org/zh/openai-agents-sdk)、Google ADK 和 [OpenHands](https://www.edgepedia.org/zh/openhands)，使用 LiteLLM 连接多个提供商。<sup>[1](https://www.litellm.ai/about)</sup>

## 采用情况

贝里AI列出的生产用户包括奈飞（Netflix）、英伟达（NVIDIA）、Okta、AT&T、Lemonade、苏黎世保险（Zurich）、Cloudera、Twilio、IBM、SAP、Ramp 和美国国家航空航天局（NASA），并将典型用户描述为：为数百名工程师提供网关访问并按团队跟踪成本的平台团队，以及需要本地或气隙安装并支持 SSO 和审计日志的受监管行业组织。<sup>[1](https://www.litellm.ai/about)</sup> 对比网站将 LiteLLM 描述为事实上的标准开源 LLM 网关，同时指出替代方案在托管运维、治理或网关开销方面有所不同。<sup>[10](https://www.kosmoy.com/resources/blog/litellm-alternatives/)</sup>

## 安全事件与漏洞

**2026 年 3 月 PyPI 供应链入侵。** 2026 年 3 月 24 日，Endor Labs 的研究人员发现 PyPI 上的 `litellm` 1.82.7 和 1.82.8 版本包含上游 GitHub 仓库中没有的恶意代码；注入发生在 wheel 构建期间或之后，向 `proxy_server.py` 添加了 12 行代码。<sup>[4](https://www.endorlabs.com/learn/teampcp-isnt-done)</sup> 两个版本都在导入时执行隐藏载荷，1.82.8 还安装了一个 `.pth` 文件，该文件会在任何 Python 调用时运行载荷，即使从未导入 litellm。该载荷收集 SSH 密钥、云令牌、[Kubernetes](https://www.edgepedia.org/zh/kubernetes) 密钥、加密货币钱包和 .env 文件，在 Kubernetes 集群中部署特权 Pod 以进行横向移动，并安装持久的 systemd 后门。<sup>[4](https://www.endorlabs.com/learn/teampcp-isnt-done)</sup> 恶意版本在 PyPI 上存在约 40 分钟后被移除；1.82.6 版本是最后一个已知干净的版本。<sup>[4](https://www.endorlabs.com/learn/teampcp-isnt-done)</sup><sup> • </sup><sup>[5](https://www.itpro.com/security/cyber-attacks/the-litellm-supply-chain-attack-this-year-could-be-the-biggest-ever)</sup>

Endor Labs 以高置信度将攻击归因于 TeamPCP，该组织曾入侵 Aqua Security 的 Trivy 扫描器和 Checkmarx 的 KICS，此次行动横跨 [GitHub Actions](https://www.edgepedia.org/zh/github-actions)、Docker Hub、npm、OpenVSX 和 PyPI。<sup>[4](https://www.endorlabs.com/learn/teampcp-isnt-done)</sup> 安全公司 CloudSEK 和 Hudson Rock 后来报告称，包括英伟达、三星（Samsung）、思科（Cisco）、ServiceNow、Zscaler、Salesforce 和[亚马逊云科技](https://www.edgepedia.org/zh/amazon-web-services)（Amazon Web Services）在内的 2,500 多个组织有凭据暴露；他们强调，暴露并不等于已遭入侵。暴露的材料包括 AWS、谷歌云（Google Cloud）和微软 Azure 凭据、SSH 密钥、Kubernetes 令牌、.env 文件、CI/CD 机密，以及针对 AI 构建的 LLM API 密钥和网关配置。<sup>[5](https://www.itpro.com/security/cyber-attacks/the-litellm-supply-chain-attack-this-year-could-be-the-biggest-ever)</sup>

**漏洞。** CVE-2026-42208 是代理 API 密钥验证中的一个严重 SQL 注入漏洞（CVSS 9.3），影响 1.81.16 至 1.83.7 之前的版本；未认证攻击者可以通过任意 LLM API 路由的错误处理路径触达存在漏洞的查询，并读取或修改代理数据库。该漏洞在 1.83.7 中修复，临时缓解措施为 `disable_error_logs: true`，并被加入 CISA 的已知被利用漏洞目录。<sup>[6](https://github.com/advisories/GHSA-r75f-5x8p-qvmc)</sup> 一个相关的命令注入漏洞 CVE-2026-42271 也在 1.83.7 中修复，并于 6 月被加入 CISA 列表；该漏洞中两个端点会在主机上运行提供的命令，且没有角色检查。<sup>[11](https://www.tomshardware.com/tech-industry/cyber-security/cryptomining-malware-used-poetry-to-infect-more-than-3-400-servers-researchers-say-four-words-in-the-poellm-verse-changed-11-times-point-the-botnet-to-new-servers)</sup>

**PoeLLM 挖矿活动。** Lumen 的 Black Lotus Labs 追踪了一个名为 Canto Incognito 的行动，其中名为 PoeLLM 的挖矿恶意软件攻击了 3,400 多台服务器，许多服务器运行着包括 LiteLLM 和 Ollama 在内的开源 AI 服务的易受攻击版本。对 LiteLLM 而言，利用 CVE-2026-42271 向连接端点发送精心构造的 POST 请求可能是攻击路径。该载荷运行连接 Kryptex 基础设施的 XMRig 和 Iron 挖矿程序，受感染服务器成为扫描器和漏洞利用服务器。<sup>[11](https://www.tomshardware.com/tech-industry/cyber-security/cryptomining-malware-used-poetry-to-infect-more-than-3-400-servers-researchers-say-four-words-in-the-poellm-verse-changed-11-times-point-the-botnet-to-new-servers)</sup>

## References

1. [About LiteLLM | The Open-Source AI Gateway](https://www.litellm.ai/about)
2. [Getting Started | LiteLLM](https://docs.litellm.ai/docs/)
3. [Top LLM PyPI package compromised to steal user details, TechRadar](https://www.itpro.com/security/litellm-pypi-compromise-everything-we-know-so-far)
4. [TeamPCP Isn't Done: Threat Actor Behind Trivy and KICS Compromises Now Hits LiteLLM's 95 Million Monthly Downloads on PyPI, Endor Labs](https://www.endorlabs.com/learn/teampcp-isnt-done)
5. [The LiteLLM supply chain attack this year could be the biggest ever, IT Pro](https://www.itpro.com/security/cyber-attacks/the-litellm-supply-chain-attack-this-year-could-be-the-biggest-ever)
6. [LiteLLM has SQL Injection in Proxy API key verification, CVE-2026-42208, GitHub Advisory Database](https://github.com/advisories/GHSA-r75f-5x8p-qvmc)
7. [Life of a Request | LiteLLM](https://docs.litellm.ai/docs/proxy/architecture)
8. [Router - Load Balancing | LiteLLM](https://docs.litellm.ai/docs/routing)
9. [MCP Overview | LiteLLM](https://docs.litellm.ai/docs/mcp/)
10. [LiteLLM Alternatives (2026): 7 Gateways Compared, Kosmoy](https://www.kosmoy.com/resources/blog/litellm-alternatives/)
11. [Cryptomining malware used poetry to infect more than 3,400 servers, Tom's Hardware](https://www.tomshardware.com/tech-industry/cyber-security/cryptomining-malware-used-poetry-to-infect-more-than-3-400-servers-researchers-say-four-words-in-the-poellm-verse-changed-11-times-point-the-botnet-to-new-servers)

---
*Initially written Oct 15, 2026*

Topic: 社会与历史 › 经济与商业 › 商业与工作 › Business and work overview › Companies and corporations › Venture-backed startups and growth companies › Software, internet, and enterprise-technology startups › Developer tools and open-source software

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/litellm

English original: https://www.edgepedia.org/litellm
