Skip to content

fix: doubao anthropic fetch models#1207

Merged
looplj merged 1 commit intorelease/v0.9.xfrom
dev-tmp
Mar 28, 2026
Merged

fix: doubao anthropic fetch models#1207
looplj merged 1 commit intorelease/v0.9.xfrom
dev-tmp

Conversation

@looplj
Copy link
Copy Markdown
Owner

@looplj looplj commented Mar 28, 2026

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 503 to +508
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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

@looplj looplj merged commit 918e16c into release/v0.9.x Mar 28, 2026
2 of 3 checks passed
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 3 additional findings in Devin Review.

Open in Devin Review

Comment on lines +506 to +508
case channelType == channel.TypeDoubaoAnthropic:
baseURL = strings.TrimSuffix(baseURL, "/compatible")
return baseURL + "/v3/models", headers
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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).
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant