Skip to Content
开发文档高级功能智能模型路由

智能模型路由

OfoxAI 的智能模型路由可以自动为你的请求选择最佳模型,基于成本、速度、质量等维度进行优化。

Auto 模式

最简单的使用方式 — 设置 model: "auto",让 OfoxAI 自动选择:

response = client.chat.completions.create( model="auto", messages=[{"role": "user", "content": "解释量子计算"}] ) # 查看实际使用的模型 print(response.model) # 如 "openai/gpt-4o"

Auto 模式会根据请求内容的复杂度和可用模型的状态,自动选择最合适的模型。

模型池配置

你可以指定候选模型池和路由偏好:

model_routing.py
response = client.chat.completions.create( model="auto", messages=[{"role": "user", "content": "帮我优化这段代码"}], extra_body={ "model_routing_config": { "models": [ "openai/gpt-4o", "anthropic/claude-sonnet-4.5", "google/gemini-3-flash-preview" ], "preference": "quality" # 质量优先 } } )

路由偏好

偏好说明
balanced综合考虑质量、速度和成本(默认)
quality质量优先,选择能力最强的模型
speed速度优先,选择响应最快的模型
cost成本优先,选择最便宜的模型

使用场景

成本优化

对于简单对话,自动使用便宜的模型;复杂任务使用高端模型:

# 简单场景 → 可能选择 gpt-4o-mini 或 gemini-3-flash-preview response = client.chat.completions.create( model="auto", messages=[{"role": "user", "content": "今天星期几?"}], extra_body={"model_routing_config": {"preference": "cost"}} )

高可用

指定多个备选模型,确保服务不中断:

response = client.chat.completions.create( model="auto", messages=[{"role": "user", "content": "分析市场趋势"}], extra_body={ "model_routing_config": { "models": [ "openai/gpt-4o", "anthropic/claude-sonnet-4.5", "google/gemini-3.1-pro-preview" ], "preference": "balanced" } } )

智能路由会自动感知各模型的实时状态(延迟、可用性、负载),在候选池中做出最优选择。

Last updated on