当前位置: 首页 > backend >正文

openai接口参数max_tokens改名max-completion-tokens?

文章目录

    • 关于max_tokens参数
    • max_tokens改max-completion-tokens?
    • 控制 OpenAI 模型响应的长度

关于max_tokens参数

大模型 API(比如 OpenAI、DeepSeek、Moonshot 等)都是按照“Token 数量”来计费。
控制内容:控制一次请求返回的“全部 token 数量”上限,包括提示(prompt)和生成的内容(completion)。
举例:你发送一个 100 tokens 的 prompt,max_tokens 设为 200,则最多会生成 100 tokens 的回答(100 prompt + 100 completion = 200)。

如果需要输出的内容超出Max_Tokens的最大值,那就需要做好可能被聊天大模型主动截断的准备。

一般,在多轮对话中,历史对话的输入输出都会作为新一轮的模型输入 token 进行计费。

Context Length(上下文长度):
定义:“context length”指的是模型在进行一次特定的推理时可以考虑的最大令牌数。换句话说,它是模型在生成响应之前可以“回顾”和“理解”的输入内容的长度。

作用:这个参数决定了模型能够记住和参考多少先前的信息。较长的上下文长度允许模型在生成响应时利用更多的历史信息。

OpenAI 官方解释更名是为了让参数含义更加清晰,max_completion_tokens 明确表示只限制“生成内容(completion)”部分,而不是输入(prompt)+输出(completion)的总token数,避免长期因 max_tokens 命名带来的困惑。过去,有用户常误解 max_tokens 的精确作用,导致不必要的Bug和支持请求。

max_tokens改max-completion-tokens?

openapi开发者官方论坛:https://community.openai.com/t/why-was-max-tokens-changed-to-max-completion-tokens/938077/1

We are doing this because max_tokens previously meant both the number of tokens we generated (and billed you for) and the number of tokens you got back in your response. With the o1 models, this is no longer true — we generate more tokens than we return, as reasoning tokens are not visible. Some clients may have depended on the previous behavior and written code that assumes that max_tokens equals usage.completion_tokens or the number of tokens they received. To avoid breaking these clients, we are requiring you opt-in to the new behavior by using a new parameter.
我们这样做是因为 max_tokens 之前既表示我们生成的 tokens 数量(以及您为此支付的费用),也表示您在响应中收到的 tokens 数量。对于 o1 模型,情况已不再如此——我们生成的 tokens 比返回的 tokens 多,因为推理 tokens 是不可见的。某些客户端可能依赖于之前的行为,并编写了假设 max_tokens 等于 usage.completion_tokens 或他们收到的 tokens 数量的代码。为了避免破坏这些客户端,我们要求您通过使用一个新参数来选择启用新行为。

More documentation here: https://platform.openai.com/docs/guides/reasoning/controlling-costs
更多信息请参考: https://platform.openai.com/docs/guides/reasoning/controlling-costs

兼容性影响
讨论区用户认为,仅仅为了术语准确就引入breaking change,确实带来定制代码或第三方工具的兼容问题,特别是自动化构建和API适配方面。
但OpenAI表示如此改动是为了长远的API直观性、预期一致性和文档优化。

token限制机制
技术讨论还涉及token配额的计数方式,OpenAI进一步clarify:模型的实际生成token不会超过指定的max_completion_tokens数量。输入太长时会提示报错而不是截断生成。

控制 OpenAI 模型响应的长度

官网文档:https://help.openai.com/en/articles/5072518-controlling-the-length-of-openai-model-responses

You can control the length of a model’s output using several techniques depending on your goals and the model you’re working with.
您可以使用多种技术来控制模型输出的长度,具体取决于您的目标和您正在使用的模型。

Set a Maximum Token Limit
设置最大令牌限制
Use the max_completion_tokens parameter to limit how many tokens the model will generate.
使用 max_completion_tokens 参数来限制模型将生成的令牌数量。

Playground: This is labeled as “Maximum Length”.
Playground:标记为 “Maximum Length”。

API: 应用程序接口 :

For reasoning models like o3, o4-mini, and gpt-4.1, use max_completion_tokens.
对于 o3、o4-mini 和 gpt-4.1 等推理模型 ,请使用 max_completion_tokens

For earlier models, max_tokens still works and behaves the same as before.
对于早期的模型 ,max_tokens 的工作方式和行为与以前相同。

Important: 重要 :
max_tokens is deprecated for newer reasoning models.
max_tokens 对于较新的推理模型已弃用 。

You can review the model reference page for the token behavior of specific models.
您可以查看模型参考页面 ,了解特定模型的令牌行为。

http://www.xdnf.cn/news/5510.html

相关文章:

  • 17前端项目----支付弹框
  • 10.二叉搜索树中第k小的元素(medium)
  • 用pymysql操作数据库
  • POST请求 、响应、requests库高级用法
  • 甜蜜聊天话术库
  • Go语言标识符
  • 嵌入式STM32学习——433M无线遥控灯
  • AI-Talk开发板之驱动1.28寸圆屏
  • 深入理解 Polly:.NET Core 中的健壮错误处理策略
  • HTTP/1.1 host虚拟主机详解
  • USB学习【6】USB传输错误的处理
  • Typescript 源码核心流程
  • 【C语言练习】035. 编写结构体的函数
  • MySQL视图深度解析:从基础语法到高级应用
  • Mask-aware Pixel-Shuffle Down-Sampling (MPD) 下采样
  • vector 常见用法及模拟
  • 算法题(144):跳石头
  • 游戏逆向开发全阶段电子资料分享 – 从入门到精通实战教程
  • 软件架构师知识点总结
  • nfs挂载
  • python实现用户登录
  • 系统架构设计(四):架构风格总结
  • 常见的 DCGM 设备级别指标及其含义
  • 2024睿抗编程赛国赛-题解
  • 作业...
  • 【C/C++】无符号调试:GDB解栈实战指南
  • nrf52832 ble_app_templete_s132及nrf5_sdk packs下载安装
  • 使用FastAPI和React以及MongoDB构建全栈Web应用07 FastAPI实现经典三层架构
  • 2025低空经济发展趋势
  • SQL:SELF JOIN(自连接)与CROSS JOIN(交叉连接)