Skip to content

fix(openai): adapt gpt responses api for max completions - #703

Merged
steebchen merged 5 commits into
mainfrom
terragon/add-e2e-test-gpt5-nano-responses-api
Sep 1, 2025
Merged

steebchen merged 5 commits into
mainfrom
terragon/add-e2e-test-gpt5-nano-responses-api

Conversation

@steebchen

@steebchen steebchen commented Sep 1, 2025

Copy link
Copy Markdown
Member

Summary

  • Adds an end-to-end test for the GPT-5-nano model responses API
  • Validates parameter handling including model selection, messages, max tokens, and reasoning effort
  • Ensures successful response status and correct response structure
  • Checks logs for correct model and provider usage
  • Verifies reasoning tokens and content presence in the response
  • Updates parameter naming from max_completion_tokens to max_output_tokens in provider API and types

Changes

Testing

  • Added a new test case in apps/gateway/src/api.e2e.ts named GPT-5-nano responses API parameter handling
  • Test skips if no OpenAI API key is provided
  • Sends a POST request to /v1/chat/completions with GPT-5-nano model and specific parameters
  • Validates HTTP 200 response and response JSON structure
  • Confirms no unsupported parameter errors
  • Validates logs for streamed flag, used model, and provider
  • Checks reasoning tokens and message content in the response

Code

  • Renamed max_completion_tokens to max_output_tokens in packages/models/src/provider-api.ts and packages/models/src/types.ts

Test plan

  • Run the new e2e test with a valid OpenAI API key
  • Confirm the test skips gracefully without the API key
  • Verify response correctness and log validation
  • Ensure no regression in existing tests

🌿 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

    • Improved compatibility with the OpenAI responses API by using the correct output parameter when reasoning is enabled.
  • Bug Fixes

    • Fixed handling of output token limits to align with provider expectations, improving response reliability and usage reporting.
  • Tests

    • Added end-to-end coverage for GPT-5-nano parameter handling, validating response structure, usage metrics (including reasoning tokens), and provider/model logging (duplicate test blocks included).

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>
@coderabbitai

coderabbitai Bot commented Sep 1, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds 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 max_completion_tokens to max_output_tokens, updating the TypeScript interface accordingly.

Changes

Cohort / File(s) Summary
Gateway e2e tests
apps/gateway/src/api.e2e.ts
Adds two identical e2e tests for GPT-5-nano calling /v1/chat/completions with extra params (e.g., max_tokens, reasoning_effort), asserting 200, validating choices[0].message.content (string/array/object handling), checking usage (including optional reasoning_tokens), and confirming logs show model/provider.
OpenAI Responses API payload rename
packages/models/src/provider-api.ts, packages/models/src/types.ts
Renames request-body field max_completion_tokensmax_output_tokens in the OpenAI Responses API path when reasoning is enabled and updates the OpenAIResponsesRequestBody interface accordingly.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs


📜 Recent 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 110b8d7 and cd1cebb.

📒 Files selected for processing (1)
  • apps/gateway/src/api.e2e.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/gateway/src/api.e2e.ts
⏰ 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)
  • GitHub Check: build / run
  • GitHub Check: e2e / run
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch terragon/add-e2e-test-gpt5-nano-responses-api

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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>
@steebchen steebchen changed the title Add e2e test for GPT-5-nano responses API parameter handling Add e2e test for GPT-5-nano responses API parameter handling and update token parameter naming Sep 1, 2025
@github-actions github-actions Bot changed the title Add e2e test for GPT-5-nano responses API parameter handling and update token parameter naming feat(tests): add e2e test for GPT-5-nano responses API</|assistant|> Sep 1, 2025
@steebchen steebchen changed the title feat(tests): add e2e test for GPT-5-nano responses API</|assistant|> feat(tests): add e2e test for GPT-5-nano responses API Sep 1, 2025
- 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>
@steebchen
steebchen marked this pull request as ready for review September 1, 2025 16:32

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (or test.skip) so CI shows an explicit skip. Also consider asserting log.reasoningEffort === "medium" and, if available, log.maxTokens === 100 to 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 564c9a6 and 110b8d7.

📒 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.ts
  • packages/models/src/provider-api.ts
  • apps/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 use db().query.<table>.findMany() or db().query.<table>.findFirst()

Files:

  • packages/models/src/types.ts
  • packages/models/src/provider-api.ts
  • apps/gateway/src/api.e2e.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Never use as any or : any in TypeScript files.

Files:

  • packages/models/src/types.ts
  • packages/models/src/provider-api.ts
  • apps/gateway/src/api.e2e.ts
apps/{api,gateway}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

apps/{api,gateway}/**/*.{ts,tsx}: Use Drizzle with the latest object syntax for database operations
For read queries, use db().query.

.findMany() or db().query.
.findFirst()

Files:

  • apps/gateway/src/api.e2e.ts
apps/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_tokens matches OpenAI Responses API expectations and avoids unsupported parameter errors. No further issues in this segment.


202-202: No lingering max_completion_tokens references found. Migration to max_output_tokens is complete.

packages/models/src/provider-api.ts (1)

485-486: Correct mapping to Responses API.

Forwarding max_tokens to responsesBody.max_output_tokens in 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.
@steebchen steebchen changed the title feat(tests): add e2e test for GPT-5-nano responses API fix(openai): adapt gpt responses api for max completions Sep 1, 2025
@steebchen
steebchen added this pull request to the merge queue Sep 1, 2025
Merged via the queue into main with commit 3be5d0a Sep 1, 2025
12 checks passed
@steebchen
steebchen deleted the terragon/add-e2e-test-gpt5-nano-responses-api branch September 1, 2025 17:40
@coderabbitai coderabbitai Bot mentioned this pull request Jan 16, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant