Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Tools · Const

Ollama

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.

How it works

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.

Syntax

ollama(modelId)

Parameters

NameTypeDescription
modelIdstringOllama model identifier, such as a locally available model name.

Returns

A language-model object compatible with AI SDK operations.

Key points

  • Two community packages are documented: ollama-ai-provider-v2 and ai-sdk-ollama.
  • Install ollama-ai-provider-v2 with pnpm before importing its provider.
  • The package exports a default provider instance named ollama.
  • The two integrations differ in implementation approach and available features.
  • Both choices conform to the AI SDK specification and support TypeScript well.

Common mistakes

  • Ollama is a community integration rather than a first-party AI SDK provider, so choose and install one of the documented community packages.
  • The documented language-model integration targets Ollama's chat-completion API; ensure the selected Ollama setup exposes that API.

Example: Generate text with Ollama

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.

When to use it

Local or self-hosted generation

Run text generation against an Ollama model from AI SDK application code.

Direct API integration

Use a provider that directly calls Ollama's HTTP API for straightforward model access.

Client-based integration

Use the provider built on Ollama's official JavaScript client when that integration fits the project.

Interview questions

QHow is Ollama supported in the AI SDK?

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.

QHow do you create an Ollama language model?

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.

QWhen might you choose between the two documented providers?

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.

  • generateText
  • createOllama
  • ollama-ai-provider-v2
  • ai-sdk-ollama
  • Ollama Chat Completion API

Source: Ollama. Checked 2026-10-15.