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
b72e641d
authored
Jun 05, 2025
by
Apple\Apple
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/main' into alpha
parents
74c00e22
a813b241
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
5 deletions
+48
-5
dto/claude.go
+1
-0
dto/openai_request.go
+4
-1
relay/channel/openrouter/dto.go
+9
-0
service/convert.go
+34
-4
No files found.
dto/claude.go
View file @
b72e641d
...
...
@@ -18,6 +18,7 @@ type ClaudeMediaMessage struct {
Thinking
string
`json:"thinking,omitempty"`
Signature
string
`json:"signature,omitempty"`
Delta
string
`json:"delta,omitempty"`
CacheControl
json
.
RawMessage
`json:"cache_control,omitempty"`
// tool_calls
Id
string
`json:"id,omitempty"`
Name
string
`json:"name,omitempty"`
...
...
dto/openai_request.go
View file @
b72e641d
...
...
@@ -29,7 +29,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"`
...
...
@@ -56,6 +55,8 @@ 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
Reasoning
json
.
RawMessage
`json:"reasoning,omitempty"`
}
func
(
r
*
GeneralOpenAIRequest
)
ToMap
()
map
[
string
]
any
{
...
...
@@ -125,6 +126,8 @@ type MediaContent struct {
InputAudio
any
`json:"input_audio,omitempty"`
File
any
`json:"file,omitempty"`
VideoUrl
any
`json:"video_url,omitempty"`
// OpenRouter Params
CacheControl
json
.
RawMessage
`json:"cache_control,omitempty"`
}
func
(
m
*
MediaContent
)
GetImageMedia
()
*
MessageImageUrl
{
...
...
relay/channel/openrouter/dto.go
0 → 100644
View file @
b72e641d
package
openrouter
type
RequestReasoning
struct
{
// One of the following (not both):
Effort
string
`json:"effort,omitempty"`
// Can be "high", "medium", or "low" (OpenAI-style)
MaxTokens
int
`json:"max_tokens,omitempty"`
// Specific token limit (Anthropic-style)
// Optional: Default is false. All models support this.
Exclude
bool
`json:"exclude,omitempty"`
// Set to true to exclude reasoning tokens from response
}
service/convert.go
View file @
b72e641d
...
...
@@ -5,6 +5,7 @@ import (
"fmt"
"one-api/common"
"one-api/dto"
"one-api/relay/channel/openrouter"
relaycommon
"one-api/relay/common"
"strings"
)
...
...
@@ -18,10 +19,24 @@ func ClaudeToOpenAIRequest(claudeRequest dto.ClaudeRequest, info *relaycommon.Re
Stream
:
claudeRequest
.
Stream
,
}
isOpenRouter
:=
info
.
ChannelType
==
common
.
ChannelTypeOpenRouter
if
claudeRequest
.
Thinking
!=
nil
{
if
strings
.
HasSuffix
(
info
.
OriginModelName
,
"-thinking"
)
&&
!
strings
.
HasSuffix
(
claudeRequest
.
Model
,
"-thinking"
)
{
openAIRequest
.
Model
=
openAIRequest
.
Model
+
"-thinking"
if
isOpenRouter
{
reasoning
:=
openrouter
.
RequestReasoning
{
MaxTokens
:
claudeRequest
.
Thinking
.
BudgetTokens
,
}
reasoningJSON
,
err
:=
json
.
Marshal
(
reasoning
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to marshal reasoning: %w"
,
err
)
}
openAIRequest
.
Reasoning
=
reasoningJSON
}
else
{
thinkingSuffix
:=
"-thinking"
if
strings
.
HasSuffix
(
info
.
OriginModelName
,
thinkingSuffix
)
&&
!
strings
.
HasSuffix
(
openAIRequest
.
Model
,
thinkingSuffix
)
{
openAIRequest
.
Model
=
openAIRequest
.
Model
+
thinkingSuffix
}
}
}
...
...
@@ -62,16 +77,30 @@ func ClaudeToOpenAIRequest(claudeRequest dto.ClaudeRequest, info *relaycommon.Re
}
else
{
systems
:=
claudeRequest
.
ParseSystem
()
if
len
(
systems
)
>
0
{
systemStr
:=
""
openAIMessage
:=
dto
.
Message
{
Role
:
"system"
,
}
isOpenRouterClaude
:=
isOpenRouter
&&
strings
.
HasPrefix
(
info
.
UpstreamModelName
,
"anthropic/claude"
)
if
isOpenRouterClaude
{
systemMediaMessages
:=
make
([]
dto
.
MediaContent
,
0
,
len
(
systems
))
for
_
,
system
:=
range
systems
{
message
:=
dto
.
MediaContent
{
Type
:
"text"
,
Text
:
system
.
GetText
(),
CacheControl
:
system
.
CacheControl
,
}
systemMediaMessages
=
append
(
systemMediaMessages
,
message
)
}
openAIMessage
.
SetMediaContent
(
systemMediaMessages
)
}
else
{
systemStr
:=
""
for
_
,
system
:=
range
systems
{
if
system
.
Text
!=
nil
{
systemStr
+=
*
system
.
Text
}
}
openAIMessage
.
SetStringContent
(
systemStr
)
}
openAIMessages
=
append
(
openAIMessages
,
openAIMessage
)
}
}
...
...
@@ -99,6 +128,7 @@ func ClaudeToOpenAIRequest(claudeRequest dto.ClaudeRequest, info *relaycommon.Re
message
:=
dto
.
MediaContent
{
Type
:
"text"
,
Text
:
mediaMsg
.
GetText
(),
CacheControl
:
mediaMsg
.
CacheControl
,
}
mediaMessages
=
append
(
mediaMessages
,
message
)
case
"image"
:
...
...
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