QuantumNous / QuantumNous/new-api
[Bug] Claude Messages 转 OpenAI Chat 时单元素 stop_sequences 被转换为 string,导致部分上游 400
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 48.5k
- Forks
- 11.6k
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 58
Description
Deployment source
Repository release / official image (self-hosted)
Your current newapi version
v1.0.0-rc.30
Submission Checks
- Non-duplicate issue: I have searched existing Issues and confirmed there are no similar issues.
- Read this first: I have fully read the section above, reviewed the docs at https://docs.newapi.ai/ and the project README, and asked AI first, confirming this is not a usage, configuration, or integration question.
- Supported version: I have provided an exact version, commit, or image tag (not
latestorunknown) and confirmed that the issue reproduces on an unmodified, supported version from this repository. - Not a third-party service: I confirm that this issue is not exclusive to a third-party hosting site, relay, API service, or fork that has not been verified against the unmodified repository. Third-party instance issues must be reported to their operator.
- Issue attribution: I have provided evidence that distinguishes the client, new-api, and upstream layers. For relay issues, I compared equivalent redacted requests sent directly upstream and through new-api, confirming that new-api introduces or changes the error rather than merely forwarding the upstream error unchanged.
- Channel and protocol boundary: I confirm that the issue is not caused by a Coding Plan service, reverse-engineered channel, third-party API wrapper, Codex reverse-proxy endpoint, or behavior specific to the Codex API. If first observed through such an interface, I have reproduced it using a standard API protocol supported by this repository.
- Maintainer time: I understand that maintainers have limited time and issues that do not follow this template may be ignored or closed directly.
Issue Description
当通过 /v1/messages 调用 Claude Messages API,并由 NewAPI 转换为 OpenAI Chat Completions 请求时:
如果请求中的 stop_sequences 只有一个元素,例如:
{
"stop_sequences": ["</block>"]
}
NewAPI 会转换成:
{
"stop": "</block>"
}
而不是保留数组:
"stop": ["</block>"]
虽然 OpenAI Chat Completions API 本身允许 stop 为 string 或 array,
但部分严格的 OpenAI-compatible provider 只接受 array。
例如 OpenCode Go 的部分上游会因此返回:
status_code=400
JSON parse error:
Cannot construct instance of ArrayList
no String-argument constructor/factory method to deserialize from String value ('</block>')
ChatCompletionRequest["stop"]
Steps to Reproduce
客户端请求:
POST /v1/messages
请求中包含:
{
"stop_sequences": ["</block>"]
}
NewAPI 在 Claude Messages -> OpenAI Chat Completions 转换后发送:
{
"stop": "</block>"
}
上游要求:
{
"stop": ["</block>"]
}
因此返回 HTTP 400。
当前行为
单元素:
[""]
转换为:
""
多元素:
["A", "B"]
则仍然保持数组。
因此该问题表现为间歇性:只有请求包含单个 stop_sequences 时才会触发。
Expected Result
建议 Claude Messages -> OpenAI Chat Completions 转换时始终保持 stop_sequences 的数组结构:
if len(claudeRequest.StopSequences) > 0 {
openAIRequest.Stop = claudeRequest.StopSequences
}
而不是:
if len(claudeRequest.StopSequences) == 1 {
openAIRequest.Stop = claudeRequest.StopSequences[0]
} else if len(claudeRequest.StopSequences) > 1 {
openAIRequest.Stop = claudeRequest.StopSequences
}
这样生成:
{
"stop": [""]
}
仍然是合法的 OpenAI Chat Completions 请求,同时兼容要求 stop 必须为数组的 provider。
Related Screenshots
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Claude Messages to OpenAI Chat conversion handling the /v1/messages path and trace how stop_sequences is mapped. Reproduce the case with a one-element array, then verify that the outgoing request preserves an array while multi-element behavior remains unchanged. Done when strict array-only providers accept the converted request without the reported 400 error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 74/100