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
0ba6004f
authored
Nov 30, 2025
by
Seefs
Committed by
GitHub
Nov 30, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge pull request #2334 from seefs001/feature/glm-coding
feat: glm coding plan && kimi coding plan
parent
ec811724
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
82 additions
and
22 deletions
+82
-22
constant/channel.go
+24
-0
controller/channel.go
+13
-4
relay/channel/moonshot/adaptor.go
+11
-0
relay/channel/volcengine/adaptor.go
+14
-14
relay/channel/zhipu_4v/adaptor.go
+19
-3
relay/channel/zhipu_4v/constants.go
+1
-1
No files found.
constant/channel.go
View file @
0ba6004f
...
...
@@ -180,3 +180,27 @@ func GetChannelTypeName(channelType int) string {
}
return
"Unknown"
}
type
ChannelSpecialBase
struct
{
ClaudeBaseURL
string
OpenAIBaseURL
string
}
var
ChannelSpecialBases
=
map
[
string
]
ChannelSpecialBase
{
"glm-coding-plan"
:
{
ClaudeBaseURL
:
"https://open.bigmodel.cn/api/anthropic"
,
OpenAIBaseURL
:
"https://open.bigmodel.cn/api/coding/paas/v4"
,
},
"glm-coding-plan-international"
:
{
ClaudeBaseURL
:
"https://api.z.ai/api/anthropic"
,
OpenAIBaseURL
:
"https://api.z.ai/api/coding/paas/v4"
,
},
"kimi-coding-plan"
:
{
ClaudeBaseURL
:
"https://api.kimi.com/coding"
,
OpenAIBaseURL
:
"https://api.kimi.com/coding/v1"
,
},
"doubao-coding-plan"
:
{
ClaudeBaseURL
:
"https://ark.cn-beijing.volces.com/api/coding"
,
OpenAIBaseURL
:
"https://ark.cn-beijing.volces.com/api/coding/v3"
,
},
}
controller/channel.go
View file @
0ba6004f
...
...
@@ -11,7 +11,6 @@ import (
"github.com/QuantumNous/new-api/constant"
"github.com/QuantumNous/new-api/dto"
"github.com/QuantumNous/new-api/model"
"github.com/QuantumNous/new-api/relay/channel/volcengine"
"github.com/QuantumNous/new-api/service"
"github.com/gin-gonic/gin"
...
...
@@ -192,10 +191,20 @@ func FetchUpstreamModels(c *gin.Context) {
case
constant
.
ChannelTypeAli
:
url
=
fmt
.
Sprintf
(
"%s/compatible-mode/v1/models"
,
baseURL
)
case
constant
.
ChannelTypeZhipu_v4
:
url
=
fmt
.
Sprintf
(
"%s/api/paas/v4/models"
,
baseURL
)
if
plan
,
ok
:=
constant
.
ChannelSpecialBases
[
baseURL
];
ok
&&
plan
.
OpenAIBaseURL
!=
""
{
url
=
fmt
.
Sprintf
(
"%s/models"
,
plan
.
OpenAIBaseURL
)
}
else
{
url
=
fmt
.
Sprintf
(
"%s/api/paas/v4/models"
,
baseURL
)
}
case
constant
.
ChannelTypeVolcEngine
:
if
baseURL
==
volcengine
.
DoubaoCodingPlan
{
url
=
fmt
.
Sprintf
(
"%s/v1/models"
,
volcengine
.
DoubaoCodingPlanOpenAIBaseURL
)
if
plan
,
ok
:=
constant
.
ChannelSpecialBases
[
baseURL
];
ok
&&
plan
.
OpenAIBaseURL
!=
""
{
url
=
fmt
.
Sprintf
(
"%s/v1/models"
,
plan
.
OpenAIBaseURL
)
}
else
{
url
=
fmt
.
Sprintf
(
"%s/v1/models"
,
baseURL
)
}
case
constant
.
ChannelTypeMoonshot
:
if
plan
,
ok
:=
constant
.
ChannelSpecialBases
[
baseURL
];
ok
&&
plan
.
OpenAIBaseURL
!=
""
{
url
=
fmt
.
Sprintf
(
"%s/models"
,
plan
.
OpenAIBaseURL
)
}
else
{
url
=
fmt
.
Sprintf
(
"%s/v1/models"
,
baseURL
)
}
...
...
relay/channel/moonshot/adaptor.go
View file @
0ba6004f
...
...
@@ -6,6 +6,7 @@ import (
"io"
"net/http"
channelconstant
"github.com/QuantumNous/new-api/constant"
"github.com/QuantumNous/new-api/dto"
"github.com/QuantumNous/new-api/relay/channel"
"github.com/QuantumNous/new-api/relay/channel/claude"
...
...
@@ -44,6 +45,16 @@ func (a *Adaptor) Init(info *relaycommon.RelayInfo) {
}
func
(
a
*
Adaptor
)
GetRequestURL
(
info
*
relaycommon
.
RelayInfo
)
(
string
,
error
)
{
baseURL
:=
info
.
ChannelBaseUrl
if
specialPlan
,
ok
:=
channelconstant
.
ChannelSpecialBases
[
baseURL
];
ok
{
if
info
.
RelayFormat
==
types
.
RelayFormatClaude
{
return
fmt
.
Sprintf
(
"%s/v1/messages"
,
specialPlan
.
ClaudeBaseURL
),
nil
}
if
info
.
RelayFormat
==
types
.
RelayFormatOpenAI
{
return
fmt
.
Sprintf
(
"%s/chat/completions"
,
specialPlan
.
OpenAIBaseURL
),
nil
}
}
switch
info
.
RelayFormat
{
case
types
.
RelayFormatClaude
:
return
fmt
.
Sprintf
(
"%s/anthropic/v1/messages"
,
info
.
ChannelBaseUrl
),
nil
...
...
relay/channel/volcengine/adaptor.go
View file @
0ba6004f
...
...
@@ -24,11 +24,8 @@ import (
)
const
(
contextKeyTTSRequest
=
"volcengine_tts_request"
contextKeyResponseFormat
=
"response_format"
DoubaoCodingPlan
=
"doubao-coding-plan"
DoubaoCodingPlanClaudeBaseURL
=
"https://ark.cn-beijing.volces.com/api/coding"
DoubaoCodingPlanOpenAIBaseURL
=
"https://ark.cn-beijing.volces.com/api/coding/v3"
contextKeyTTSRequest
=
"volcengine_tts_request"
contextKeyResponseFormat
=
"response_format"
)
type
Adaptor
struct
{
...
...
@@ -40,7 +37,7 @@ func (a *Adaptor) ConvertGeminiRequest(*gin.Context, *relaycommon.RelayInfo, *dt
}
func
(
a
*
Adaptor
)
ConvertClaudeRequest
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
,
req
*
dto
.
ClaudeRequest
)
(
any
,
error
)
{
if
info
.
ChannelBaseUrl
==
DoubaoCodingPlan
{
if
_
,
ok
:=
channelconstant
.
ChannelSpecialBases
[
info
.
ChannelBaseUrl
];
ok
{
adaptor
:=
claude
.
Adaptor
{}
return
adaptor
.
ConvertClaudeRequest
(
c
,
info
,
req
)
}
...
...
@@ -243,11 +240,12 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
if
baseUrl
==
""
{
baseUrl
=
channelconstant
.
ChannelBaseURLs
[
channelconstant
.
ChannelTypeVolcEngine
]
}
specialPlan
,
hasSpecialPlan
:=
channelconstant
.
ChannelSpecialBases
[
baseUrl
]
switch
info
.
RelayFormat
{
case
types
.
RelayFormatClaude
:
if
baseUrl
==
DoubaoCodingPlan
{
return
fmt
.
Sprintf
(
"%s/v1/messages"
,
DoubaoCodingPlan
ClaudeBaseURL
),
nil
if
hasSpecialPlan
&&
specialPlan
.
ClaudeBaseURL
!=
""
{
return
fmt
.
Sprintf
(
"%s/v1/messages"
,
specialPlan
.
ClaudeBaseURL
),
nil
}
if
strings
.
HasPrefix
(
info
.
UpstreamModelName
,
"bot"
)
{
return
fmt
.
Sprintf
(
"%s/api/v3/bots/chat/completions"
,
baseUrl
),
nil
...
...
@@ -256,8 +254,8 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
default
:
switch
info
.
RelayMode
{
case
constant
.
RelayModeChatCompletions
:
if
baseUrl
==
DoubaoCodingPlan
{
return
fmt
.
Sprintf
(
"%s/chat/completions"
,
DoubaoCodingPlan
OpenAIBaseURL
),
nil
if
hasSpecialPlan
&&
specialPlan
.
OpenAIBaseURL
!=
""
{
return
fmt
.
Sprintf
(
"%s/chat/completions"
,
specialPlan
.
OpenAIBaseURL
),
nil
}
if
strings
.
HasPrefix
(
info
.
UpstreamModelName
,
"bot"
)
{
return
fmt
.
Sprintf
(
"%s/api/v3/bots/chat/completions"
,
baseUrl
),
nil
...
...
@@ -345,11 +343,13 @@ 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
&&
info
.
ChannelBaseUrl
==
DoubaoCodingPlan
{
if
info
.
IsStream
{
return
claude
.
ClaudeStreamHandler
(
c
,
resp
,
info
,
claude
.
RequestModeMessage
)
if
info
.
RelayFormat
==
types
.
RelayFormatClaude
{
if
_
,
ok
:=
channelconstant
.
ChannelSpecialBases
[
info
.
ChannelBaseUrl
];
ok
{
if
info
.
IsStream
{
return
claude
.
ClaudeStreamHandler
(
c
,
resp
,
info
,
claude
.
RequestModeMessage
)
}
return
claude
.
ClaudeHandler
(
c
,
resp
,
info
,
claude
.
RequestModeMessage
)
}
return
claude
.
ClaudeHandler
(
c
,
resp
,
info
,
claude
.
RequestModeMessage
)
}
if
info
.
RelayMode
==
constant
.
RelayModeAudioSpeech
{
...
...
relay/channel/zhipu_4v/adaptor.go
View file @
0ba6004f
...
...
@@ -6,6 +6,7 @@ import (
"io"
"net/http"
channelconstant
"github.com/QuantumNous/new-api/constant"
"github.com/QuantumNous/new-api/dto"
"github.com/QuantumNous/new-api/relay/channel"
"github.com/QuantumNous/new-api/relay/channel/claude"
...
...
@@ -43,15 +44,30 @@ func (a *Adaptor) Init(info *relaycommon.RelayInfo) {
}
func
(
a
*
Adaptor
)
GetRequestURL
(
info
*
relaycommon
.
RelayInfo
)
(
string
,
error
)
{
baseURL
:=
info
.
ChannelBaseUrl
if
baseURL
==
""
{
baseURL
=
channelconstant
.
ChannelBaseURLs
[
channelconstant
.
ChannelTypeZhipu_v4
]
}
specialPlan
,
hasSpecialPlan
:=
channelconstant
.
ChannelSpecialBases
[
baseURL
]
switch
info
.
RelayFormat
{
case
types
.
RelayFormatClaude
:
return
fmt
.
Sprintf
(
"%s/api/anthropic/v1/messages"
,
info
.
ChannelBaseUrl
),
nil
if
hasSpecialPlan
&&
specialPlan
.
ClaudeBaseURL
!=
""
{
return
fmt
.
Sprintf
(
"%s/v1/messages"
,
specialPlan
.
ClaudeBaseURL
),
nil
}
return
fmt
.
Sprintf
(
"%s/api/anthropic/v1/messages"
,
baseURL
),
nil
default
:
switch
info
.
RelayMode
{
case
relayconstant
.
RelayModeEmbeddings
:
return
fmt
.
Sprintf
(
"%s/api/paas/v4/embeddings"
,
info
.
ChannelBaseUrl
),
nil
if
hasSpecialPlan
&&
specialPlan
.
OpenAIBaseURL
!=
""
{
return
fmt
.
Sprintf
(
"%s/embeddings"
,
specialPlan
.
OpenAIBaseURL
),
nil
}
return
fmt
.
Sprintf
(
"%s/api/paas/v4/embeddings"
,
baseURL
),
nil
default
:
return
fmt
.
Sprintf
(
"%s/api/paas/v4/chat/completions"
,
info
.
ChannelBaseUrl
),
nil
if
hasSpecialPlan
&&
specialPlan
.
OpenAIBaseURL
!=
""
{
return
fmt
.
Sprintf
(
"%s/chat/completions"
,
specialPlan
.
OpenAIBaseURL
),
nil
}
return
fmt
.
Sprintf
(
"%s/api/paas/v4/chat/completions"
,
baseURL
),
nil
}
}
}
...
...
relay/channel/zhipu_4v/constants.go
View file @
0ba6004f
package
zhipu_4v
var
ModelList
=
[]
string
{
"glm-4"
,
"glm-4v"
,
"glm-3-turbo"
,
"glm-4-alltools"
,
"glm-4-plus"
,
"glm-4-0520"
,
"glm-4-air"
,
"glm-4-airx"
,
"glm-4-long"
,
"glm-4-flash"
,
"glm-4v-plus"
,
"glm-4"
,
"glm-4v"
,
"glm-3-turbo"
,
"glm-4-alltools"
,
"glm-4-plus"
,
"glm-4-0520"
,
"glm-4-air"
,
"glm-4-airx"
,
"glm-4-long"
,
"glm-4-flash"
,
"glm-4v-plus"
,
"glm-4.6"
,
}
var
ChannelName
=
"zhipu_4v"
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