Skip to content

fix(litellm): enrich model discovery with info#10

Merged
yuseferi merged 5 commits into
yuseferi:mainfrom
overbit:fix-model-info
Jul 24, 2026
Merged

fix(litellm): enrich model discovery with info#10
yuseferi merged 5 commits into
yuseferi:mainfrom
overbit:fix-model-info

Conversation

@overbit

@overbit overbit commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes: #9
Fixes non-chat (embedding/image/audio) models appearing in the OpenCode picker and missing capability metadata (vision, reasoning, limits) for database-defined LiteLLM models. Discovery now enriches /v1/models with /v1/model/info — with alias-tolerant matching, a realistic fetch timeout for remote proxies, and visible warnings when enrichment degrades — and maps LiteLLM capability flags to OpenCode's reasoning and modalities fields.

Type of change

  • 🐛 Bug fix (non-breaking)
  • ✨ New feature (non-breaking)
  • 💥 Breaking change
  • 📝 Documentation only
  • 🔧 Internal / refactor

Checklist

  • npm run typecheck passes
  • No new runtime dependencies (or justified in this PR description)
  • README updated if public API or behavior changed
  • CHANGELOG.md updated under ## [Unreleased]
  • Commit messages follow Conventional Commits

How was this tested?

  • tsc --noEmit clean (Node 24, TypeScript 5.9).
  • Ran the real plugin config hook against a mock LiteLLM HTTP server (20 assertions) replicating payloads observed on LiteLLM 1.89.2 with database-defined models:
    • lean /v1/models entries without mode — embedding models are hidden once /v1/model/info supplies mode: embedding, including ids with no "embed" substring;
    • alias mismatch (model_name: gemini/gemini-3.6-flash vs model_info.key: gemini/gemini-3.5-flash) — enrichment still lands via multi-key indexing (model_name / model_info.key / litellm_params.model);
    • mode: null moonshot entries with supports_vision on litellm_params — vision, reasoning, pdf/audio flags map to OpenCode attachment, reasoning, and modalities.input;
    • deepseek/* wildcard access-rule entries are hidden;
    • duplicate model_name info entries (wildcard expansion) are deduped;
    • /v1/model/info returning HTTP 500 — discovery degrades to id heuristics with a logged warning, chat models still load;
    • repeated config hook invocations (OpenCode calls it multiple times per run) are a no-op with zero extra HTTP requests.
  • Iterated against a live remote LiteLLM 1.89.2 proxy (OpenCode 1.17.11, node:24-bookworm-slim) during development; a final picker re-check on the live setup is appreciated.

Screenshots / logs (optional)

```
[opencode-litellm] Discovered 18 models from https://litellm.example.com (16 added, 1 non-chat hidden, 1 wildcard ignored)
[opencode-litellm] /v1/model/info unavailable; non-chat model filtering will use id heuristics only:
```

Summary by CodeRabbit

  • New Features

    • Model discovery now uses richer metadata to identify chat models and their capabilities.
    • The model picker hides embedding, image, audio, non-chat, and wildcard models.
    • Reasoning, vision, PDF, image, and audio support are reflected in model configuration.
    • Discovery supports model aliases and reports discovered, added, skipped, and hidden models.
  • Bug Fixes

    • Repeated configuration runs no longer trigger unnecessary model re-discovery.
    • Discovery now tolerates unavailable metadata endpoints and falls back to existing classification.
    • Discovery timeout increased to 15 seconds while health checks remain fast.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@overbit, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 58 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9b8dc508-4735-4337-a919-cafce57c67e7

📥 Commits

Reviewing files that changed from the base of the PR and between a2d4f2d and 01ea9fc.

📒 Files selected for processing (3)
  • README.md
  • src/plugin/index.ts
  • src/utils/litellm-api.ts
📝 Walkthrough

Walkthrough

LiteLLM discovery now retrieves and merges /v1/model/info metadata, filters non-chat and wildcard models, avoids repeated injection, and propagates reasoning and modality capabilities into OpenCode configuration.

Changes

Model discovery and OpenCode integration

Layer / File(s) Summary
Metadata contracts and API discovery
src/types/index.ts, src/utils/litellm-api.ts
Adds typed /v1/model/info responses, separate health and fetch timeouts, and alias-aware metadata discovery.
Discovery orchestration and model filtering
src/plugin/index.ts
Adds idempotent parallel discovery, metadata enrichment, non-chat and wildcard filtering, preservation of existing models, and expanded logging.
OpenCode capability mapping
src/plugin/index.ts, src/plugin/build-model.ts
Propagates reasoning, vision, PDF, attachment, and modality capabilities into OpenCode model entries.
Behavior and layout documentation
CHANGELOG.md, README.md
Documents enriched discovery, filtering, timeout behavior, and updated source layout.

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

Sequence Diagram(s)

sequenceDiagram
  participant ConfigHook
  participant LiteLLMModels
  participant LiteLLMModelInfo
  participant OpenCodeConfig
  ConfigHook->>LiteLLMModels: Fetch /v1/models
  ConfigHook->>LiteLLMModelInfo: Fetch /v1/model/info
  LiteLLMModels-->>ConfigHook: Return model entries
  LiteLLMModelInfo-->>ConfigHook: Return capability metadata
  ConfigHook->>OpenCodeConfig: Add filtered enriched models
  ConfigHook->>ConfigHook: Cache injected model ids
Loading

Suggested reviewers: yuseferi

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: enriching LiteLLM model discovery with model info.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
src/utils/litellm-api.ts (1)

112-119: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Generalize the litellm_params fallback beyond supports_vision.

Only supports_vision is backfilled from litellm_params when missing from model_info. The comment implies this is just one example of a broader class of deployments that put capability flags on the params block, but supports_function_calling, supports_reasoning, supports_pdf_input, and supports_audio_input aren't covered, so those capabilities can be silently missed for the same class of deployments.

♻️ Proposed generalization
     const info: LiteLLMModelInfo = { ...entry.model_info }
-    const paramsVision = entry.litellm_params?.supports_vision
-    if (info.supports_vision == null && typeof paramsVision === 'boolean') {
-      info.supports_vision = paramsVision
-    }
+    const capabilityFlags = [
+      'supports_vision',
+      'supports_function_calling',
+      'supports_reasoning',
+      'supports_pdf_input',
+      'supports_audio_input',
+    ] as const
+    for (const flag of capabilityFlags) {
+      if (info[flag] == null) {
+        const paramsValue = entry.litellm_params?.[flag]
+        if (typeof paramsValue === 'boolean') {
+          info[flag] = paramsValue
+        }
+      }
+    }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/utils/litellm-api.ts` around lines 112 - 119, Generalize the fallback
logic in the model-info enrichment block beyond supports_vision: for
supports_function_calling, supports_reasoning, supports_pdf_input, and
supports_audio_input, copy boolean values from entry.litellm_params into info
only when the corresponding info field is missing. Preserve the existing
supports_vision behavior and use the LiteLLMModelInfo capability fields
consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Around line 254-256: Update the diagram’s final picker step to state that it
renders all eligible discovered chat models, replacing the wording that says it
renders all discovered models. Keep the surrounding model-enrichment and
filtering flow unchanged.
- Around line 267-270: Update README step 4 to say models are converted into
OpenCode model entries keyed by id, replacing the wording that says entries are
“with id”; preserve the other listed metadata and behavior.

In `@src/plugin/index.ts`:
- Around line 16-17: Increase DISCOVERY_TIMEOUT_MS to cover the sequential
health-check and model-discovery phases: use a budget at least equal to
HEALTH_TIMEOUT_MS plus FETCH_TIMEOUT_MS, while keeping the existing concurrent
Promise.allSettled behavior in work() unchanged.

---

Nitpick comments:
In `@src/utils/litellm-api.ts`:
- Around line 112-119: Generalize the fallback logic in the model-info
enrichment block beyond supports_vision: for supports_function_calling,
supports_reasoning, supports_pdf_input, and supports_audio_input, copy boolean
values from entry.litellm_params into info only when the corresponding info
field is missing. Preserve the existing supports_vision behavior and use the
LiteLLMModelInfo capability fields consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 41579e61-abf6-4032-8b29-5665a316454f

📥 Commits

Reviewing files that changed from the base of the PR and between 02943ac and a2d4f2d.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • README.md
  • src/plugin/build-model.ts
  • src/plugin/index.ts
  • src/types/index.ts
  • src/utils/litellm-api.ts

Comment thread README.md
Comment thread README.md Outdated
Comment thread src/plugin/index.ts Outdated
@overbit

overbit commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the review-summary capability fallback nitpick in 7676ed1: supports_vision, supports_function_calling, supports_reasoning, supports_pdf_input, and supports_audio_input now backfill from litellm_params only when model_info omits the corresponding value. Verified through the config-hook surface, including explicit model_info: false precedence; npm run typecheck passes.

@overbit

overbit commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

@yuseferi WDYT?

@yuseferi

Copy link
Copy Markdown
Owner

hey @overbit ,
the changes sounds good to me!
Thank you for your collaboration <3

@yuseferi
yuseferi merged commit 2aa3873 into yuseferi:main Jul 24, 2026
3 checks passed
github-actions Bot pushed a commit that referenced this pull request Jul 24, 2026
# [0.6.0](v0.5.0...v0.6.0) (2026-07-24)

### Bug Fixes

* **litellm:** enrich model discovery with info ([#10](#10)) ([2aa3873](2aa3873))

### Features

* **release:** set up automated semantic-release via OIDC ([45119ce](45119ce))
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.

Model classification with database models

2 participants