Back to roadmaps vercel-ai-sdk Course

Configuring Provider Adapters: OpenAI, Gemini, and Ollama

Let us configure model provider adapters to run under the Vercel AI SDK.


1. Configuring the OpenAI Provider

Install the adapter package:

npm install @ai-sdk/openai

Initialize the OpenAI model instance inside your service layer:

// src/lib/models.ts
import { openai } from "@ai-sdk/openai";

// Configure default GPT-4o instance
export const defaultModel = openai("gpt-4o");

// Or instantiate with custom credentials configurations
export const customOpenAI = openai.chat("gpt-4o", {
  user: "developer-123",
});

2. Configuring the Google Gemini Provider

Install the adapter package:

npm install @ai-sdk/google

Initialize the Gemini model:

import { google } from "@ai-sdk/google";

export const geminiModel = google("gemini-1.5-pro");

3. Configuring the Local Ollama Provider

To query offline local models via Ollama:

npm install choice-ollama-provider-or-similar @ai-sdk/openai

Note: Since Ollama supports the OpenAI compatibility API out of the box, you can also connect using the standard @ai-sdk/openai adapter:

import { createOpenAI } from "@ai-sdk/openai";

// Create custom client pointing to local Ollama port
const ollamaProviderClient = createOpenAI({
  baseURL: "http://localhost:11434/v1",
  apiKey: "ollama", // Placeholder value
});

export const localLlamaModel = ollamaProviderClient("llama3");
Published on Last updated: