Skip to content

fix: Make OpenRouterUsage fields optional to handle incomplete API re…#15

Merged
christopherkarani merged 1 commit intochristopherkarani:mainfrom
iliasaz:fix/optional-openrouter-usage
Jan 8, 2026
Merged

fix: Make OpenRouterUsage fields optional to handle incomplete API re…#15
christopherkarani merged 1 commit intochristopherkarani:mainfrom
iliasaz:fix/optional-openrouter-usage

Conversation

@iliasaz
Copy link
Contributor

@iliasaz iliasaz commented Dec 31, 2025

Some OpenRouter API responses don't include complete usage data (missing fields or null values), which caused JSON decoding failures. This change:

  • Makes promptTokens, completionTokens, and totalTokens optional in OpenRouterUsage
  • Updates OpenRouterProvider to safely unwrap usage values before creating TokenUsage
  • Adds comprehensive unit tests for OpenRouter type decoding (14 tests)

…sponses

Some OpenRouter API responses don't include complete usage data (missing
fields or null values), which caused JSON decoding failures. This change:

- Makes promptTokens, completionTokens, and totalTokens optional in OpenRouterUsage
- Updates OpenRouterProvider to safely unwrap usage values before creating TokenUsage
- Adds comprehensive unit tests for OpenRouter type decoding (14 tests)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@christopherkarani
Copy link
Owner

@claude review this pr

@claude
Copy link

claude bot commented Jan 3, 2026

Claude encountered an error —— View job

Command failed: git fetch origin --depth=20 fix/optional-openrouter-usage

I'll analyze this and get back to you.

@christopherkarani
Copy link
Owner

@iliasaz I review this pr. and currently holding off on it as we're planning to use https://github.com/christopherkarani/Conduit as the main inference layer. what are your thoughts?

@iliasaz
Copy link
Contributor Author

iliasaz commented Jan 3, 2026

Is Conduit the next iteration of your SwiftAI project, or is it something radically new?
As an alternative to building yet another mega-wrapper, I'd consider matt's package AnyLanguageModel, which is an inference library already supporting many popular providers and API flavors. That way you can focus more on the agentic stuff.

@christopherkarani christopherkarani merged commit 701adea into christopherkarani:main Jan 8, 2026
0 of 4 checks passed
christopherkarani added a commit that referenced this pull request Feb 13, 2026
…licate detection

- Issue #3: Replace .rawValue == string comparisons with typed constants
  for HiveChatRole (system, tool, assistant)
- Issue #6: Add error logging in router catch block when failing to read
  pendingToolCallsKey
- Issue #7: Add duplicateToolName error case and guard in init to throw
  instead of silently overwriting tools with duplicate names
- Issue #15: Add preconditions to HiveCompactionPolicy.init to validate
  maxTokens >= 1 and preserveLastMessages >= 0
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.

2 participants