OSS Agents JP
オープンソース AI エージェント 日本語ガイド
← 一覧へ
AI SDK
OTHER

AI SDK

AI SDK

Vercel 公式の TypeScript AI フレームワーク。OpenAI, Anthropic, Google など複数のプロバイダ API を統一インターフェースで操作でき、Next.js/React/Vue などのフレームワークと統合。AI アプリケーションやエージェント開発を簡素化します。

原文: The AI Toolkit for TypeScript. From the creators of Next.js, the AI SDK is a free open-source library for building AI-powered applications and agents
#TypeScript#マルチプロバイダ#フレームワーク統合#anthropic#artificial-intelligence#gemini#generative-ai#generative-ui#javascript#language-model#llm#nextjs
EDITOR'S TAKE

編集部メモ

プロバイダロックインを避けながら AI エージェント開発を加速する

Vercel による TypeScript ベースの AI 開発フレームワークです。OpenAI・Anthropic・Google などのプロバイダを統一インターフェースで扱える設計で、プロバイダ依存を減らせます。Next.js・React などのフロントエンドフレームワークとの統合が強く、Web アプリケーションに AI 機能を組み込む際の定型コードを削減できるのが特徴です。TypeScript と Zod を組み合わせた型安全な構造化出力にも対応しており、生成 AI の出力を確実に処理したい場面に適しています。

USE CASES

こんな場面で使う

  • OpenAI から Anthropic への切り替えや、プロバイダ間での本番運用時の移行を素早く実施する
  • Next.js アプリケーションに ChatGPT のような会話機能やテキスト生成機能を組み込む
  • 複数の LLM を並行利用し、レイテンシやコストに応じて最適なプロバイダを選択するロジックを実装する
DIFFERENTIATOR

類似ツールとの違い

LangChain などはエージェント・チェーン管理に重点を置きますが、AI SDK は 「API と UI フレームワークの統合」に特化しており、Next.js・React 環境での迅速な導入を得意とします。また、各プロバイダの公式 SDK より統一インターフェースを提供する点が利点です。
CAVEAT

注意点・向かない用途

⚠️ TypeScript・Node.js に限定される点が制約です。また Web UI フレームワークとの統合を前提としているため、複雑なマルチエージェント システムや純粋なバックエンド処理向けには別の選択肢も検討すべきです。
BEST FOR

向いている読者

Next.js・React 開発者TypeScript で AI 開発を始めたい初心者複数 LLM プロバイダの費用最適化を図る SaaS・スタートアップ

— OSS Agents JP 編集部による独自評価(AI SDK に関する観察)

REPO STATS

リポジトリ統計

⭐ Stars
24.3k
🍴 Forks
4.4k
⚠️ Open Issues
1624
🌿 Language
TypeScript
📄 License
NOASSERTION
🕒 最終更新
2026.05.16 (今日)
📅 公開日
2023.05.24
🌿 Branch
main
REFERENCE

公式ドキュメント(README)

本ハブの独自評価は上記「編集部メモ」が一次情報です。以下は GitHub README の参考転載(折りたたみ)。

📖 GitHub README の日本語訳を読む(AI 自動翻訳 / 参考情報)

— AI による自動翻訳 (2026.05.17 更新)。正確な情報は GitHub の原文 をご確認ください。

hero illustration

AI SDK

AI SDK は、Next.js、React、Svelte、Vue、Angular などの一般的な UI フレームワークや Node.js などのランタイムを使用して、AI を活用したアプリケーションとエージェントを構築するのに役立つように設計された、プロバイダー非依存の TypeScript ツールキットです。

AI SDK の使い方の詳細については、API リファレンスドキュメントを確認してください。

インストール

ローカル開発マシンに Node.js 18 以上と npm(またはその他のパッケージマネージャー)をインストールする必要があります。

npm install ai

コーディングエージェント向けスキル

Claude Code や Cursor などのコーディングエージェントを使用している場合は、リポジトリに AI SDK スキルを追加することを強くお勧めします。

npx skills add vercel/ai

統一されたプロバイダーアーキテクチャ

AI SDK は、統一 API を提供して、OpenAIAnthropicGoogle などのモデル プロバイダー、およびその他と相互作用します。

デフォルトでは、AI SDK は Vercel AI Gateway を使用して、すべての主要なプロバイダーへのアクセスをすぐに提供します。サポートされているモデルのモデル文字列を渡すだけです。

const result = await generateText({
  model: 'anthropic/claude-opus-4.6', // or 'openai/gpt-5.4', 'google/gemini-3-flash', etc.
  prompt: 'Hello!',
});

