功能模块
OpenAI API 兼容层(Responses / Chat Completions)
相关 Provider
Grok Build
问题与使用场景
Codex 经本地代理(cc-switch)调用 grok2api 的 grok-4.5 时,长会话会直接失败:
HTTP 400
This model's maximum prompt length is 500000 but the request contains 907154 tokens.
建议方案
- P0:
/v1/models 对 grok-4.5 返回 context_length=500000(及兼容字段),方便客户端提前 compact。
- P0:
/responses 增加本地 token 预检;接近/超过上限时返回可恢复错误,或引导 compact,避免直接打上游 400。
- P1:强化 Build compact 路径,保证 compact 后可续跑,并裁剪过旧 reasoning/tool 历史。
- P1:文档补充当前没有 context/auto-compact 配置项、长会话建议走 Build、
reasoningReplayEnabled 的作用与副作用。
期望行为:
- 接近 500k 时能提前 compact 或给出可恢复错误
- 不再直接 upstream 400
验收标准
- 当请求
/v1/models 时,grok-4.5 应返回 context_length=500000(或等价兼容字段)
- 当
/responses 请求接近/超过 500k 时,系统应拦截或引导 compact,而不是直接把超大请求打到上游并返回笼统 400
- 当调用
/v1/responses/compact(Build)后,会话应可继续多轮 /responses
- 现有短会话、不依赖 compact 的客户端应继续兼容
- Codex 长会话回归中,500k 超限硬失败应明显减少
API、配置或界面示例
- 期望的 models 响应片段:
{
"object": "list",
"data": [
{
"id": "grok-4.5",
"object": "model",
"owned_by": "grok2api",
"context_length": 500000
}
]
}
- 超限时期望的可恢复错误示例:
{
"error": {
"type": "invalid_request_error",
"code": "context_length_exceeded",
"message": "Prompt too long for grok-4.5 (estimated 907154 > 500000). Please call /v1/responses/compact or reduce input."
}
}
- 相关接口:
- GET /v1/models
- POST /v1/responses
- POST /v1/responses/compact
- 配置说明:
当前无 context/auto-compact 配置项;与上下文相关的主要是:
routing:
reasoningReplayEnabled: true
reasoningReplayTTL: 1h
reasoningReplayMaxEntries: 10240
替代方案
No response
兼容性、部署与迁移影响
No response
提交前检查
功能模块
OpenAI API 兼容层(Responses / Chat Completions)
相关 Provider
Grok Build
问题与使用场景
Codex 经本地代理(cc-switch)调用 grok2api 的
grok-4.5时,长会话会直接失败:HTTP 400
This model's maximum prompt length is 500000 but the request contains 907154 tokens.
建议方案
/v1/models对grok-4.5返回context_length=500000(及兼容字段),方便客户端提前 compact。/responses增加本地 token 预检;接近/超过上限时返回可恢复错误,或引导 compact,避免直接打上游 400。reasoningReplayEnabled的作用与副作用。期望行为:
验收标准
/v1/models时,grok-4.5应返回context_length=500000(或等价兼容字段)/responses请求接近/超过 500k 时,系统应拦截或引导 compact,而不是直接把超大请求打到上游并返回笼统 400/v1/responses/compact(Build)后,会话应可继续多轮/responsesAPI、配置或界面示例
{
"object": "list",
"data": [
{
"id": "grok-4.5",
"object": "model",
"owned_by": "grok2api",
"context_length": 500000
}
]
}
{
"error": {
"type": "invalid_request_error",
"code": "context_length_exceeded",
"message": "Prompt too long for grok-4.5 (estimated 907154 > 500000). Please call /v1/responses/compact or reduce input."
}
}
当前无 context/auto-compact 配置项;与上下文相关的主要是:
routing:
reasoningReplayEnabled: true
reasoningReplayTTL: 1h
reasoningReplayMaxEntries: 10240
替代方案
No response
兼容性、部署与迁移影响
No response
提交前检查