Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Oct 29, 2025

Implements dynamic model discovery for xAI using their REST API endpoints instead of hard-coded model IDs.

Changes

  • Fetches models from xAI's /v1/language-models endpoint
  • Adds model caching with refresh capability in the UI
  • Updates xAI settings with model picker and refresh button
  • Disables reasoning_effort for incompatible models
  • Derives prompt cache support from API pricing metadata

Testing

  • Added unit tests for xAI fetcher and model cache
  • Verified model refresh in UI settings panel

Important

Implements dynamic model discovery for xAI provider using API, updates UI with model picker and caching, and adds relevant tests.

  • Behavior:
    • Implements dynamic model discovery for xAI using /v1/language-models API endpoint.
    • Adds model caching with refresh capability in the UI.
    • Updates xAI settings with model picker and refresh button.
    • Disables reasoning_effort for incompatible models.
    • Derives prompt cache support from API pricing metadata.
  • UI Components:
    • Adds XAI component in XAI.tsx for xAI provider settings.
    • Updates ApiOptions.tsx to integrate xAI model picker and refresh logic.
    • Modifies ApiOptions.spec.tsx to test xAI-specific UI behavior.
  • Testing:
    • Adds unit tests for xAI fetcher in xai.spec.ts.
    • Verifies model refresh in UI settings panel.
  • Misc:
    • Removes xaiModels from static model lists in constants.ts and provider-settings.ts.
    • Adjusts calculateApiCostInternal() in cost.ts to return a number instead of an object.

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

Copilot AI review requested due to automatic review settings October 29, 2025 04:00
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. enhancement New feature or request labels Oct 29, 2025
@roomote
Copy link

roomote bot commented Oct 29, 2025

See this task on Roo Code Cloud

Reviewed the latest commit (8c81c55). The changes only update documentation URLs to point to the correct xAI documentation pages. No issues found.

Issues Found

  • Type safety violation in useSelectedModel hook - Fixed by constructing a complete ModelInfo object using openAiModelInfoSaneDefaults as a base
Previous Reviews

Mention @roomote in a comment to trigger your PR Fixer agent and make changes to this pull request.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR migrates xAI provider from static model configuration to dynamic model fetching, enabling real-time model discovery and pricing information from the xAI API. This brings xAI in line with other dynamic providers like LiteLLM and DeepInfra.

  • Implements dynamic model fetching from xAI's /v1/language-models endpoint
  • Updates xAI provider to be a "dynamic provider" with API key-based model discovery
  • Adds UI components for refreshing models and handling context window overrides

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/api/providers/fetchers/xai.ts New fetcher implementation for xAI models API with pricing and modality parsing
packages/types/src/providers/xai.ts Refactored static registry to store only contextWindow/maxTokens/description, removing pricing fields
webview-ui/src/components/settings/providers/XAI.tsx Added model refresh UI, ModelPicker integration, and context window override
src/api/providers/xai.ts Updated to use context window override and construct complete ModelInfo from partial static data
src/shared/api.ts Added xAI to dynamic provider configuration
src/core/webview/webviewMessageHandler.ts Added xAI model fetching to requestRouterModels handler
webview-ui/src/components/ui/hooks/useSelectedModel.ts Updated to prioritize dynamic models over static for xAI
webview-ui/src/components/settings/ApiOptions.tsx Integrated xAI into dynamic model flow and hid generic model picker

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Oct 29, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Oct 29, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Oct 29, 2025
@hannesrudolph hannesrudolph moved this from PR [Needs Prelim Review] to PR [Draft / In Progress] in Roo Code Roadmap Oct 30, 2025
@hannesrudolph hannesrudolph force-pushed the feat/xai-dynamic-model-discovery branch from c0dbf8a to c0a0dcf Compare October 30, 2025 14:34
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Oct 30, 2025
@hannesrudolph hannesrudolph force-pushed the feat/xai-dynamic-model-discovery branch from c0a0dcf to 4b39e2e Compare October 30, 2025 14:37
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Oct 30, 2025
- Implemented dynamic model discovery for xAI provider using /v1/language-models endpoint
- Models are now fetched at runtime with real-time pricing and capabilities
- Fixed pricing conversion: XAI API returns fractional cents (basis points), divide by 10,000 not 100
- This fixes pricing display showing $20.00 instead of $0.20 per 1M tokens
- Removed static xAI models from MODELS_BY_PROVIDER to rely on dynamic discovery
- Enhanced error logging with detailed status and URL information
- Support dynamic model context window overrides from API
- Fixed parseApiPrice to handle zero values correctly (for free models)
- Provided complete ModelInfo fallback in useSelectedModel for UI type safety
- Added comprehensive test coverage for cost utilities and XAI fetcher
- Updated all tests to reflect correct pricing scale and dynamic model behavior
- Resolved conflicts in calculateApiCostOpenAI signature (added reasoningTokens param)
- Updated cerebras.ts to use new cost calculation with reasoning tokens
- Updated groq.ts to use new cost calculation with reasoning tokens
- Updated lite-llm.ts to use new cost calculation with reasoning tokens
- Updated openai-native.ts to use new cost calculation with reasoning tokens
- All providers now properly handle reasoning token costs
Both calculateApiCostAnthropic and calculateApiCostOpenAI now return a number directly (the total cost) instead of an object with totalCost, totalInputTokens, and totalOutputTokens properties.
- Fixed anthropic.ts to destructure totalCost correctly
- Fixed deepinfra.ts to destructure totalCost correctly
- Updated cost test file for both Anthropic and OpenAI functions
The cost calculation functions now return a number directly instead of an object with totalCost, totalInputTokens, and totalOutputTokens properties.
@hannesrudolph hannesrudolph force-pushed the feat/xai-dynamic-model-discovery branch from 23e76db to 27830f2 Compare November 4, 2025 05:50
@hannesrudolph
Copy link
Collaborator Author

Successfully resolved merge conflicts for PR #8900 "feat(xai): add dynamic model discovery with correct pricing".

Resolution Summary

  • Combined dynamic XAI model discovery with main's new cost signature (number return).
  • Plumbed reasoningTokens where applicable; non-reasoning models pass undefined.
  • Updated all call sites to use direct number instead of destructuring.
  • Type-check and lint pass; CI checks passing.

Files Resolved

  1. src/shared/cost.ts
  2. src/api/providers/openai-native.ts
  3. src/api/providers/cerebras.ts
  4. src/api/providers/groq.ts
  5. src/api/providers/lite-llm.ts
  6. src/api/providers/requesty.ts
  7. src/api/providers/anthropic.ts
  8. src/api/providers/deepinfra.ts
  9. src/core/task/Task.ts
  10. src/utils/tests/cost.spec.ts

Current Status

  • Mergeable: MERGEABLE
  • Merge State: BLOCKED (reviews required)
  • Checks: All passing (including Windows/Ubuntu platform tests and integration tests)

Request

  • Please re-review and merge when ready.

@hannesrudolph hannesrudolph requested a review from roomote November 4, 2025 05:59
@hannesrudolph hannesrudolph moved this from PR [Draft / In Progress] to PR [Needs Prelim Review] in Roo Code Roadmap Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request PR - Needs Preliminary Review size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

Status: PR [Needs Prelim Review]

Development

Successfully merging this pull request may close these issues.

2 participants