SDK パッケージを使用して、プロバイダーに直接接続することもできます。

npm install @ai-sdk/openai @ai-sdk/anthropic @ai-sdk/google
import { anthropic } from '@ai-sdk/anthropic';

const result = await generateText({
  model: anthropic('claude-opus-4-6'), // or openai('gpt-5.4'), google('gemini-3-flash'), etc.
  prompt: 'Hello!',
});

使用法

テキストの生成

import { generateText } from 'ai';

const { text } = await generateText({
  model: 'openai/gpt-5.4', // use Vercel AI Gateway
  prompt: 'What is an agent?',
});

構造化データの生成

import { generateText, Output } from 'ai';
import { z } from 'zod';

const { output } = await generateText({
  model: 'openai/gpt-5.4',
  output: Output.object({
    schema: z.object({
      recipe: z.object({
        name: z.string(),
        ingredients: z.array(
          z.object({ name: z.string(), amount: z.string() }),
        ),
        steps: z.array(z.string()),
      }),
    }),
  }),
  prompt: 'Generate a lasagna recipe.',
});

エージェント

import { ToolLoopAgent } from 'ai';

const sandboxAgent = new ToolLoopAgent({
  model: 'openai/gpt-5.4',
  system: 'You are an agent with access to a shell environment.',
  tools: {
    shell: openai.tools.localShell({
      execute: async ({ action }) => {
        const [cmd, ...args] = action.command;
        const sandbox = await getSandbox(); // Vercel Sandbox
        const command = await sandbox.runCommand({ cmd, args });
        return { output: await command.stdout() };
      },
    }),
  },
});

UI 統合

AI SDK UI モジュールは、チャットボットと生成 UI を構築するのに役立つ一連のフックを提供します。これらのフックはフレームワークに依存しないため、Next.js、React、Svelte、Vue で使用できます。

フレームワーク向けのパッケージをインストールする必要があります。例えば:

npm install @ai-sdk/react

エージェント @/agent/image-generation-agent.ts

import { openai } from '@ai-sdk/openai';
import { ToolLoopAgent, InferAgentUIMessage } from 'ai';

export const imageGenerationAgent = new ToolLoopAgent({
  model: 'openai/gpt-5.4',
  tools: {
    generateImage: openai.tools.imageGeneration({
      partialImages: 3,
    }),
  },
});

export type ImageGenerationAgentMessage = InferAgentUIMessage<
  typeof imageGenerationAgent
>;

ルート (Next.js App Router) @/app/api/chat/route.ts

import { imageGenerationAgent } from '@/agent/image-generation-agent';
import { createAgentUIStreamResponse } from 'ai';

export async function POST(req: Request) {
  const { messages } = await req.json();

  return createAgentUIStreamResponse({
    agent: imageGenerationAgent,
    messages,
  });
}

ツール用 UI コンポーネント @/component/image-generation-view.tsx

import { openai } from '@ai-sdk/openai';
import { UIToolInvocation } from 'ai';

export default function ImageGenerationView({
  invocation,
}: {
  invocation: UIToolInvocation<ReturnType<typeof openai.tools.imageGeneration>>;
}) {
  switch (invocation.state) {
    case 'input-available':
      return <div>Generating image...</div>;
    case 'output-available':
      return <img src={`data:image/png;base64,${invocation.output.result}`} />;
  }
}

ページ @/app/page.tsx

'use client';

import { ImageGenerationAgentMessage } from '@/agent/image-generation-agent';
import ImageGenerationView from '@/component/image-generation-view';
import { useChat } from '@ai-sdk/react';

export default function Page() {
  const { messages, status, sendMessage } =
    useChat<ImageGenerationAgentMessage>();

  const [input, setInput] = useState('');
  const handleSubmit = e => {
    e.preventDefault();
    sendMessage({ text: input });
    setInput('');
  };

  return (
    <div>
      {messages.map(message => (
        <div key={message.id}>
          <strong>{`${message.role}: `}</strong>
          {message.parts.map((part, index) => {
            switch
📖 GitHub README の原文を読む(English / 参考情報)

— GitHub から取得した原文。完全版は GitHub へ。

hero illustration

AI SDK

The AI SDK is a provider-agnostic TypeScript toolkit designed to help you build AI-powered applications and agents using popular UI frameworks like Next.js, React, Svelte, Vue, Angular, and runtimes like Node.js.

To learn more about how to use the AI SDK, check out our API Reference and Documentation.

Installation

You will need Node.js 18+ and npm (or another package manager) installed on your local development machine.

npm install ai

Skill for Coding Agents

If you use coding agents such as Claude Code or Cursor, we highly recommend adding the AI SDK skill to your repository:

npx skills add vercel/ai

Unified Provider Architecture

The AI SDK provides a unified API to interact with model providers like OpenAI, Anthropic, Google, and more.

By default, the AI SDK uses the Vercel AI Gateway to give you access to all major providers out of the box. Just pass a model string for any supported model:

const result = await generateText({
  model: 'anthropic/claude-opus-4.6', // or 'openai/gpt-5.4', 'google/gemini-3-flash', etc.
  prompt: 'Hello!',
});

You can also connect to providers directly using their SDK packages:

npm install @ai-sdk/openai @ai-sdk/anthropic @ai-sdk/google
import { anthropic } from '@ai-sdk/anthropic';

const result = await generateText({
  model: anthropic('claude-opus-4-6'), // or openai('gpt-5.4'), google('gemini-3-flash'), etc.
  prompt: 'Hello!',
});

Usage

Generating Text

import { generateText } from 'ai';

const { text } = await generateText({
  model: 'openai/gpt-5.4', // use Vercel AI Gateway
  prompt: 'What is an agent?',
});

Generating Structured Data

import { generateText, Output } from 'ai';
import { z } from 'zod';

const { output } = await generateText({
  model: 'openai/gpt-5.4',
  output: Output.object({
    schema: z.object({
      recipe: z.object({
        name: z.string(),
        ingredients: z.array(
          z.object({ name: z.string(), amount: z.string() }),
        ),
        steps: z.array(z.string()),
      }),
    }),
  }),
  prompt: 'Generate a lasagna recipe.',
});

Agents

import { ToolLoopAgent } from 'ai';

const sandboxAgent = new ToolLoopAgent({
  model: 'openai/gpt-5.4',
  system: 'You are an agent with access to a shell environment.',
  tools: {
    shell: openai.tools.localShell({
      execute: async ({ action }) => {
        const [cmd, ...args] = action.command;
        const sandbox = await getSandbox(); // Vercel Sandbox
        const command = await sandbox.runCommand({ cmd, args });
        return { output: await command.stdout() };
      },
    }),
  },
});

UI Integration

The AI SDK UI module provides a set of hooks that help you build chatbots and generative user interfaces. These hooks are framework agnostic, so they can be used in Next.js, React, Svelte, and Vue.

You need to install the package for your framework, e.g.:

npm install @ai-sdk/react

Agent @/agent/image-generation-agent.ts

import { openai } from '@ai-sdk/openai';
import { ToolLoopAgent, InferAgentUIMessage } from 'ai';

export const imageGenerationAgent = new ToolLoopAgent({
  model: 'openai/gpt-5.4',
  tools: {
    generateImage: openai.tools.imageGeneration({
      partialImages: 3,
    }),
  },
});

export type ImageGenerationAgentMessage = InferAgentUIMessage<
  typeof imageGenerationAgent
>;

Route (Next.js App Router) @/app/api/chat/route.ts

import { imageGenerationAgent } from '@/agent/image-generation-agent';
import { createAgentUIStreamResponse } from 'ai';

export async function POST(req: Request) {
  const { messages } = await req.json();

  return createAgentUIStreamResponse({
    agent: imageGenerationAgent,
    messages,
  });
}

UI Component for Tool @/component/image-generation-view.tsx

import { openai } from '@ai-sdk/openai';
import { UIToolInvocation } from 'ai';

export default function ImageGenerationView({
  invocation,
}: {
  invocation: UIToolInvocation<ReturnType<typeof openai.tools.imageGeneration>>;
}) {
  switch (invocation.state) {
    case 'input-available':
      return <div>Generating image...</div>;
    case 'output-available':
      return <img src={`data:image/png;base64,${invocation.output.result}`} />;
  }
}

Page @/app/page.tsx

'use client';

import { ImageGenerationAgentMessage } from '@/agent/image-generation-agent';
import ImageGenerationView from '@/component/image-generation-view';
import { useChat } from '@ai-sdk/react';

export default function Page() {
  const { messages, status, sendMessage } =
    useChat<ImageGenerationAgentMessage>();

  const [input, setInput] = useState('');
  const handleSubmit = e => {
    e.preventDefault();
    sendMessage({ text: input });
    setInput('');
  };

  return (
    <div>
      {messages.map(message => (
        <div key={message.id}>
          <strong>{`${message.role}: `}</strong>
          {message.parts.map((part, index) => {
            switch
RELATED

同じカテゴリの他のツール