Skip to content

Fixes issue #744: nil response bodies in openrouter responses#747

Closed
kplawver wants to merge 2 commits into
crmne:mainfrom
bonusly:bonusly-handle-openrouter-response-body-nils
Closed

Fixes issue #744: nil response bodies in openrouter responses#747
kplawver wants to merge 2 commits into
crmne:mainfrom
bonusly:bonusly-handle-openrouter-response-body-nils

Conversation

@kplawver

Copy link
Copy Markdown

What this does

Fixes issue 744 where openrouter sends empty an response body for streaming responses and .empty? raises an error. Switching it to .blank? works and all the other openrouter provider tests pass.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Performance improvement

Scope check

  • I read the Contributing Guide
  • This aligns with RubyLLM's focus on LLM communication
  • This isn't application-specific logic that belongs in user code
  • This benefits most users, not just my specific use case

Required for new features

  • I opened an issue before writing code and received maintainer approval
  • Linked issue: #___

PRs for new features or enhancements without a prior approved issue will be closed.

Quality check

  • I ran overcommit --install and all hooks pass
  • I tested my changes thoroughly (I monkey-patched RubyLLM locally with the fix to confirm it worked w/ openrouter in our app)
    • For provider changes: Re-recorded VCR cassettes with bundle exec rake vcr:record[provider_name]
    • All tests pass: bundle exec rspec
  • I updated documentation if needed
  • I didn't modify auto-generated files manually (models.json, aliases.json)

AI-generated code

  • I used AI tools to help write this code
  • I have reviewed and understand all generated code (required if above is checked)

API changes

  • Breaking change
  • New public methods/classes
  • Changed method signatures
  • No API changes

@fidalgo

fidalgo commented Apr 27, 2026

Copy link
Copy Markdown

I've opened a PR that aims to fix this on all providers and raising a meaningful error.
Have a look and let me know your thoughts: #733

@Teckden

Teckden commented May 1, 2026

Copy link
Copy Markdown

+1 for the fix, this also happens in our project

but blank? is not a ruby method, it comes from the ActiveSupport, maybe it is better to follow the already existing check in the bedrock chat:

return if data.nil? || data.empty?

@kplawver

kplawver commented May 1, 2026

Copy link
Copy Markdown
Author

+1 for the fix, this also happens in our project

but blank? is not a ruby method, it comes from the ActiveSupport, maybe it is better to follow the already existing check in the bedrock chat:

return if data.nil? || data.empty?

Good call. I'll update it and push (though activesupport is in the Gemfile.lock, it's a good idea not to rely on it). Thanks!

@kplawver

kplawver commented May 1, 2026

Copy link
Copy Markdown
Author

I've opened a PR that aims to fix this on all providers and raising a meaningful error. Have a look and let me know your thoughts: #733

I think the problem is that you can get the nil response at the beginning of a streaming response from an OpenRouter provider, so you don't actually want to raise an error, you just want to return so the stream can continue processing, right? It might be OK for the other providers, but I don't know that this solves the problem from the original bug report about OpenRouter specifically (I could be wrong though).

@crmne

crmne commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Closed because the nil OpenRouter response body fix has landed directly on main in commit 32f70eb. I used the same guard pattern as Bedrock with plain Ruby nil?/empty? handling, plus a regression spec. Thanks for the original fix and discussion.

@crmne crmne closed this Jun 8, 2026
@kplawver

kplawver commented Jun 8, 2026

Copy link
Copy Markdown
Author

Closed because the nil OpenRouter response body fix has landed directly on main in commit 32f70eb. I used the same guard pattern as Bedrock with plain Ruby nil?/empty? handling, plus a regression spec. Thanks for the original fix and discussion.

I'm happy as long as it got fixed. Thanks!

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.

[BUG] NoMethodError: undefined method 'empty?' for nil in OpenRouter parse_completion_response

4 participants