Skip to content

fix(opencode-go): route Grok 4.7 through the Responses API - #2001

Open
tosinxt wants to merge 1 commit into
Zoo-Code-Org:mainfrom
tosinxt:fix/opencode-go-grok-4-7
Open

tosinxt wants to merge 1 commit into
Zoo-Code-Org:mainfrom
tosinxt:fix/opencode-go-grok-4-7

Conversation

@tosinxt

@tosinxt tosinxt commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Related GitHub Issue

Closes: #1996

Description

OpenCode Go serves grok-4.7 only on the Responses API, but neither format set listed it, so requests went to Chat Completions with the fetcher's generic limits.

  • Routing: grok-4.7 joins OPENCODE_GO_RESPONSES_FORMAT_MODELS explicitly (no Grok-wide rule, as the issue asks), so streaming requests and completePrompt both use /v1/responses.
  • Native configuration, from xAI's Grok 4.7 model page rather than the Grok 4.6 entry:
    • 500,000-token context window, text and image input, function calling.
    • Reasoning effort low / medium / high / xhigh, default high, which the Responses path sends as reasoning.effort.
    • xAI publishes no separate output cap, so, as for grok-4.6, maxTokens equals the context window; requests still go through the shared max-output rule (100K here).
  • Go pricing from the OpenCode Go pricing table (checked October 10, 2026): $2 / $6 / $0.50 per 1M input / output / cached-input tokens up to 200K input tokens, and twice that above (longContextPricing with a 200K threshold). No cache-write rate is set, since Go doesn't publish one. The Responses path already prices through calculateApiCostOpenAI, which applies the tier.

Test Procedure

Run from src/ unless noted:

  • pnpm exec vitest run api/providers/__tests__/opencode-go.spec.ts api/providers/fetchers/__tests__/opencode-go.spec.ts: 100 pass. New cases: streaming and non-streaming requests go to Responses with reasoning.effort: "high" and no temperature (never Chat Completions or Messages); tool-call partials, completed tool calls and cached usage are priced at the Go rates; cost at 200,000 vs 200,001 input tokens plus an above-threshold case with cached input and output; and the fetcher resolves an ID-only catalog entry to the native configuration. Before the fix these fail: requests go to Chat Completions and the fetcher returns the generic 32,768-token fallback.
  • From packages/types: pnpm exec vitest run src/__tests__/opencode-go.test.ts: 42 pass (registry entry, Responses set, no cache-write rate). Existing Grok 4.5 (Chat Completions), Grok 4.6, GPT and other protocol cases are unchanged and pass.
  • pnpm exec vitest run api: 123 files, 3,061 passed. All of packages/types: 31 files, 453 passed.
  • pnpm check-types (in src and packages/types) ✅, pnpm lint ✅ (pre-commit hook), Prettier ✅.

Not run: an authenticated request to the Go gateway. As in the issue, everything is verified with mocked SDK calls.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Visual Snapshot (UI changes only): N/A, no UI change.
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Visual Snapshots

N/A, no UI change.

Videos (interaction / animation only)

N/A.

Documentation Updates

  • No documentation updates are required.

Additional Notes

#2000 (Claude Haiku 5.5, #1995) touches the same files in different places; the two branches merge cleanly with each other in either order.

Get in Touch

Discord: tosin.py

OpenCode Go serves grok-4.7 only on /v1/responses, but the provider
sent it to Chat Completions with generic limits. Add it to the
Responses format set with a native configuration from xAI's model page
(500K context, text and image input, reasoning effort
low/medium/high/xhigh with high as the default) and the Go pricing with
its 200K tier and no cache-write rate.

Closes Zoo-Code-Org#1996
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: Zoo-Code-Org/Zoo-Code/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: a5e83bd3-efd8-4b98-bdc0-69b8343415e1



📥 Commits

Reviewing files that changed from the base of the PR and between ecab519 and 9b5ffdb.




📒 Files selected for processing (4)
  • packages/types/src/__tests__/opencode-go.test.ts
  • packages/types/src/providers/opencode-go.ts
  • src/api/providers/__tests__/opencode-go.spec.ts
  • src/api/providers/fetchers/__tests__/opencode-go.spec.ts



Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.




📜 Recent review details
🧰 Additional context used
📓 Path-based instructions (6)
Treat model, provider, MCP, path, command, and tool data as untrusted.

⚙️ CodeRabbit configuration file

Files:

  • src/api/providers/fetchers/__tests__/opencode-go.spec.ts
  • src/api/providers/__tests__/opencode-go.spec.ts



For persisted settings, verify the complete schema/storage/runtime/webview round trip, shared default semantics, and focused true plus false/unset tests.

⚙️ CodeRabbit configuration file

Files:

  • packages/types/src/__tests__/opencode-go.test.ts
  • packages/types/src/providers/opencode-go.ts



Require regression coverage at the lowest valid harness with behavior-focused assertions, including relevant negative, error, false/unset, and boundary cases.

⚙️ CodeRabbit configuration file

Files:

  • packages/types/src/__tests__/opencode-go.test.ts
  • src/api/providers/fetchers/__tests__/opencode-go.spec.ts
  • src/api/providers/__tests__/opencode-go.spec.ts



Check strict typing and exhaustive behavior across normal, boundary, error, cancellation, retry, and compatibility paths.

⚙️ CodeRabbit configuration file

Files:

  • packages/types/src/__tests__/opencode-go.test.ts
  • src/api/providers/fetchers/__tests__/opencode-go.spec.ts
  • packages/types/src/providers/opencode-go.ts
  • src/api/providers/__tests__/opencode-go.spec.ts



Verify extension/webview contracts, cancellation and error propagation, VS Code lifecycle correctness, and behavior under retries and partial failure.

⚙️ CodeRabbit configuration file

Files:

  • src/api/providers/fetchers/__tests__/opencode-go.spec.ts
  • src/api/providers/__tests__/opencode-go.spec.ts



Act as an adversarial second-opinion reviewer.

⚙️ CodeRabbit configuration file

Files:

  • packages/types/src/__tests__/opencode-go.test.ts
  • src/api/providers/fetchers/__tests__/opencode-go.spec.ts
  • packages/types/src/providers/opencode-go.ts
  • src/api/providers/__tests__/opencode-go.spec.ts

🪛 GitHub Check: mutation-diff
packages/types/src/providers/opencode-go.ts

[warning] 653-653: Mutation test advisory
packages/types/src/providers/opencode-go.ts:653: Survived StringLiteral mutant (replacement: ""). See the job summary for the complete list and resolution guidance.





🔇 Additional comments (4)
packages/types/src/providers/opencode-go.ts (1)

633-654: LGTM!

Also applies to: 735-735


packages/types/src/__tests__/opencode-go.test.ts (1)

43-43: LGTM!

Also applies to: 193-216


src/api/providers/fetchers/__tests__/opencode-go.spec.ts (1)

127-144: LGTM!

Also applies to: 236-236


src/api/providers/__tests__/opencode-go.spec.ts (1)

45-46: LGTM!

Also applies to: 54-54, 1372-1372, 1381-1408, 1410-1454, 1456-1467, 1469-1489






📝 Summary

Summary by CodeRabbit

  • New Features
    • Added Grok 4.7 to the OpenCode Go model catalog, with support for image inputs, prompt caching, configurable reasoning effort, and up to 500,000 tokens of context and output.
    • Added tiered pricing for longer-context requests.
📝 Summary
📝 Summary

Walkthrough

The OpenCode Go model registry now includes Grok 4.7 metadata and Responses routing. Tests cover native model discovery, streaming and prompt-completion requests, tool calls, usage accounting, and pricing tiers.

Changes

OpenCode Go Grok 4.7 support

Layer / File(s) Summary
Registry metadata and Responses classification
packages/types/src/providers/opencode-go.ts, packages/types/src/__tests__/opencode-go.test.ts
The registry adds Grok 4.7 with a 500,000-token context and output limit, image and prompt-cache support, reasoning options, and pricing. It routes the model through Responses. Registry tests check its metadata.
Native model configuration
src/api/providers/fetchers/__tests__/opencode-go.spec.ts
Fetcher tests check that an ID-only catalog entry resolves to Grok 4.7 native metadata.
Responses request handling
src/api/providers/__tests__/opencode-go.spec.ts
Provider tests cover Responses routing for streaming and prompt completion, reasoning settings, tool calls, cached-token usage, and pricing tiers. Model-cache mocks include Grok 4.7.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium





Merge Risk: ⚪ Minimal · up to 9b5ff

This adds Grok 4.7 support for OpenCode Go with the specified routing, limits, and pricing. No merge-blocking risk was identified; the only caveat is that no authenticated gateway request was run.

Pre-merge checks | Passed 8
✅ Passed checks (8 passed)
Check name Status Explanation
Linked Issues check Passed Issue #1996 coding requirements are met. The PR adds grok-4.7 to OPENCODE_GO_RESPONSES_FORMAT_MODELS and adds native metadata with a 500,000-token context, image support, prompt-cache support, rea…
Out of Scope Changes check Passed The changed files stay within issue #1996. Registry changes implement routing and native model configuration. Provider tests verify the requested request paths, capabilities, pricing, and usage behavi…
Regression Evidence Passed Focused coverage exists for each changed behavior. The registry tests verify Grok 4.7 metadata, Responses classification, and the intentionally unset cache-write price (packages/types/src/tests/op…
Security Boundaries Passed No changed path meets the security failure conditions. The production diff only adds static grok-4.7 metadata and its exact ID to the Responses allowlist in `packages/types/src/providers/opencode-go…
Persistence Integrity Passed PASS — The pull request changes only the OpenCode Go model registry, format classification, and tests. The changed production code adds static grok-4.7 metadata and routing; it does not add or modif…
Lifecycle Resource Cleanup Passed No changed lifecycle path can be shown to leak a resource or duplicate work. The PR changes only the Grok 4.7 registry entry and the Responses-format model set in `packages/types/src/providers/opencod…
Title check Passed The title clearly and concisely describes the primary change: routing OpenCode Go's Grok 4.7 integration through the Responses API.
Description check Passed The description follows the repository template. It links issue #1996, explains the routing and native configuration changes, documents focused and broad test procedures with results, completes the ch…

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR





  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

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

@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review status

Thanks for contributing. This comment tracks the review sequence and the next action.

Current step: Awaiting fresh human maintainer or CODEOWNER approval.

Automated review is complete for the latest commit but does not replace human approval.

Review-state labels are managed by this workflow; do not edit them manually. community-approved is managed the same way — do not add or remove it manually. It signals a fresh community code approval for the current head as an advisory priority only; maintainer review is still required.

@codecov

codecov Bot commented Oct 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot added coderabbit-review-active Required CI passed; CodeRabbit review is active awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit labels Oct 10, 2026
@github-actions github-actions Bot added awaiting-maintainer CodeRabbit approved; waiting for a human maintainer and removed coderabbit-review-active Required CI passed; CodeRabbit review is active awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit labels Oct 10, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-maintainer CodeRabbit approved; waiting for a human maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] OpenCode Go routes Grok 4.7 through Chat Completions instead of Responses

1 participant