经 AI Skill Hub 精选评估,通用LLM接口 获评「推荐使用」。已获得 2.0k 颗 GitHub Star,这款AI工具在功能完整性、社区活跃度和易用性方面表现出色,AI 评分 7.5 分,适合有一定技术背景的用户使用。
通用LLM接口 是一款基于 Python 开发的开源工具,专注于 ai、llm、python 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
通用LLM接口 是一款基于 Python 开发的开源工具,专注于 ai、llm、python 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
# 方式一:pip 安装(推荐)
pip install any-llm
# 方式二:虚拟环境安装(推荐生产环境)
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install any-llm
# 方式三:从源码安装(获取最新功能)
git clone https://github.com/mozilla-ai/any-llm
cd any-llm
pip install -e .
# 验证安装
python -c "import any_llm; print('安装成功')"
# 命令行使用
any-llm --help
# 基本用法
any-llm input_file -o output_file
# Python 代码中调用
import any_llm
# 示例
result = any_llm.process("input")
print(result)
# any-llm 配置文件示例(config.yml) app: name: "any-llm" debug: false log_level: "INFO" # 运行时指定配置文件 any-llm --config config.yml # 或通过环境变量配置 export ANY_LLM_API_KEY="your-key" export ANY_LLM_OUTPUT_DIR="./output"
<p align="center"> <picture> <img src="https://raw.githubusercontent.com/mozilla-ai/any-llm/refs/heads/main/docs/images/any-llm-logo-mark.png" width="20%" alt="Project logo"/> </picture> </p>
Install support for specific providers:
pip install 'any-llm-sdk[openai]' # Just OpenAI
pip install 'any-llm-sdk[mistral,ollama]' # Multiple providers
pip install 'any-llm-sdk[all]' # All supported providers
See our list of supported providers to choose which ones you need.
```python pip install 'any-llm-sdk[mistral,ollama]'
export MISTRAL_API_KEY="YOUR_KEY_HERE" # or OPENAI_API_KEY, etc from any_llm import completion import os
any-llm offers two main approaches for interacting with LLM providers:
Recommended approach: Use separate provider and model parameters:
```python from any_llm import completion import os
assert os.environ.get('MISTRAL_API_KEY')
response = completion( model="mistral-small-latest", provider="mistral", messages=[{"role": "user", "content": "Hello!"}] ) print(response.choices[0].message.content)
**That's it!** Change the provider name and add provider-specific keys to switch between LLM providers.
> **Coming from LiteLLM?** Your API keys and environment variables carry over unchanged. Install the SDK with extras for the providers you need, then update your import and model strings:
>
> bash > pip install 'any-llm-sdk[openai,anthropic]' # or [all] for everything > > python > # before > from litellm import completion > response = completion(model="openai/gpt-4o", messages=[...]) > > # after > from any_llm import completion > response = completion(model="openai:gpt-4o", messages=[...]) > ``` > > See Supported Providers to map your existing model strings.
That's the full migration — no proxy, no extra config.
Set environment variables for your chosen providers:
```bash export OPENAI_API_KEY="your-key-here" export ANTHROPIC_API_KEY="your-key-here" export MISTRAL_API_KEY="your-key-here"
assert os.environ.get('MISTRAL_API_KEY')
response = completion( model="mistral-small-latest", provider="mistral", messages=[{"role": "user", "content": "Hello!"}] ) print(response.choices[0].message.content)
**Alternative syntax:** Use combined `provider:model` format:
python response = completion( model="mistral:mistral-small-latest", # <provider_id>:<model_id> messages=[{"role": "user", "content": "Hello!"}] )
#### Option 2: AnyLLM Class (Recommended for Production)
For applications that need to reuse providers, perform multiple operations, or require more control:
python from any_llm import AnyLLM
llm = AnyLLM.create("mistral", api_key="your-mistral-api-key")
response = llm.completion( model="mistral-small-latest", messages=[{"role": "user", "content": "Hello!"}] )
```
| Approach | Best For | Connection Handling |
|---|---|---|
**Direct API Functions** (completion) | Scripts, notebooks, single requests | New client per call (stateless) |
**AnyLLM Class** (AnyLLM.create) | Production apps, multiple requests | Reuses client (connection pooling) |
Both approaches support identical features: streaming, tools, responses API, etc.
For providers that implement the OpenAI-style Responses API, use responses or aresponses:
```python from any_llm import responses
result = responses( model="gpt-4o-mini", provider="openai", input_data=[ {"role": "user", "content": [ {"type": "text", "text": "Summarize this in one sentence."} ]} ], )
统一LLM接口,方便开发
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
✅ Apache 2.0 — 宽松开源协议,可商用,需保留版权声明和 NOTICE 文件,含专利授权条款。
AI Skill Hub 点评:通用LLM接口 的核心功能完整,质量良好。对于AI 技术爱好者来说,这是一个值得纳入个人工具库的选择。建议先在非生产环境试用,再逐步推广。
| 原始名称 | any-llm |
| 原始描述 | 开源AI工具:Communicate with an LLM provider using a single interface。⭐2.0k · Python |
| Topics | aillmpython |
| GitHub | https://github.com/mozilla-ai/any-llm |
| License | Apache-2.0 |
| 语言 | Python |
收录时间:2026-05-26 · 更新时间:2026-05-26 · License:Apache-2.0 · AI Skill Hub 不对第三方内容的准确性作法律背书。