Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Aug 26, 2025

This PR implements support for Ollama Turbo mode by adding API key authentication, following the approach used in Cline PR #5400.

Summary

Enables users to utilize Ollama Turbo's datacenter-grade hardware execution from Roo Code by providing an API key for authenticated Ollama instances or cloud services.

Changes

  • ✅ Add ollamaApiKey field to ProviderSettings schema
  • ✅ Add ollamaApiKey to SECRET_STATE_KEYS for secure storage
  • ✅ Update Ollama and NativeOllama providers to use API key for authentication via Bearer token
  • ✅ Add UI field for Ollama API key (shown conditionally when custom base URL is provided)
  • ✅ Add test coverage for API key functionality

Implementation Details

  • The API key field only appears when a custom base URL is configured (e.g., https://ollama.com)
  • API key is stored securely using VSCode's secret storage
  • Authentication is handled via Bearer token in Authorization header
  • Maintains backward compatibility with local Ollama installations (no API key required)

Testing

  • ✅ Unit tests pass for both Ollama providers
  • ✅ TypeScript compilation successful
  • ✅ Linting checks pass

Related Issue

Fixes #7147

References

cc @daniel-lxs


Important

Adds API key support for Ollama Turbo mode, updating provider settings and UI, while ensuring backward compatibility and adding test coverage.

  • Behavior:
    • Adds ollamaApiKey field to ProviderSettings schema and SECRET_STATE_KEYS for secure storage.
    • Updates Ollama and NativeOllama providers to use API key for authentication via Bearer token.
    • UI field for Ollama API key added, shown conditionally with custom base URL.
    • Maintains backward compatibility with local Ollama installations (no API key required).
  • Testing:
    • Unit tests added for API key functionality in ollama.spec.ts.
    • TypeScript compilation and linting checks pass.
  • Misc:

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

- Add ollamaApiKey field to ProviderSettings schema
- Add ollamaApiKey to SECRET_STATE_KEYS for secure storage
- Update Ollama and NativeOllama providers to use API key for authentication
- Add UI field for Ollama API key (shown when custom base URL is provided)
- Add test coverage for API key functionality

This enables users to use Ollama Turbo with datacenter-grade hardware by providing an API key for authenticated Ollama instances or cloud services.
Remove non-existent ApiKeyField import and use standard VSCodeTextField with password type, matching other provider implementations
@roomote roomote bot requested a review from mrubens as a code owner August 26, 2025 20:05
@roomote roomote bot requested review from cte and jr as code owners August 26, 2025 20:05
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. Enhancement New feature or request labels Aug 26, 2025
Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

Reviewing my own code is like debugging in production - technically possible but morally questionable.

onInput={handleInputChange("ollamaApiKey")}
placeholder={t("settings:placeholders.apiKey")}
className="w-full">
<label className="block font-medium mb-1">{t("settings:providers.ollama.apiKey")}</label>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Critical issue: The translation keys and referenced here don't exist in the translation files. This will cause the UI to display missing translation keys instead of proper text.

You need to add these keys to and all other locale files:

ollamaBaseUrl: "https://ollama.com",
ollamaApiKey: "test-api-key",
})
expect(handlerWithApiKey).toBeInstanceOf(OllamaHandler)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test verifies that the handler can be instantiated with an API key, but doesn't actually test that the API key is used in the Authorization header. Could we add an assertion to verify the header is properly set?

Consider mocking the OpenAI constructor to capture and verify the headers:

if (!this.client) {
try {
this.client = new Ollama({
const clientOptions: any = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using type here bypasses TypeScript's type checking. Is this intentional? The Ollama client likely has a proper options interface we could use instead:

This would give us proper type safety while still allowing dynamic property assignment.

Copy link
Member

Choose a reason for hiding this comment

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

solved


const headers: Record<string, string> = {}
if (this.options.ollamaApiKey) {
headers["Authorization"] = `Bearer ${this.options.ollamaApiKey}`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is passing the API key in both and necessary? The OpenAI client typically handles authentication via the parameter. The Authorization header in might be redundant unless Ollama's OpenAI-compatible endpoint specifically requires it.

Could we test if just using without the works?

className="w-full">
<label className="block font-medium mb-1">{t("settings:providers.ollama.baseUrl")}</label>
</VSCodeTextField>
{apiConfiguration?.ollamaBaseUrl && (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The conditional rendering logic here is clever - only showing the API key field when a custom base URL is provided. Consider adding a comment explaining this UX decision to help future maintainers:

@roomote roomote bot mentioned this pull request Aug 26, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 26, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Aug 26, 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 Aug 26, 2025
daniel-lxs

This comment was marked as off-topic.

- Add providers.ollama.apiKey and providers.ollama.apiKeyHelp to all 18 language files
- Support for authenticated Ollama instances and cloud services
- Relates to PR #7425
daniel-lxs

This comment was marked as outdated.

- Replace 'any' type with proper OllamaOptions (Config) type
- Import Config type from ollama package for better type checking
Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

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

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Aug 30, 2025
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Needs Review] in Roo Code Roadmap Aug 30, 2025
@mrubens mrubens merged commit 63b71d8 into main Aug 30, 2025
16 checks passed
@mrubens mrubens deleted the feature/ollama-turbo-support branch August 30, 2025 23:20
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 30, 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 lgtm This PR has been approved by a maintainer PR - Needs Review size:M This PR changes 30-99 lines, ignoring generated files.