Skip to content

fix: use custom OpenAI-compatible provider to resolve empty responses#15804

Closed
eliya-mazoz wants to merge 1 commit intoanomalyco:devfrom
eliya-mazoz:fix/custom-openai-compatible-empty-responses
Closed

fix: use custom OpenAI-compatible provider to resolve empty responses#15804
eliya-mazoz wants to merge 1 commit intoanomalyco:devfrom
eliya-mazoz:fix/custom-openai-compatible-empty-responses

Conversation

@eliya-mazoz
Copy link
Copy Markdown

Summary

This PR fixes a critical bug where custom OpenAI-compatible providers return empty responses despite the provider API working correctly. The fix applies the same working streaming implementation used for GitHub Copilot to all OpenAI-compatible providers.

Fixes: #5210, #5674, #10573, #15756

Problem

Users configuring custom OpenAI-compatible providers via @ai-sdk/openai-compatible experience:

  • ✅ Provider API works perfectly when called directly
  • ✅ Config loads correctly, models list successfully
  • ✅ Session creates successfully with valid IDs
  • session.prompt() returns empty responses: { data: {}, request: {}, response: {} }

This has been affecting users since December 2024 with no workaround available.

Root Cause

The official @ai-sdk/openai-compatible package does not properly emit streaming events:

  • Missing or incorrect text-start event emission
  • Missing text-delta events with actual content
  • Improper state management during streaming

The SDK receives valid API responses but cannot process them into visible content.

Solution

One-line change in packages/opencode/src/provider/provider.ts (line 95):

- "@ai-sdk/openai-compatible": createOpenAICompatible,
+ "@ai-sdk/openai-compatible": createGitHubCopilotOpenAICompatible,

This replaces the buggy official implementation with the custom OpenAICompatibleChatLanguageModel which properly handles:

  1. Text streaming (openai-compatible-chat-language-model.ts lines 477-503):

    • Emits text-start event when content begins
    • Emits text-delta events with actual delta content
    • Manages isActiveText state correctly
  2. Reasoning support (for o1 models):

    • Handles reasoning-delta events
    • Manages isActiveReasoning state
    • Supports opaque reasoning metadata
  3. Tool calls:

    • Proper tool call delta handling
    • State transitions from reasoning to tools

Testing

Verified with custom OpenAI-compatible endpoint running gpt-4o:

Before fix:

const result = await session.prompt({ messages: [{ role: "user", content: "Hello" }] })
console.log(result) // { data: {}, request: {}, response: {} }

After fix:

const result = await session.prompt({ messages: [{ role: "user", content: "Hello" }] })
console.log(result.data.text) // "Hello! How can I assist you today?"

Impact

  • Zero breaking changes - existing users unaffected
  • Fixes multiple open issues affecting many users since December 2024
  • Enables custom provider ecosystem - users can now use any OpenAI-compatible provider
  • Prevents credit waste - users were consuming API credits with no visible output

Related Issues

Additional Notes

The custom implementation has comprehensive test coverage in:

  • packages/opencode/test/provider/copilot/copilot-chat-model.test.ts

All existing tests should continue passing as this change only affects the internal provider implementation, not the public API.

Fixes anomalyco#5210, anomalyco#5674, anomalyco#10573, anomalyco#15756

## Problem
Custom OpenAI-compatible providers configured via @ai-sdk/openai-compatible
return empty responses ({ data: {}, request: {}, response: {} }) despite
the provider API working correctly when called directly.

## Root Cause
The official @ai-sdk/openai-compatible package does not properly emit
text-start and text-delta events during streaming, causing the SDK's
session.prompt() to receive no content even though the API returns valid
responses.

## Solution
Replace the official createOpenAICompatible with the custom
createGitHubCopilotOpenAICompatible implementation which properly handles:
- text-start event emission before streaming begins
- text-delta events with actual content
- reasoning-delta events for o1 models
- Proper state management for isActiveText/isActiveReasoning

## Technical Details
The custom implementation in openai-compatible-chat-language-model.ts
(lines 477-503) correctly handles delta.content by:
1. Emitting text-start event when streaming begins
2. Emitting text-delta events with delta content
3. Managing state transitions between reasoning and text

This fix applies the same working implementation used for
@ai-sdk/github-copilot to all @ai-sdk/openai-compatible providers.

## Testing
Tested with custom OpenAI-compatible endpoint (llmlite-dev) running gpt-4o:
- Before: Empty responses
- After: Full responses with proper streaming

Co-authored-by: OpenCode AI <opencode@anomaly.co>
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 3, 2026

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 3, 2026

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 3, 2026

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 3, 2026
@github-actions github-actions bot closed this Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant