model字段自动匹配对应的模型服务。这种路由策略适用于以下场景:gpt-4o、gpt-4o-mini、claude-3-5-sonnet)gpt-4-*匹配所有 gpt-4系列模型)参数 | 说明 | 示例 | 是否必填 |
模型服务 | 从已创建的模型服务列表中选择 | gpt-4o-openai | 是 |
匹配模型名 | 客户端请求的 model 参数匹配规则,支持精确匹配和通配符匹配( *) | gpt-4o 或 gpt-4-* | 是 |
重写模型名 | 转发到后端服务时,将请求中的 model 参数重写为指定值。留空则透传原始值 | gpt-4o 或留空 | 否 |
模型服务 | 匹配模型名 | 重写模型名 |
gpt-4o-openai | gpt-4o | (留空) |
gpt-4o-mini-openai | gpt-4o-mini | (留空) |
claude-3-5-sonnet-anthropic | claude-3-5-sonnet | (留空) |
# 请求1:路由到 gpt-4o-openaicurl -X POST https://{网关域名}/ai/llm/v1/chat/completions \\-H "Authorization:Bearer {API_Key}" \\-H "Content-Type:application/json" \\-d '{"model":"gpt-4o", "messages":[{"role":"user", "content":"你好"}]}'# 请求2:路由到 claude-3-5-sonnet-anthropiccurl -X POST https://{网关域名}/ai/llm/v1/chat/completions \\-H "Authorization:Bearer {API_Key}" \\-H "Content-Type:application/json" \\-d '{"model":"claude-3-5-sonnet", "messages": [{"role": "user", "content": "你好"}]}'
gpt-4-*系列的模型都路由到同一个服务模型服务 | 匹配模型名 | 重写模型名 |
gpt-4-family-openai | gpt-4-* | (留空) |
gpt-3.5-turbo-openai | gpt-3.5-turbo | (留空) |
# 请求1:匹配通配符规则,路由到 gpt-4-family-openai,透传model=gpt-4ocurl -X POST https://{网关域名}/ai/llm/v1/chat/completions \\-H "Authorization: Bearer {API_Key}" \\-H "Content-Type: application/json" \\-d '{"model": "gpt-4o", "messages": [{"role": "user", "content": "你好"}]}'# 请求2:匹配通配符规则,路由到 gpt-4-family-openai,透传model=gpt-4-turbocurl -X POST https://{网关域名}/ai/llm/v1/chat/completions \\-H "Authorization: Bearer {API_Key}" \\-H "Content-Type: application/json" \\-d '{"model": "gpt-4-turbo", "messages": [{"role": "user", "content": "你好"}]}'# 请求3:精确匹配,路由到 gpt-3.5-turbo-openaicurl -X POST https://{网关域名}/ai/llm/v1/chat/completions \\-H "Authorization: Bearer {API_Key}" \\-H "Content-Type: application/json" \\-d '{"model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "你好"}]}'
模型服务 | 匹配模型名 | 重写模型名 |
gpt-4o-openai | my-custom-gpt4 | gpt-4o |
claude-3-5-sonnet-anthropic | my-custom-claude | claude-3-5-sonnet-20241022 |
# 客户端请求model=my-custom-gpt4,网关转发时重写为model=gpt-4ocurl -X POST https://{网关域名}/ai/llm/v1/chat/completions \\-H "Authorization: Bearer {API_Key}" \\-H "Content-Type: application/json" \\-d '{"model": "my-custom-gpt4", "messages": [{"role": "user", "content": "你好"}]}'# 转发到后端OpenAI服务的请求body:# {"model": "gpt-4o", "messages": [{"role": "user", "content": "你好"}]}
model_name_route 路由策略后,网关从配置列表的第一条规则开始,按从上到下的顺序匹配请求中的 model 参数,首个命中的规则生效。顺序 | 模型名称规则 | 匹配类型 | 目标模型服务 |
1 | gpt-4o | 精确匹配 | 服务 A |
2 | gpt-4* | 通配符匹配 | 服务 B |
model=gpt-4o 时,命中第一条规则并路由到服务 A;请求 model=gpt-4-turbo 时,命中第二条规则并路由到服务 B。gpt-4* 配置在 gpt-4o 之前,则请求 model=gpt-4o 会优先命中 gpt-4*,并路由到服务 B。gpt-4-* 中的连字符是普通字符,该规则可以匹配 gpt-4-turbo,但不能匹配 gpt-4o。gpt-* 和 gpt-4* 都能匹配 gpt-4o。哪条规则排在前面,就使用哪条规则对应的模型服务。model 参数,但无法匹配任何已配置规则时,网关返回 HTTP 404。{"error": {"message": "model 'unknown-model' is not supported by any configured model_name_route rule"}}
model、model 为空字符串或不是字符串时,属于请求参数异常,不属于“模型名称未匹配”场景。通配符 | 说明 | 示例 | 匹配结果 |
* | 匹配任意字符(0个或多个) | gpt-4-* | 匹配 gpt-4-turbo、gpt-4o、gpt-4-0125-preview |
gpt-* | 前缀匹配 | gpt-* | 匹配所有以 gpt-开头的模型 |
*只能在匹配模型名字段使用,不支持在重写模型名字段使用*GPT-*不会匹配gpt-4omodel字段替换为"重写模型名"配置的值场景 | 匹配模型名 | 重写模型名 | 客户端请求 model | 转发到后端的 model |
透传原始 model | gpt-4o | (留空) | gpt-4o | gpt-4o |
统一模型标识 | gpt-4-* | gpt-4-turbo-2024-04-09 | gpt-4-turbo | gpt-4-turbo-2024-04-09 |
自定义别名 | my-gpt4 | gpt-4o | my-gpt4 | gpt-4o |
{"error": {"code": "model_not_found","message": "模型 'gpt-5' 不存在,请检查模型名称是否正确。可用模型: gpt-4o, gpt-4-*, claude-3-5-sonnet","type": "invalid_request_error"}}
Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback