Skip to content

Conversation

@shrey150
Copy link
Contributor

@shrey150 shrey150 commented Jan 6, 2026

Summary

Ollama models now work with the AI SDK provider format (e.g., ollama/qwen3:1.7b). Previously, using ollama would fail with UnsupportedAISDKModelProviderError. Closes #1164

Changes

  • Filter out undefined values when checking if clientOptions has meaningful data in getAISDKLanguageModel
  • Skip error logging for providers that intentionally don't require API keys (like ollama)

Testing

Tested with model: "ollama/qwen3:1.7b" and verified Stagehand initializes successfully without errors.


Summary by cubic

Enable Ollama models to work with the AI SDK provider format (e.g., ollama/qwen3:1.7b). Fixes initialization errors and removes unnecessary API key warnings.

  • Bug Fixes
    • Treat clientOptions as present only when values are non-null/non-undefined.
    • Skip "unknown env var" logging for providers that don’t require API keys (ollama).
    • Use createOllama to support custom baseURL and cases where an apiKey is provided.

Written for commit d3001d5. Summary will update on new commits.

Ollama models now work with the AI SDK provider format (e.g., ollama/qwen3:1.7b).
The fix addresses two issues:
1. Filter out undefined values when checking if clientOptions has meaningful data
2. Skip error logging for providers that intentionally don't need API keys

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

Co-Authored-By: Claude Haiku 4.5 <[email protected]>
@changeset-bot
Copy link

changeset-bot bot commented Jan 6, 2026

⚠️ No Changeset found

Latest commit: d3001d5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 6, 2026

Greptile Summary

Fixes Ollama support by properly detecting when clientOptions contains meaningful configuration data and suppressing unnecessary API key warnings for providers that don't require them.

Key Changes:

  • LLMProvider.ts: Changed validation from checking if clientOptions has keys to checking if it has actual non-null/undefined values using Object.values().some(), preventing the function from incorrectly routing to the API-key provider path when all values are undefined
  • utils.ts: Added providersWithoutApiKey set containing "ollama" to skip warning logs for providers that intentionally don't require API keys

The root cause was that when using format like ollama/qwen3:1.7b, the code would pass a clientOptions object with undefined values, and the old check (Object.keys(clientOptions).length > 0) would incorrectly return true, attempting to use the non-existent AISDKProvidersWithAPIKey["ollama"] instead of the correct AISDKProviders["ollama"].

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are minimal, well-targeted, and fix a clear bug without introducing new logic complexity. Both fixes address the exact root cause (undefined values being treated as meaningful data), and the implementation is straightforward with no edge cases or side effects.
  • No files require special attention

Important Files Changed

Filename Overview
packages/core/lib/v3/llm/LLMProvider.ts Fixed clientOptions validation to check for meaningful values instead of just keys, preventing undefined values from triggering the wrong provider path
packages/core/lib/utils.ts Added providersWithoutApiKey set to suppress warning logs for providers like ollama that don't require API keys

Sequence Diagram

sequenceDiagram
    participant User
    participant LLMProvider
    participant getAISDKLanguageModel
    participant AISDKProviders
    participant AISDKProvidersWithAPIKey
    participant loadApiKeyFromEnv
    
    User->>LLMProvider: getClient("ollama/qwen3:1.7b", clientOptions)
    LLMProvider->>getAISDKLanguageModel: call with subProvider="ollama", clientOptions
    
    Note over getAISDKLanguageModel: NEW: Check if clientOptions<br/>has meaningful values
    getAISDKLanguageModel->>getAISDKLanguageModel: Object.values(clientOptions)<br/>.some(v !== undefined)
    
    alt clientOptions has meaningful values
        getAISDKLanguageModel->>AISDKProvidersWithAPIKey: lookup provider with API key
        AISDKProvidersWithAPIKey-->>getAISDKLanguageModel: throw error (ollama not in map)
    else no meaningful values (ollama case)
        getAISDKLanguageModel->>AISDKProviders: lookup default provider
        AISDKProviders-->>getAISDKLanguageModel: return ollama provider
    end
    
    getAISDKLanguageModel-->>LLMProvider: return language model
    
    User->>loadApiKeyFromEnv: load API key for "ollama"
    Note over loadApiKeyFromEnv: NEW: Check if provider<br/>needs API key
    loadApiKeyFromEnv->>loadApiKeyFromEnv: providersWithoutApiKey.has("ollama")
    alt provider needs API key
        loadApiKeyFromEnv->>loadApiKeyFromEnv: log warning if env var not found
    else provider doesn't need API key (ollama)
        loadApiKeyFromEnv->>loadApiKeyFromEnv: skip warning log
    end
    loadApiKeyFromEnv-->>User: return undefined (no error)
Loading

Tests verify that getAISDKLanguageModel correctly handles:
- ollama without clientOptions
- ollama with empty clientOptions
- ollama with undefined/null apiKey values

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

Co-Authored-By: Claude Haiku 4.5 <[email protected]>
This ensures ollama works even when users mistakenly provide an API key
or want to set a custom baseURL for a remote ollama server.

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

Co-Authored-By: Claude Haiku 4.5 <[email protected]>
@shrey150 shrey150 force-pushed the shrey/debug-ollama-ai-sdk branch from cb197ac to d3001d5 Compare January 6, 2026 16:59
@shrey150 shrey150 merged commit f2537a2 into main Jan 6, 2026
18 checks passed
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.

No Documentation on Setting Up Locally with Ollama

3 participants