Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a9727223
authored
Feb 07, 2026
by
Seefs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 使用openai兼容接口调用部分渠道在最终端点为claude原生端点下还是走了openai扣减input_token的逻辑
parent
a30561d8
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
21 additions
and
31 deletions
+21
-31
relay/channel/ali/adaptor.go
+2
-5
relay/channel/claude/adaptor.go
+1
-0
relay/channel/codex/adaptor.go
+4
-4
relay/channel/deepseek/adaptor.go
+2
-5
relay/channel/moonshot/adaptor.go
+2
-5
relay/channel/vertex/adaptor.go
+3
-2
relay/channel/volcengine/adaptor.go
+2
-4
relay/channel/zhipu_4v/adaptor.go
+2
-5
relay/common/relay_info.go
+2
-0
relay/compatible_handler.go
+1
-1
No files found.
relay/channel/ali/adaptor.go
View file @
a9727223
...
...
@@ -223,11 +223,8 @@ func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, info *relaycom
switch
info
.
RelayFormat
{
case
types
.
RelayFormatClaude
:
if
supportsAliAnthropicMessages
(
info
.
UpstreamModelName
)
{
if
info
.
IsStream
{
return
claude
.
ClaudeStreamHandler
(
c
,
resp
,
info
)
}
return
claude
.
ClaudeHandler
(
c
,
resp
,
info
)
adaptor
:=
claude
.
Adaptor
{}
return
adaptor
.
DoResponse
(
c
,
resp
,
info
)
}
adaptor
:=
openai
.
Adaptor
{}
...
...
relay/channel/claude/adaptor.go
View file @
a9727223
...
...
@@ -95,6 +95,7 @@ func (a *Adaptor) DoRequest(c *gin.Context, info *relaycommon.RelayInfo, request
}
func
(
a
*
Adaptor
)
DoResponse
(
c
*
gin
.
Context
,
resp
*
http
.
Response
,
info
*
relaycommon
.
RelayInfo
)
(
usage
any
,
err
*
types
.
NewAPIError
)
{
info
.
FinalRequestRelayFormat
=
types
.
RelayFormatClaude
if
info
.
IsStream
{
return
ClaudeStreamHandler
(
c
,
resp
,
info
)
}
else
{
...
...
relay/channel/codex/adaptor.go
View file @
a9727223
...
...
@@ -26,7 +26,7 @@ func (a *Adaptor) ConvertGeminiRequest(c *gin.Context, info *relaycommon.RelayIn
}
func
(
a
*
Adaptor
)
ConvertClaudeRequest
(
*
gin
.
Context
,
*
relaycommon
.
RelayInfo
,
*
dto
.
ClaudeRequest
)
(
any
,
error
)
{
return
nil
,
errors
.
New
(
"codex channel: endpoint not supported"
)
return
nil
,
errors
.
New
(
"codex channel:
/v1/messages
endpoint not supported"
)
}
func
(
a
*
Adaptor
)
ConvertAudioRequest
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
,
request
dto
.
AudioRequest
)
(
io
.
Reader
,
error
)
{
...
...
@@ -41,15 +41,15 @@ func (a *Adaptor) Init(info *relaycommon.RelayInfo) {
}
func
(
a
*
Adaptor
)
ConvertOpenAIRequest
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
,
request
*
dto
.
GeneralOpenAIRequest
)
(
any
,
error
)
{
return
nil
,
errors
.
New
(
"codex channel: endpoint not supported"
)
return
nil
,
errors
.
New
(
"codex channel:
/v1/chat/completions
endpoint not supported"
)
}
func
(
a
*
Adaptor
)
ConvertRerankRequest
(
c
*
gin
.
Context
,
relayMode
int
,
request
dto
.
RerankRequest
)
(
any
,
error
)
{
return
nil
,
errors
.
New
(
"codex channel: endpoint not supported"
)
return
nil
,
errors
.
New
(
"codex channel:
/v1/rerank
endpoint not supported"
)
}
func
(
a
*
Adaptor
)
ConvertEmbeddingRequest
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
,
request
dto
.
EmbeddingRequest
)
(
any
,
error
)
{
return
nil
,
errors
.
New
(
"codex channel: endpoint not supported"
)
return
nil
,
errors
.
New
(
"codex channel:
/v1/embeddings
endpoint not supported"
)
}
func
(
a
*
Adaptor
)
ConvertOpenAIResponsesRequest
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
,
request
dto
.
OpenAIResponsesRequest
)
(
any
,
error
)
{
...
...
relay/channel/deepseek/adaptor.go
View file @
a9727223
...
...
@@ -95,11 +95,8 @@ func (a *Adaptor) DoRequest(c *gin.Context, info *relaycommon.RelayInfo, request
func
(
a
*
Adaptor
)
DoResponse
(
c
*
gin
.
Context
,
resp
*
http
.
Response
,
info
*
relaycommon
.
RelayInfo
)
(
usage
any
,
err
*
types
.
NewAPIError
)
{
switch
info
.
RelayFormat
{
case
types
.
RelayFormatClaude
:
if
info
.
IsStream
{
return
claude
.
ClaudeStreamHandler
(
c
,
resp
,
info
)
}
else
{
return
claude
.
ClaudeHandler
(
c
,
resp
,
info
)
}
adaptor
:=
claude
.
Adaptor
{}
return
adaptor
.
DoResponse
(
c
,
resp
,
info
)
default
:
adaptor
:=
openai
.
Adaptor
{}
return
adaptor
.
DoResponse
(
c
,
resp
,
info
)
...
...
relay/channel/moonshot/adaptor.go
View file @
a9727223
...
...
@@ -102,11 +102,8 @@ func (a *Adaptor) ConvertEmbeddingRequest(c *gin.Context, info *relaycommon.Rela
func
(
a
*
Adaptor
)
DoResponse
(
c
*
gin
.
Context
,
resp
*
http
.
Response
,
info
*
relaycommon
.
RelayInfo
)
(
usage
any
,
err
*
types
.
NewAPIError
)
{
switch
info
.
RelayFormat
{
case
types
.
RelayFormatClaude
:
if
info
.
IsStream
{
return
claude
.
ClaudeStreamHandler
(
c
,
resp
,
info
)
}
else
{
return
claude
.
ClaudeHandler
(
c
,
resp
,
info
)
}
adaptor
:=
claude
.
Adaptor
{}
return
adaptor
.
DoResponse
(
c
,
resp
,
info
)
default
:
adaptor
:=
openai
.
Adaptor
{}
return
adaptor
.
DoResponse
(
c
,
resp
,
info
)
...
...
relay/channel/vertex/adaptor.go
View file @
a9727223
...
...
@@ -365,10 +365,11 @@ func (a *Adaptor) DoRequest(c *gin.Context, info *relaycommon.RelayInfo, request
}
func
(
a
*
Adaptor
)
DoResponse
(
c
*
gin
.
Context
,
resp
*
http
.
Response
,
info
*
relaycommon
.
RelayInfo
)
(
usage
any
,
err
*
types
.
NewAPIError
)
{
claudeAdaptor
:=
claude
.
Adaptor
{}
if
info
.
IsStream
{
switch
a
.
RequestMode
{
case
RequestModeClaude
:
return
claude
.
ClaudeStreamHandler
(
c
,
resp
,
info
)
return
claude
Adaptor
.
DoResponse
(
c
,
resp
,
info
)
case
RequestModeGemini
:
if
info
.
RelayMode
==
constant
.
RelayModeGemini
{
return
gemini
.
GeminiTextGenerationStreamHandler
(
c
,
info
,
resp
)
...
...
@@ -381,7 +382,7 @@ func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, info *relaycom
}
else
{
switch
a
.
RequestMode
{
case
RequestModeClaude
:
return
claude
.
ClaudeHandler
(
c
,
resp
,
info
)
return
claude
Adaptor
.
DoResponse
(
c
,
resp
,
info
)
case
RequestModeGemini
:
if
info
.
RelayMode
==
constant
.
RelayModeGemini
{
return
gemini
.
GeminiTextGenerationHandler
(
c
,
info
,
resp
)
...
...
relay/channel/volcengine/adaptor.go
View file @
a9727223
...
...
@@ -347,10 +347,8 @@ func (a *Adaptor) DoRequest(c *gin.Context, info *relaycommon.RelayInfo, request
func
(
a
*
Adaptor
)
DoResponse
(
c
*
gin
.
Context
,
resp
*
http
.
Response
,
info
*
relaycommon
.
RelayInfo
)
(
usage
any
,
err
*
types
.
NewAPIError
)
{
if
info
.
RelayFormat
==
types
.
RelayFormatClaude
{
if
_
,
ok
:=
channelconstant
.
ChannelSpecialBases
[
info
.
ChannelBaseUrl
];
ok
{
if
info
.
IsStream
{
return
claude
.
ClaudeStreamHandler
(
c
,
resp
,
info
)
}
return
claude
.
ClaudeHandler
(
c
,
resp
,
info
)
adaptor
:=
claude
.
Adaptor
{}
return
adaptor
.
DoResponse
(
c
,
resp
,
info
)
}
}
...
...
relay/channel/zhipu_4v/adaptor.go
View file @
a9727223
...
...
@@ -109,11 +109,8 @@ func (a *Adaptor) DoRequest(c *gin.Context, info *relaycommon.RelayInfo, request
func
(
a
*
Adaptor
)
DoResponse
(
c
*
gin
.
Context
,
resp
*
http
.
Response
,
info
*
relaycommon
.
RelayInfo
)
(
usage
any
,
err
*
types
.
NewAPIError
)
{
switch
info
.
RelayFormat
{
case
types
.
RelayFormatClaude
:
if
info
.
IsStream
{
return
claude
.
ClaudeStreamHandler
(
c
,
resp
,
info
)
}
else
{
return
claude
.
ClaudeHandler
(
c
,
resp
,
info
)
}
adaptor
:=
claude
.
Adaptor
{}
return
adaptor
.
DoResponse
(
c
,
resp
,
info
)
default
:
if
info
.
RelayMode
==
relayconstant
.
RelayModeImagesGenerations
{
return
zhipu4vImageHandler
(
c
,
resp
,
info
)
...
...
relay/common/relay_info.go
View file @
a9727223
...
...
@@ -145,6 +145,8 @@ type RelayInfo struct {
// RequestConversionChain records request format conversions in order, e.g.
// ["openai", "openai_responses"] or ["openai", "claude"].
RequestConversionChain
[]
types
.
RelayFormat
// 最终请求到上游的格式 TODO: 当前仅设置了Claude
FinalRequestRelayFormat
types
.
RelayFormat
ThinkingContentInfo
TokenCountMeta
...
...
relay/compatible_handler.go
View file @
a9727223
...
...
@@ -334,7 +334,7 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage
var
audioInputQuota
decimal
.
Decimal
var
audioInputPrice
float64
isClaudeUsageSemantic
:=
relayInfo
.
ChannelType
==
constant
.
ChannelTypeAnthropic
isClaudeUsageSemantic
:=
relayInfo
.
FinalRequestRelayFormat
==
types
.
RelayFormatClaude
if
!
relayInfo
.
PriceData
.
UsePrice
{
baseTokens
:=
dPromptTokens
// 减去 cached tokens
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment