fix: doubao anthropic fetch models#1207
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the model fetching logic for DoubaoAnthropic by adjusting the base URL suffix handling and updating corresponding tests. Specifically, it adds a case to trim the /compatible suffix and append /v3/models for this channel type. A review comment suggests refactoring the switch-case block to merge similar logic for Doubao-related channel types to reduce code duplication.
| case channelType == channel.TypeDoubao || channelType == channel.TypeVolcengine: | ||
| baseURL = strings.TrimSuffix(baseURL, "/v3") | ||
| return baseURL + "/v3/models", headers | ||
| case channelType == channel.TypeDoubaoAnthropic: | ||
| baseURL = strings.TrimSuffix(baseURL, "/compatible") | ||
| return baseURL + "/v3/models", headers |
There was a problem hiding this comment.
To improve code clarity and reduce duplication, you can merge the logic for TypeDoubao, TypeVolcengine, and TypeDoubaoAnthropic since they all result in a /v3/models endpoint. This can be done by combining them into a single case block.
| case channelType == channel.TypeDoubao || channelType == channel.TypeVolcengine: | |
| baseURL = strings.TrimSuffix(baseURL, "/v3") | |
| return baseURL + "/v3/models", headers | |
| case channelType == channel.TypeDoubaoAnthropic: | |
| baseURL = strings.TrimSuffix(baseURL, "/compatible") | |
| return baseURL + "/v3/models", headers | |
| case channelType == channel.TypeDoubao || channelType == channel.TypeVolcengine || channelType == channel.TypeDoubaoAnthropic: | |
| if channelType == channel.TypeDoubaoAnthropic { | |
| baseURL = strings.TrimSuffix(baseURL, "/compatible") | |
| } else { | |
| baseURL = strings.TrimSuffix(baseURL, "/v3") | |
| } | |
| return baseURL + "/v3/models", headers |
| case channelType == channel.TypeDoubaoAnthropic: | ||
| baseURL = strings.TrimSuffix(baseURL, "/compatible") | ||
| return baseURL + "/v3/models", headers |
There was a problem hiding this comment.
🟡 DoubaoAnthropic endpoint changed to Volcengine v3 but auth still sends X-Api-Key first
The new TypeDoubaoAnthropic case in prepareModelsEndpoint routes model fetching to the Volcengine v3 API (/v3/models), but UsesAnthropicModelAPI() at internal/ent/channel/type.go:25 still returns true for this type (because IsAnthropicLike() matches the _anthropic suffix). This causes the auth logic at internal/server/biz/model_fetcher.go:315-316 to set X-Api-Key instead of Bearer auth. At internal/server/biz/model_fetcher.go:348-354, the first request to the Volcengine v3 endpoint will use X-Api-Key auth (incorrect for Volcengine), fail, and then retry with Bearer auth.
Before this PR, the endpoint was Anthropic-style (/v1/models), so the X-Api-Key first-attempt was arguably correct. Now that the endpoint is Volcengine-style (same pattern as TypeDoubao at line 503-505, which uses Bearer), every model-fetch for this channel type makes a guaranteed-to-fail extra HTTP request.
Prompt for agents
In internal/ent/channel/type.go, update the UsesAnthropicModelAPI() method to exclude TypeDoubaoAnthropic, since it no longer uses an Anthropic-style /v1/models endpoint. For example, change the method body to:
func (t Type) UsesAnthropicModelAPI() bool {
return (t.IsAnthropic() || t.IsAnthropicLike() || t == TypeClaudecode) && t != TypeDoubaoAnthropic
}
Alternatively, update the auth logic in internal/server/biz/model_fetcher.go lines 315-321 and 348-357 to handle TypeDoubaoAnthropic like a non-Anthropic type (using Bearer auth directly).
Was this helpful? React with 👍 or 👎 to provide feedback.
Uh oh!
There was an error while loading. Please reload this page.