#7309 Invalid max_tokens value, the valid range of max_tokens is [1, 393216]https://api.deepseek.com/v1/

52.7**2 Posted at: 1 hour ago

Invalid max_tokens value, the valid range of max_tokens is [1, 393216]
https://api.deepseek.com/v1/
{'model': 'deepseek-flash', 'timeout': 300, 'temperature': 0.1, 'max_tokens': 3276800}
Traceback (most recent call last):
File "videotrans\translator\_openaicompat.py", line 77, in _item_task
File "openai\_utils\_utils.py", line 298, in wrapper
File "openai\resources\chat\completions\completions.py", line 1215, in create
File "openai\_base_client.py", line 1332, in post
File "openai\_base_client.py", line 1105, in request
openai.BadRequestError: Error code: 400 - {'error': {'message': 'Invalid max_tokens value, the valid range of max_tokens is [1, 393216]', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_request_error'}}

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "videotrans\task\only_one.py", line 67, in run
File "videotrans\task\_stage_translate.py", line 31, in trans
File "videotrans\translator\_runner.py", line 63, in run
File "videotrans\translator\_base.py", line 71, in run
File "videotrans\translator\_base.py", line 200, in _run_srt
File "tenacity\__init__.py", line 338, in wrapped_f
File "tenacity\__init__.py", line 477, in call
File "tenacity\__init__.py", line 378, in iter
File "tenacity\__init__.py", line 400, in
File "concurrent\futures\_base.py", line 451, in result
File "concurrent\futures\_base.py", line 403, in __get_result
File "tenacity\__init__.py", line 480, in call
File "videotrans\translator\_openaicompat.py", line 82, in _item_task
videotrans.configure.excepts.StopTask: Invalid max_tokens value, the valid range of max_tokens is [1, 393216]
https://api.deepseek.com/v1/
{'model': 'deepseek-flash', 'timeout': 300, 'temperature': 0.1, 'max_tokens': 3276800}

cfg=[TaskCfgVTT]当前工作模式: 翻译视频或音频 单视频模式
原始输入文件名: D:/SetupFiles/yt-dlp/Introduction to FLIP Fluids/houdini/030-38 - Houdini Chocolate VEX Animation.mp4,
输出结果保存到文件夹: D:/SetupFiles/yt-dlp/Introduction to FLIP Fluids/houdini/030-38 - Houdini Chocolate VEX Animation-mp4,
临时文件夹: D:/SetupFiles/pyvideotrans/win-pyvideotrans-v4.05-0711/tmp/23856/1bbab4962e
未选 清理已存在
已选 启用CUDA加速
已选 降噪
语音识别:faster-whisper(本地内置), model_name: distil-large-v3.5, 发音语言: 英语, 断句方式:LLM重新断句
翻译渠道:DeepSeek,原始语言:英语,目标语言:简体中文, 已选 发送完整字幕
配音渠道:Edge-TTS(免费), 角色:Yunxi(Male/CN), 配音语言:简体中文, 已选 二次语音识别
音量:+100%, 语速:+0%, 已选 音频加速, 已选 视频慢速
字幕: 嵌入硬字幕
代理地址:


=
system:Windows-10-10.0.26100-SP0
version:v4.05
frozen:True
language:zh
root_dir:D:/SetupFiles/pyvideotrans/win-pyvideotrans-v4.05-0711

1 Replies

#1 DeepSeek reply at 1 hour ago

核心原因是 给 DeepSeek 的 max_tokens 设置过大。日志显示实际请求参数为 'max_tokens': 3276800,而 DeepSeek 官方限制的最大值为 393216,所以返回 400 Bad Request

max_tokens 越大,AI 单次返回的文本上限越高,但并非越大越好,超过渠道上限会直接报错。

解决方法(任选其一,推荐方法 1)

  1. 进入 菜单 -> 工具/选项 -> 高级选项 -> 字幕翻译调整,找到与 max_tokens / 最大token 相关的设置项,将其改回默认值(或小于 393216 的值,例如 819216384),保存后重试。
  2. 若同时使用了「发送完整字幕」、「AI翻译附带所有字幕做参考」、「LLM纠错每批字幕行数」等会大幅增加 token 消耗的选项,可一并降低为:

    • 关闭「发送完整字幕」或调小每批字幕行数
    • 将「AI翻译渠道每批字幕行数」调小(例如 20-50)
  3. 注意:当前为 v4.05 版本,建议升级到最新 v4.12,部分参数上限与 LLM 纠错逻辑已优化,可减少此类问题。
补充提醒:deepseek-flash 与官方文档中模型命名(deepseek-chat / deepseek-reasoner)不一致,若该模型并非官方支持名称,也可能导致参数校验异常,建议在翻译设置中确认模型名是否为官方可用模型,或切换为 DeepSeek 默认模型。

请查阅相关文档:

Thinking...
Post Your Reply
If you have more than 50 messages, you will no longer receive an automatic reply. Please ask a new question!
Open source and free maintenance is not easy. If this project is helpful to you, please consider making a small donation to help the project continue to maintain and update.

Dondate via ko-fi.com

Related resource