OpenRouter 是一个提供大型语言模型端点的平台。

身份验证

设置您的 OPENROUTER_API_KEY环境变量。在此处获取您的密钥:https://openrouter.ai/settings/keys

export OPENROUTER_API_KEY=***

示例

OpenRouter 与您的 Agent 一起使用:

from agno.agent import Agent, RunResponse
from agno.models.openrouter import OpenRouter

agent = Agent(
    model=OpenRouter(id="gpt-4o"),
    markdown=True
)

# 在终端中打印响应
agent.print_response("写一个两句话的恐怖故事。")

参数

参数类型默认值描述
idstr"gpt-4o"用于生成响应的具体模型 ID。
namestr"OpenRouter"OpenRouter 代理的名称标识符。
providerstr"OpenRouter:"+id模型提供者,结合了 "OpenRouter" 和模型 ID。
api_keyOptional[str]-用于向 OpenRouter 服务进行请求身份验证的 API 密钥。从环境变量 OPENROUTER_API_KEY 中检索。
base_urlstr"https://openrouter.ai/api/v1"向 OpenRouter 服务发出 API 请求的基础 URL。
max_tokensint1024响应中要生成的最大 token 数。

OpenRouter 还支持 OpenAI 的参数。

提示缓存

当使用的提供商支持时,提示缓存将通过我们的 OpenRouter 模型自动进行。在其他情况下,您可以通过 cache_control 标头激活它。 您可以在 他们的文档 中了解有关与 OpenRouter 一起进行提示缓存的更多信息。