Nango API Integration for AI Agents
Nango provides unified API access for AI agents with OAuth handling, 700+ pre-built integrations, and MCP server support. This skill helps you connect your agent to any external API.
Why Nango for Agents?
- - 700+ APIs pre-integrated - No need to build each integration from scratch
- 2800+ pre-built actions - Ready-to-use API operations
- MCP servers per app - Model Context Protocol support
- 1:1 API access - No abstraction layer, you see exact API requests
- White-label OAuth - Embeddable auth flows
- Any backend language - Works with Python, Node, etc.
- AI-generated code - Write integration logic with AI
Quick Start
Step 1: Create Nango Account
- 1. Go to https://nango.dev
- Sign up for a free account
- Create a new project
- Get your API key from Settings
Step 2: Install Nango SDK
CODEBLOCK0
Step 3: Configure Environment
Add to your environment:
CODEBLOCK1
Integration Patterns
Pattern 1: OAuth Flow
For APIs requiring OAuth (Google, Slack, GitHub, etc.):
CODEBLOCK2
Pattern 2: API Key
For APIs using API keys (Stripe, OpenAI, etc.):
CODEBLOCK3
Pattern 3: MCP Server
For Model Context Protocol integration:
CODEBLOCK4
Popular API Integrations
| Provider | Use Case | Auth Type |
|---|
| Google | Gmail, Calendar, Drive | OAuth |
| Slack |
Messages, Channels | OAuth |
| GitHub | Repos, Issues, PRs | OAuth |
| Salesforce | CRM Data | OAuth |
| Stripe | Payments | API Key |
| Notion | Notes, Databases | OAuth |
| Linear | Issues, Projects | OAuth |
| HubSpot | CRM, Marketing | OAuth |
Creating Custom Integrations
Template for New Provider
CODEBLOCK5
Deploy Custom Integration
CODEBLOCK6
Error Handling
CODEBLOCK7
Best Practices for Agents
1. Connection Management
- - Store connection IDs with user context
- Check connection health before operations
- Implement re-auth flows automatically
2. Error Recovery
- - Handle rate limits gracefully
- Cache frequently accessed data
- Provide clear error messages to users
3. Security
- - Never expose API keys in prompts
- Use environment variables for secrets
- Implement permission scoping
4. Performance
- - Batch operations when possible
- Use webhooks instead of polling
- Implement request caching
MCP Integration for OpenClaw
To use Nango with OpenClaw agents:
CODEBLOCK8
Common Issues
Issue: "Connection not found"
- - Ensure connection_id matches what was created
- Check if credentials expired
Issue: "Provider not supported"
- - Check full list at https://nango.dev/integrations
- Create custom integration for unsupported providers
Issue: "Rate limited"
- - Implement exponential backoff
- Consider upgrading Nango plan
Resources
- - Nango Dashboard: https://app.nango.dev
- Documentation: https://docs.nango.dev
- Integration Catalog: https://nango.dev/integrations
- GitHub: https://github.com/NangoHQ/nango
- Community: https://nango.dev/community
Pricing
- - Free Tier: 10,000 API calls/month
- Pro: $49/month for 100,000 calls
- Enterprise: Custom pricing for unlimited
Free tier is sufficient for development and small projects.
面向AI代理的Nango API集成
Nango为AI代理提供统一的API访问,支持OAuth处理、700多个预构建集成以及MCP服务器支持。此技能帮助您将代理连接到任何外部API。
为什么选择Nango用于代理?
- - 700多个预集成API - 无需从头构建每个集成
- 2800多个预构建操作 - 即用型API操作
- 每个应用的MCP服务器 - 模型上下文协议支持
- 1:1 API访问 - 无抽象层,您能看到确切的API请求
- 白标OAuth - 可嵌入的身份验证流程
- 任何后端语言 - 支持Python、Node等
- AI生成代码 - 使用AI编写集成逻辑
快速开始
步骤1:创建Nango账户
- 1. 访问 https://nango.dev
- 注册免费账户
- 创建新项目
- 从设置中获取API密钥
步骤2:安装Nango SDK
bash
Python
pip install nango
Node.js
npm install @nangohq/node-client
步骤3:配置环境
添加到您的环境变量:
bash
NANGOSECRETKEY=您的密钥
NANGO_HOST=https://api.nango.dev # 或自托管
集成模式
模式1:OAuth流程
适用于需要OAuth的API(Google、Slack、GitHub等):
python
from nango import Nango
nango = Nango()
获取OAuth URL
auth
url = nango.getauth_url(
provider=google,
redirect_uri=https://your-app.com/callback
)
用户访问auth_url,授权后返回code
用code交换连接
connection = nango.create_connection(
provider=google,
code=来自回调的授权码,
connection_id=user-google-123
)
现在进行API调用
result = nango.proxy(
provider=google,
endpoint=/gmail/v1/users/me/messages,
connection_id=user-google-123
)
模式2:API密钥
适用于使用API密钥的API(Stripe、OpenAI等):
python
from nango import Nango
nango = Nango()
为提供者设置API密钥
nango.set_credentials(
provider=stripe,
connection_id=user-stripe-123,
credentials={api
key: sktest_xxx}
)
进行调用
customers = nango.proxy(
provider=stripe,
endpoint=/v1/customers,
connection_id=user-stripe-123
)
模式3:MCP服务器
用于模型上下文协议集成:
python
获取提供者的MCP服务器配置
mcp
config = nango.getmcp_server(
provider=github,
connection_id=user-github-123
)
与兼容MCP的代理一起使用
配置包含工具、资源和提示
热门API集成
| 提供者 | 用例 | 认证类型 |
|---|
| Google | Gmail、日历、云端硬盘 | OAuth |
| Slack |
消息、频道 | OAuth |
| GitHub | 仓库、问题、PR | OAuth |
| Salesforce | CRM数据 | OAuth |
| Stripe | 支付 | API密钥 |
| Notion | 笔记、数据库 | OAuth |
| Linear | 问题、项目 | OAuth |
| HubSpot | CRM、营销 | OAuth |
创建自定义集成
新提供者模板
typescript
// integrations/my-custom-api.ts
import { NangoIntegration } from @nangohq/types;
export default NangoIntegration({
// 提供者名称
provider: my-custom-api,
// 认证类型
auth: {
type: api_key, // 或 oauth2, basic
credentials: {
api_key: { type: string, required: true }
}
},
// 可用操作
actions: {
list_items: {
endpoint: /items,
method: GET,
output: { type: array }
},
create_item: {
endpoint: /items,
method: POST,
input: { type: object },
output: { type: object }
}
}
});
部署自定义集成
bash
部署到Nango
nango deploy integrations/my-custom-api.ts
错误处理
python
from nango import Nango, NangoError
try:
result = nango.proxy(
provider=github,
endpoint=/repos/owner/repo/issues,
connection_id=user-github-123
)
except NangoError as e:
if e.code == auth_expired:
# 重新授权
authurl = nango.getauth_url(github)
print(f请重新授权:{auth_url})
elif e.code == rate_limited:
# 等待后重试
time.sleep(e.retry_after)
else:
raise
代理最佳实践
1. 连接管理
- - 使用用户上下文存储连接ID
- 在操作前检查连接健康状态
- 自动实现重新授权流程
2. 错误恢复
- - 优雅处理速率限制
- 缓存频繁访问的数据
- 向用户提供清晰的错误信息
3. 安全性
- - 绝不在提示中暴露API密钥
- 使用环境变量存储密钥
- 实现权限范围控制
4. 性能
- - 尽可能批量操作
- 使用webhook替代轮询
- 实现请求缓存
OpenClaw的MCP集成
要在OpenClaw代理中使用Nango:
python
在您的OpenClaw技能或工具中
from nango import Nango
class NangoTool:
def init(self):
self.nango = Nango()
def callapi(self, provider: str, endpoint: str, connectionid: str, params):
任何提供者的通用API调用工具。
return self.nango.proxy(
provider=provider,
endpoint=endpoint,
connectionid=connectionid,
params=params
)
def list_providers(self):
列出所有可用提供者。
return self.nango.list_providers()
def getprovideractions(self, provider: str):
获取提供者的可用操作。
return self.nango.get_actions(provider)
常见问题
问题:连接未找到
- - 确保connection_id与创建的匹配
- 检查凭据是否过期
问题:提供者不受支持
- - 查看完整列表:https://nango.dev/integrations
- 为不支持的提供者创建自定义集成
问题:速率受限
资源
- - Nango控制台:https://app.nango.dev
- 文档:https://docs.nango.dev
- 集成目录:https://nango.dev/integrations
- GitHub:https://github.com/NangoHQ/nango
- 社区:https://nango.dev/community
定价
- - 免费版:每月10,000次API调用
- 专业版:每月49美元,100,000次调用
- 企业版:自定义定价,无限调用
免费版足以满足开发和小型项目需求。