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
c0df3876
authored
May 29, 2025
by
neotf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: enhance token usage details for upstream OpenRouter
parent
ac9df0c1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
4 deletions
+12
-4
dto/openai_request.go
+3
-1
relay/channel/openai/adaptor.go
+3
-0
service/convert.go
+6
-3
No files found.
dto/openai_request.go
View file @
c0df3876
...
...
@@ -28,7 +28,6 @@ type GeneralOpenAIRequest struct {
MaxTokens
uint
`json:"max_tokens,omitempty"`
MaxCompletionTokens
uint
`json:"max_completion_tokens,omitempty"`
ReasoningEffort
string
`json:"reasoning_effort,omitempty"`
//Reasoning json.RawMessage `json:"reasoning,omitempty"`
Temperature
*
float64
`json:"temperature,omitempty"`
TopP
float64
`json:"top_p,omitempty"`
TopK
int
`json:"top_k,omitempty"`
...
...
@@ -55,6 +54,9 @@ type GeneralOpenAIRequest struct {
EnableThinking
any
`json:"enable_thinking,omitempty"`
// ali
ExtraBody
any
`json:"extra_body,omitempty"`
WebSearchOptions
*
WebSearchOptions
`json:"web_search_options,omitempty"`
// OpenRouter Params
Usage
json
.
RawMessage
`json:"usage,omitempty"`
Reasoning
json
.
RawMessage
`json:"reasoning,omitempty"`
}
type
ToolCallRequest
struct
{
...
...
relay/channel/openai/adaptor.go
View file @
c0df3876
...
...
@@ -152,6 +152,9 @@ func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayIn
if
info
.
ChannelType
!=
common
.
ChannelTypeOpenAI
&&
info
.
ChannelType
!=
common
.
ChannelTypeAzure
{
request
.
StreamOptions
=
nil
}
if
info
.
ChannelType
==
common
.
ChannelTypeOpenRouter
{
request
.
Usage
=
json
.
RawMessage
(
"{
\"
include
\"
: true}"
)
}
if
strings
.
HasPrefix
(
request
.
Model
,
"o"
)
{
if
request
.
MaxCompletionTokens
==
0
&&
request
.
MaxTokens
!=
0
{
request
.
MaxCompletionTokens
=
request
.
MaxTokens
...
...
service/convert.go
View file @
c0df3876
...
...
@@ -246,12 +246,15 @@ func StreamResponseOpenAI2Claude(openAIResponse *dto.ChatCompletionsStreamRespon
}
if
info
.
Done
{
claudeResponses
=
append
(
claudeResponses
,
generateStopBlock
(
info
.
ClaudeConvertInfo
.
Index
))
if
info
.
ClaudeConvertInfo
.
Usage
!=
nil
{
oaiUsage
:=
info
.
ClaudeConvertInfo
.
Usage
if
oaiUsage
!=
nil
{
claudeResponses
=
append
(
claudeResponses
,
&
dto
.
ClaudeResponse
{
Type
:
"message_delta"
,
Usage
:
&
dto
.
ClaudeUsage
{
InputTokens
:
info
.
ClaudeConvertInfo
.
Usage
.
PromptTokens
,
OutputTokens
:
info
.
ClaudeConvertInfo
.
Usage
.
CompletionTokens
,
InputTokens
:
oaiUsage
.
PromptTokens
,
OutputTokens
:
oaiUsage
.
CompletionTokens
,
CacheCreationInputTokens
:
oaiUsage
.
PromptTokensDetails
.
CachedCreationTokens
,
CacheReadInputTokens
:
oaiUsage
.
PromptTokensDetails
.
CachedTokens
,
},
Delta
:
&
dto
.
ClaudeMediaMessage
{
StopReason
:
common
.
GetPointer
[
string
](
stopReasonOpenAI2Claude
(
info
.
FinishReason
)),
...
...
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