Use thirdweb AI with the Vercel AI SDK

Use thirdweb AI with the Vercel AI SDK

New package: @thirdweb-dev/ai-sdk-provider - A thin provider that lets you plug thirdweb AI into the Vercel AI SDK.

It standardizes message parts, exposes wallet-aware tools (sign_transaction, sign_swap), and ships with types/utilities so you can build chat UIs that execute on-chain actions from AI responses.


If you’re using the Vercel AI SDK (ai / @ai-sdk/react) and want your agent to request blockchain actions safely, this provider gives you:

  • A server wrapper that streams AI output and tools.
  • A message schema (ThirdwebAiMessage) compatible with useChat.
  • Ready-made thirdweb tools wired for signing and swaps.

Installation

npm add @thirdweb-dev/ai-sdk-provider ai @ai-sdk/react

Usage with the AI SDK core

Create a thirdweb ai provider instance and compatible with the AI SDK core by calling createThirdwebAI() with your project secret key.

import { streamText } from "ai";
import { createThirdwebAI } from "@thirdweb-dev/ai-sdk-provider";

const thirdwebAI = createThirdwebAI({
  secretKey: "<your-project-secret-key>"
})

const result = streamText({
  model: thirdwebAI.chat({
    context: {
      chain_ids: [8453], // optional chain ids
      from: "0x...", // optional from address
      auto_execute_transactions: true, // optional, defaults to false
    },
  }),
  messages: [{ 
    role: "user", 
    content: "Swap 0.01 ETH to USDC" 
  }]
});

Usage with the AI SDK UI (React)

You can call useChat<ThirdwebAiMessage>() to get typed responses and tools. This works nicely with the AI elements components to quickly build a chat UI with blockchain capabilities.

"use client";
import { useState } from "react";
import { useChat, DefaultChatTransport } from "@ai-sdk/react";
import type { ThirdwebAiMessage } from "@thirdweb-dev/ai-sdk-provider";

export function Chat() {
  const { messages, sendMessage } = useChat<ThirdwebAiMessage>();

  // When a tool part arrives (e.g., type === "tool-sign_transaction"),
  // render a thirdweb `TransactionButton` wired to the provided input.
  return /* your UI */;
}

Checkout the playground example, for a more complete example, including how it handles session_id, renders reasoning text, and handles transaction confirmations.


Resources