fix(openai): adapt gpt responses api for max completions - #703
Conversation
Add an end-to-end test for the GPT-5-nano model in the API to verify correct handling of parameters, response structure, and logging. The test checks for successful response status, validates the response content and usage tokens, and ensures the model and provider are correctly logged. Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
WalkthroughAdds two identical GPT-5-nano end-to-end tests to the gateway that exercise /v1/chat/completions with extra parameters, and renames an OpenAI Responses API request field from Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Gateway
participant Models as provider-api.prepareRequestBody
participant OpenAI as OpenAI Responses API
Client->>Gateway: POST /v1/chat/completions (gpt-5-nano, extra params)
Gateway->>Models: prepareRequestBody(request)
alt Reasoning enabled & no tool calls
Models-->>Gateway: payload (includes max_output_tokens)
else Other path
Models-->>Gateway: payload (other fields)
end
Gateway->>OpenAI: POST /responses (payload)
OpenAI-->>Gateway: 200 (choices, usage)
Gateway-->>Client: Forwarded response
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
Changed max_completion_tokens to max_output_tokens in provider-api.ts and types.ts to ensure consistency in request body handling. Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
- Updated e2e test to handle message content as string, array, or object. - Added logging for non-string content types to aid debugging. - Improved assertions to validate different content formats in message. - Ensures robustness of content checks in API end-to-end tests. Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/gateway/src/api.e2e.ts (1)
1676-1751: Mark test as skipped when no OpenAI key (use test.runIf) and optionally assert logged params.Current early return treats the test as “pass.” Prefer
test.runIf(ortest.skip) so CI shows an explicit skip. Also consider assertinglog.reasoningEffort === "medium"and, if available,log.maxTokens === 100to validate end-to-end parameter propagation.Apply this minimal change to mark the test as skipped cleanly:
-test("GPT-5-nano responses API parameter handling", async () => { - const envVarName = getProviderEnvVar("openai"); - const envVarValue = envVarName ? process.env[envVarName] : undefined; - if (!envVarValue) { - console.log( - "Skipping GPT-5-nano responses API test - no OpenAI API key provided", - ); - return; - } +const envVarName = getProviderEnvVar("openai"); +const envVarValue = envVarName ? process.env[envVarName] : undefined; +const run = !!envVarValue ? test : test.skip; +run("GPT-5-nano responses API parameter handling", async () => {Optionally assert logged parameters after obtaining
log:const log = await validateLogs(); expect(log.streamed).toBe(false); expect(log.usedModel).toBe("gpt-5-nano"); expect(log.usedProvider).toBe("openai"); + // Optional: verify parameter propagation + expect(log.reasoningEffort).toBe("medium"); + if (log.maxTokens !== null && log.maxTokens !== undefined) { + expect(log.maxTokens).toBe(100); + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
apps/gateway/src/api.e2e.ts(1 hunks)packages/models/src/provider-api.ts(1 hunks)packages/models/src/types.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use localStorage instead of cookies for client-side data persistence
Files:
packages/models/src/types.tspackages/models/src/provider-api.tsapps/gateway/src/api.e2e.ts
**/*.{js,ts}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.{js,ts}: Use drizzle with the latest object syntax for database operations
For read queries, always usedb().query.<table>.findMany()ordb().query.<table>.findFirst()
Files:
packages/models/src/types.tspackages/models/src/provider-api.tsapps/gateway/src/api.e2e.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/general.mdc)
Never use
as anyor: anyin TypeScript files.
Files:
packages/models/src/types.tspackages/models/src/provider-api.tsapps/gateway/src/api.e2e.ts
apps/{api,gateway}/**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
.findMany() or db().query.
apps/{api,gateway}/**/*.{ts,tsx}: Use Drizzle with the latest object syntax for database operations
For read queries, use db().query..findFirst() Files:
apps/gateway/src/api.e2e.tsapps/gateway/**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
In apps/gateway (Hono), always use Hono + Zod + OpenAPI for validation and typesafety
Files:
apps/gateway/src/api.e2e.ts{apps/{api,gateway}/**/*.ts,packages/db/**/*.ts}
📄 CodeRabbit inference engine (CLAUDE.md)
{apps/{api,gateway}/**/*.ts,packages/db/**/*.ts}: Use Drizzle ORM with the latest object syntax
For read queries, use db().query..findMany() or db().query.
.findFirst() Files:
apps/gateway/src/api.e2e.ts**/*.e2e.ts
📄 CodeRabbit inference engine (CLAUDE.md)
End-to-end tests should be named with the .e2e.ts suffix
Files:
apps/gateway/src/api.e2e.ts**/*.{spec,e2e}.ts
📄 CodeRabbit inference engine (CLAUDE.md)
Write tests using Vitest
Files:
apps/gateway/src/api.e2e.ts🧬 Code graph analysis (1)
apps/gateway/src/api.e2e.ts (3)
apps/gateway/src/lib/provider.ts (1)
getProviderEnvVar(25-29)apps/gateway/src/test-utils/test-helpers.ts (1)
getProviderEnvVar(6-6)packages/db/src/schema.ts (1)
log(244-310)⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: e2e / run
🔇 Additional comments (3)
packages/models/src/types.ts (2)
202-202: Rename aligns with Responses API; looks good.Switching to
max_output_tokensmatches OpenAI Responses API expectations and avoids unsupported parameter errors. No further issues in this segment.
202-202: No lingeringmax_completion_tokensreferences found. Migration tomax_output_tokensis complete.packages/models/src/provider-api.ts (1)
485-486: Correct mapping to Responses API.Forwarding
max_tokenstoresponsesBody.max_output_tokensin the Responses branch is correct and should eliminate provider-side validation errors.
- Removed excessive validation and debugging logic for message content in the API e2e test. - Simplified assertions to focus on message content presence.
Summary
max_completion_tokenstomax_output_tokensin provider API and typesChanges
Testing
apps/gateway/src/api.e2e.tsnamedGPT-5-nano responses API parameter handling/v1/chat/completionswith GPT-5-nano model and specific parametersCode
max_completion_tokenstomax_output_tokensinpackages/models/src/provider-api.tsandpackages/models/src/types.tsTest plan
🌿 Generated by Terry
ℹ️ Tag @terragon-labs to ask questions and address PR feedback
📎 Task: https://www.terragonlabs.com/task/b9499f3a-3429-4cb2-af39-1cc04b8b9928
Summary by CodeRabbit
New Features
Bug Fixes
Tests