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
e351642d
authored
Jul 15, 2025
by
creamlike1024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: claude web search tool 计费
parent
aeca676d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
4 deletions
+38
-4
dto/claude.go
+9
-4
relay/channel/claude/relay-claude.go
+4
-0
relay/relay-text.go
+16
-0
setting/operation_setting/tools.go
+9
-0
No files found.
dto/claude.go
View file @
e351642d
...
...
@@ -324,8 +324,13 @@ func (c *ClaudeResponse) GetIndex() int {
}
type
ClaudeUsage
struct
{
InputTokens
int
`json:"input_tokens"`
CacheCreationInputTokens
int
`json:"cache_creation_input_tokens"`
CacheReadInputTokens
int
`json:"cache_read_input_tokens"`
OutputTokens
int
`json:"output_tokens"`
InputTokens
int
`json:"input_tokens"`
CacheCreationInputTokens
int
`json:"cache_creation_input_tokens"`
CacheReadInputTokens
int
`json:"cache_read_input_tokens"`
OutputTokens
int
`json:"output_tokens"`
ServerToolUse
*
ClaudeServerToolUse
`json:"server_tool_use"`
}
type
ClaudeServerToolUse
struct
{
WebSearchRequests
int
`json:"web_search_requests"`
}
relay/channel/claude/relay-claude.go
View file @
e351642d
...
...
@@ -745,6 +745,10 @@ func HandleClaudeResponseData(c *gin.Context, info *relaycommon.RelayInfo, claud
responseData
=
data
}
if
claudeResponse
.
Usage
.
ServerToolUse
!=
nil
&&
claudeResponse
.
Usage
.
ServerToolUse
.
WebSearchRequests
>
0
{
c
.
Set
(
"claude_web_search_requests"
,
claudeResponse
.
Usage
.
ServerToolUse
.
WebSearchRequests
)
}
common
.
IOCopyBytesGracefully
(
c
,
nil
,
responseData
)
return
nil
}
...
...
relay/relay-text.go
View file @
e351642d
...
...
@@ -382,6 +382,7 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
// openai web search 工具计费
var
dWebSearchQuota
decimal
.
Decimal
var
webSearchPrice
float64
// response api 格式工具计费
if
relayInfo
.
ResponsesUsageInfo
!=
nil
{
if
webSearchTool
,
exists
:=
relayInfo
.
ResponsesUsageInfo
.
BuiltInTools
[
dto
.
BuildInToolWebSearchPreview
];
exists
&&
webSearchTool
.
CallCount
>
0
{
// 计算 web search 调用的配额 (配额 = 价格 * 调用次数 / 1000 * 分组倍率)
...
...
@@ -404,6 +405,17 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
extraContent
+=
fmt
.
Sprintf
(
"Web Search 调用 1 次,上下文大小 %s,调用花费 %s"
,
searchContextSize
,
dWebSearchQuota
.
String
())
}
// claude web search tool 计费
var
dClaudeWebSearchQuota
decimal
.
Decimal
var
claudeWebSearchPrice
float64
claudeWebSearchCallCount
:=
ctx
.
GetInt
(
"claude_web_search_requests"
)
if
claudeWebSearchCallCount
>
0
{
claudeWebSearchPrice
=
operation_setting
.
GetClaudeWebSearchPricePerThousand
()
dClaudeWebSearchQuota
=
decimal
.
NewFromFloat
(
claudeWebSearchPrice
)
.
Div
(
decimal
.
NewFromInt
(
1000
))
.
Mul
(
dGroupRatio
)
.
Mul
(
dQuotaPerUnit
)
.
Mul
(
decimal
.
NewFromInt
(
int64
(
claudeWebSearchCallCount
)))
extraContent
+=
fmt
.
Sprintf
(
"Claude Web Search 调用 %d 次,调用花费 %s"
,
claudeWebSearchCallCount
,
dClaudeWebSearchQuota
.
String
())
}
// file search tool 计费
var
dFileSearchQuota
decimal
.
Decimal
var
fileSearchPrice
float64
...
...
@@ -527,6 +539,10 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
other
[
"web_search_call_count"
]
=
1
other
[
"web_search_price"
]
=
webSearchPrice
}
}
else
if
!
dClaudeWebSearchQuota
.
IsZero
()
{
other
[
"web_search"
]
=
true
other
[
"web_search_call_count"
]
=
claudeWebSearchCallCount
other
[
"web_search_price"
]
=
claudeWebSearchPrice
}
if
!
dFileSearchQuota
.
IsZero
()
&&
relayInfo
.
ResponsesUsageInfo
!=
nil
{
if
fileSearchTool
,
exists
:=
relayInfo
.
ResponsesUsageInfo
.
BuiltInTools
[
dto
.
BuildInToolFileSearch
];
exists
{
...
...
setting/operation_setting/tools.go
View file @
e351642d
...
...
@@ -23,6 +23,15 @@ const (
Gemini20FlashInputAudioPrice
=
0.70
)
const
(
// Claude Web search
ClaudeWebSearchPrice
=
10.00
)
func
GetClaudeWebSearchPricePerThousand
()
float64
{
return
ClaudeWebSearchPrice
}
func
GetWebSearchPricePerThousand
(
modelName
string
,
contextSize
string
)
float64
{
// 确定模型类型
// https://platform.openai.com/docs/pricing Web search 价格按模型类型和 search context size 收费
...
...
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