Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Aug 5, 2025

Summary

This PR fixes the Grok-4 API error reported in #6702. The issue was caused by the xAI handler including the stream_options parameter in streaming requests, which is not supported by the xAI API.

Changes

  • Removed stream_options: { include_usage: true } from the xAI handler's streaming request
  • Added a comment explaining why stream_options is not included
  • Updated tests to not expect stream_options in xAI API calls
  • Added a specific test case for Grok-4 streaming to ensure it works correctly

Testing

  • All existing xAI provider tests pass
  • Added new test specifically for Grok-4 model streaming
  • Verified that OpenAI provider tests still pass (which handle Grok via OpenAI-compatible endpoint differently)

Related Issue

Fixes #6702


Important

Remove stream_options from XAIHandler for Grok-4 model to fix API error and update tests accordingly.

  • Behavior:
    • Removed stream_options from XAIHandler in xai.ts for Grok-4 model to fix API error.
    • Added comments explaining the removal of stream_options.
  • Testing:
    • Updated xai.spec.ts to remove expectations for stream_options in xAI API calls.
    • Added test case for Grok-4 model to ensure stream_options is not included.
  • Misc:
    • Verified existing xAI and OpenAI provider tests pass.

This description was created by Ellipsis for 9eb5925. You can customize this summary. It will automatically update as commits are pushed.

- Remove stream_options parameter from xAI streaming requests as the xAI API does not support it
- Add comment explaining why stream_options is not included
- Update tests to not expect stream_options in xAI API calls
- Add specific test case for Grok-4 streaming

Fixes #6702
@roomote roomote bot requested review from cte, jr and mrubens as code owners August 5, 2025 08:52
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Aug 5, 2025
Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

Reviewing my own code is like debugging in production - technically possible but morally questionable.

messages: [{ role: "system", content: systemPrompt }, ...convertToOpenAiMessages(messages)],
stream: true,
stream_options: { include_usage: true },
// xAI API doesn't support stream_options parameter
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I notice the OpenAI provider handles Grok models by checking and conditionally excluding . Since Grok can be used through both the xAI handler and OpenAI-compatible endpoints, would it be helpful to add a comment explaining why both providers need this separate handling?

}
}

// Note: xAI API doesn't support stream_options, so usage data might not be available in streaming responses
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The comment mentions "usage data might not be available in streaming responses" - should we add a test case that verifies the handler still works correctly when usage data is not provided by the xAI API?

messages: expect.arrayContaining([{ role: "system", content: systemPrompt }]),
stream: true,
stream_options: { include_usage: true },
// xAI API doesn't support stream_options
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comment appears both here and on line 279. Could we make this test comment more specific about what aspect of stream_options we're testing?

@roomote roomote bot mentioned this pull request Aug 5, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 5, 2025
@daniel-lxs
Copy link
Member

Looks like a problem with the model, closing

@daniel-lxs daniel-lxs closed this Aug 6, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Aug 6, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Grok4 Issue

4 participants