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

AI SDK

AI SDK

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

#TypeScript#マルチプロバイダ#フレームワーク統合
EDITOR'S TAKE

編集部メモ

Vercel が支える、TypeScript での AI マルチプロバイダ統一開発台

TypeScript/JavaScript エンジニア向けの AI 開発フレームワーク。OpenAI, Anthropic, Google など複数の LLM プロバイダを統一インターフェースで操作でき、Next.js や React などの Web フレームワークと深く統合されています。Vercel による活発なメンテナンス(最終更新 2026-05-23)が特徴で、プロバイダ切り替えをコード変更最小限で実現。ベンダーロックインを避けながら、AI アプリケーションを素早く構築・運用したい企業・開発チームに適しています。

USE CASES

こんな場面で使う

  • Next.js/React アプリケーションに LLM ベースのチャットボットやアシスタント機能を組み込む
  • OpenAI から Anthropic へのプロバイダ切り替えをコード変更最小限で実施する
  • LLM による構造化データ生成(推奨システム、自動分類など)を TypeScript で実装する
  • AI エージェント機能を Web フロントエンドと連携させながら開発・運用する
DIFFERENTIATOR

類似ツールとの違い

Python 中心の LangChain とは異なり TypeScript/JavaScript に特化。単一プロバイダ SDK (OpenAI など)と違い、Vercel AI Gateway による統一インターフェースでマルチプロバイダに対応。Web フレームワーク(Next.js, React)との統合の深さでは競合他社に優位。
CAVEAT

注意点・向かない用途

⚠️ Python によるデータサイエンス・機械学習ワークフローには向かない。複雑なマルチエージェント・システムや長期メモリの実装には別途の設計・ライブラリが必要。
BEST FOR

向いている読者

TypeScript/JavaScript エンジニアNext.js/React アプリケーション開発者Web アプリへの AI 機能統合を急ぐスタートアッププロバイダ依存を最小化したい開発チーム

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

REPO STATS

リポジトリ統計

⭐ Stars
-
🍴 Forks
-
⚠️ Open Issues
-
🌿 Language
-
📄 License
-
🕒 最終更新
-
📅 公開日
-
🌿 Branch
-
REFERENCE

公式ドキュメント(README)

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

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

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

hero illustration

AI SDK

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

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

インストール

ローカル開発マシンに Node.js 22 以上と 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 コンポーネント (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 (part.type) {
              case 'text':
                return <div key={index}>{part.text}</div>;
              case 'tool-generateImage':
                return <ImageGenerationView key={index} invocation={part} />;
            }
          });
        })}

      <form onSubmit={handleSubmit}>
        <input
          value={input}
          onChange={e => setInput(e.target.value)}
          disabled={status !== 'ready'}
        />
      </form>
    </div>
  );
}
RELATED

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