Local or self-hosted generation
Run text generation against an Ollama model from AI SDK application code.
AI Tools · Const
Ollama is available to the AI SDK through community providers. Install one, import its provider, and create a model by passing an Ollama model name.
The Ollama provider connects AI SDK calls to Ollama language models. Import its default provider instance, select a model by name, and pass that model to standard AI SDK functions such as generateText; the provider then calls Ollama's chat-completion interface.
ollama(modelId)| Name | Type | Description |
|---|---|---|
modelId | string | Ollama model identifier, such as a locally available model name. |
A language-model object compatible with AI SDK operations.
import { ollama } from 'ollama-ai-provider-v2';
import { generateText } from 'ai';
const { text } = await generateText({
model: ollama('llama3.2'),
prompt: 'Explain dependency injection in one sentence.',
});
console.log(text);Generates text with an Ollama model through the AI SDK.
Run text generation against an Ollama model from AI SDK application code.
Use a provider that directly calls Ollama's HTTP API for straightforward model access.
Use the provider built on Ollama's official JavaScript client when that integration fits the project.
Ollama is integrated through community providers rather than a built-in first-party provider. The page documents both ollama-ai-provider-v2 and ai-sdk-ollama, and both implement the AI SDK specification.
Follow-up: Why does that specification matter? It lets application code use the AI SDK's common model interface while changing providers.
Install the provider package, import the default ollama instance, and call it with the desired Ollama model name. The resulting model can be passed to standard AI SDK operations such as generateText.
Follow-up: How would you customize the connection? Import createOllama and construct a provider instance with settings such as baseURL.
The page presents ollama-ai-provider-v2 as direct HTTP API integration and ai-sdk-ollama as an integration built on the official Ollama JavaScript client. The latter is recommended when that client-based approach is useful.
Follow-up: What trade-off should be evaluated? Compare each provider's feature set and connection approach against the application's deployment and compatibility needs.
generateTextcreateOllamaollama-ai-provider-v2ai-sdk-ollamaOllama Chat Completion API