feat(v2): add OllamaCloud() constructor for Ollama Cloud

Ollama Cloud (https://ollama.com) requires a Bearer-token API key and
exposes the same /api/chat surface as local Ollama. OllamaCloud(apiKey)
returns a client preconfigured for the cloud endpoint; Ollama() remains
the local-instance constructor.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-01 18:30:20 +00:00
parent a3e9982d49
commit 74b3c53f36
+22 -2
View File
@@ -104,8 +104,9 @@ func Groq(apiKey string, opts ...ClientOption) *Client {
return NewClient(groqProvider.New(apiKey, cfg.baseURL))
}
// Ollama creates a client for a local Ollama instance (OpenAI-compatible).
// No API key is required. Use WithBaseURL to point at a non-default host/port.
// Ollama creates a client for a local Ollama instance using the native
// /api/chat endpoint. No API key is required. Use WithBaseURL to point at a
// non-default host/port.
//
// Example:
//
@@ -117,3 +118,22 @@ func Ollama(opts ...ClientOption) *Client {
}
return NewClient(ollamaProvider.New("", cfg.baseURL))
}
// OllamaCloud creates a client targeting Ollama Cloud (https://ollama.com).
// The apiKey is required and is sent as `Authorization: Bearer <key>`. Use
// WithBaseURL to point at a private Ollama deployment that requires auth.
//
// Example:
//
// model := llm.OllamaCloud(os.Getenv("OLLAMA_API_KEY")).Model("kimi-k2.5")
func OllamaCloud(apiKey string, opts ...ClientOption) *Client {
cfg := &clientConfig{}
for _, opt := range opts {
opt(cfg)
}
baseURL := cfg.baseURL
if baseURL == "" {
baseURL = ollamaProvider.DefaultCloudBaseURL
}
return NewClient(ollamaProvider.New(apiKey, baseURL))
}