Skip to content

API Error: max_tokens and max_completion_tokens cannot be set at the same time (火山引擎/DeepSeek API) #288

Open

Description

@SkinAir

环境信息

  • CyberStrikeAI 版本: v1.7.17
  • AI 提供商: 火山引擎 (Volcano Engine)
  • 模型: deepseek-v4-flash-ga-260731
  • Base URL: https://ark.cn-beijing.volces.com/api/coding/v3
  • 操作系统: macOS (Darwin 25.6.0)
  • Go 版本: 1.26.1
  • Python 版本: 3.10.14

问题描述

在使用火山引擎的 DeepSeek API 进行对话时,系统在执行摘要(summarization)功能时报错:

failed to create chat completion: error, status code: 400, status: 400 Bad Request,
message: The parameter `max_tokens` specified in the request are not valid:
max_tokens and max_completion_tokens cannot be set at the same time.

复现步骤

  1. 在 config.yaml 中配置火山引擎的 DeepSeek API:
ai:
  default_channel: default
  channels:
    default:
      name: 火山codingplan
      provider: openai_compatible
      api_key: ark-xxxxx
      base_url: https://ark.cn-beijing.volces.com/api/coding/v3
      model: deepseek-v4-flash-ga-260731
      max_completion_tokens: 8192
  1. 启动服务并进行对话
  2. 当对话历史达到一定长度触发摘要(summarization)功能时,报错

错误日志

{"level":"warn","timestamp":"2026-08-28T21:44:29.564+0800","caller":"openai/summarization_diag.go:57",
"msg":"eino summarization: API request rejected","status":400,
"request_id":"021787924669719fa871229fec4115dc08043e38393b8b5e20ec7",
"response_bytes":292,
"raw_body":"{\"error\":{\"code\":\"InvalidParameter\",\"message\":\"The parameter `max_tokens` specified in the request are not valid: max_tokens and max_completion_tokens cannot be set at the same time. Request
id: 021787924669719fa871229fec4115dc08043e38393b8b5e20ec7\",\"param\":\"max_tokens\",\"type\":\"BadRequest\"}}"}

根本原因

在 internal/multiagent/eino_summarize.go:303-305 中,代码同时设置了两个互斥的参数:

return []model.Option{
    model.WithMaxTokens(outputReserve),              // 第 304 行
    einoopenai.WithMaxCompletionTokens(outputReserve), // 第 305 行
    // ...
}

火山引擎和部分 OpenAI 兼容 API 不允许同时传递这两个参数。

解决方案

删除 model.WithMaxTokens(outputReserve) 这一行,只保留 einoopenai.WithMaxCompletionTokens(outputReserve):

return []model.Option{
    einoopenai.WithMaxCompletionTokens(outputReserve),
    einoopenai.WithExtraHeader(map[string]string{
        copenai.SummarizationRequestHeader: "1",
    }),
    // ...
}

影响范围

  • 火山引擎 API
  • 部分严格实现 OpenAI 规范的兼容 API
  • 使用 DeepSeek 等对参数校验严格的模型

建议修复

建议在 newEinoSummarizationModelOptions 函数中:

  1. 删除 model.WithMaxTokens(outputReserve) 行
  2. 或者根据 provider 类型动态选择使用哪个参数

相关文件

  • internal/multiagent/eino_summarize.go:304

临时解决方法

用户可以手动修改源码后重新编译:

# 编辑 internal/multiagent/eino_summarize.go,删除第 304 行
go build -o cyberstrike-ai cmd/server/main.go
./cyberstrike-ai -config config.yaml --https

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions