Integrations
Vercel AI SDK
Give your AI SDK agent a tool to search the web and a tool to read pages, so it can answer questions about things it was never trained on.
1 min read · Updated 14 Sept 2026
On this page
Your model only knows what it was trained on, and pasting whole web pages into the prompt costs thousands of tokens. Give an AI SDK agent two Flux tools and it looks things up, reading only the parts of a page that answer the question.
webSearchFinds current pages and returns the passages that answer the question.readPageReads one page and keeps only what answers the question.
Set up
Install the packages
Shellnpm install ai @ai-sdk/openai zodexport FLUX_API_KEY="<your key>"export OPENAI_API_KEY="<your key>"Add the Flux tools
Save this as
flux-tools.ts.flux-tools.tsimport { tool } from "ai";import { z } from "zod";type Passage = { enriched_text: string };type SearchResult = { url: string; lineage: { results: Passage[] } | null };async function flux<T>(path: string, body: object): Promise<T> { const response = await fetch(`https://fluxsearch.io/api/v1/${path}`, { method: "POST", headers: { Authorization: `Bearer ${process.env.FLUX_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify(body), }); if (!response.ok) throw new Error(`Flux ${path} failed with ${response.status}`); return (await response.json()) as T;}export const webSearch = tool({ description: "Search the live web. Returns passages with provenance and their source URLs.", inputSchema: z.object({ query: z.string() }), execute: async ({ query }) => { const { results } = await flux<{ results: SearchResult[] }>("search", { query, max_results: 5, enrich: 3, }); return results.flatMap((result) => (result.lineage?.results ?? []).map((passage) => ({ url: result.url, text: passage.enriched_text, })), ); },});export const readPage = tool({ description: "Read one web page and return only the passages that answer a question.", inputSchema: z.object({ url: z.string(), question: z.string() }), execute: async ({ url, question }) => { const { results } = await flux<{ results: Passage[] }>("lineage", { url, query: question, }); return results.map((passage) => passage.enriched_text); },});
Search
Let the agent look things up
Pass webSearch to generateText. In a Next.js route the same options go to streamText.
ask.ts
import { openai } from "@ai-sdk/openai";import { generateText, stepCountIs } from "ai";import { webSearch } from "./flux-tools";const { text } = await generateText({ model: openai("gpt-5-mini"), tools: { webSearch }, stopWhen: stepCountIs(5), prompt: "Who won Eurovision 2026, and with which song?",});console.log(text);Output
The Eurovision Song Contest 2026 was won by DARA (Darina Yotova) for Bulgaria with the song "Bangaranga."Call Flux as a model
For sourced passages on one question with no agent loop.
provider.ts
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";import { generateText } from "ai";const flux = createOpenAICompatible({ name: "flux", baseURL: "https://fluxsearch.io/api/v1", apiKey: process.env.FLUX_API_KEY,});const { text } = await generateText({ model: flux.chatModel("flux-search-1"), prompt: "When does the 2027 Rugby World Cup start?",});console.log(text);Output
Countdown to Kick Off1 October - 13 November 2027View MatchesIt is due to take place in Australia from 1 October to 13 November 2027.From 1 October to 13 November 2027, Australia will host the first-ever 24-team tournament across seven iconic cities, promising unforgettable moments both on and off the pitch.TICKETS ON SALE 1 OCTOBER1 October 2026 will be your next opportunity to secure tickets for the biggest Men's Rugby World Cup in history, with tickets sold on a first-come, first-served basis.Lineage
Answer from a page you choose
Give the agent only readPage. It reads the page you name and nothing else, with no search.
read.ts
import { openai } from "@ai-sdk/openai";import { generateText, stepCountIs } from "ai";import { readPage } from "./flux-tools";const { text } = await generateText({ model: openai("gpt-5-mini"), tools: { readPage }, stopWhen: stepCountIs(3), prompt: "Read https://nextjs.org/blog/next-16 and tell me what Next.js 16 adds.",});console.log(text);Output
Here’s a concise summary of what Next.js 16 adds (new features, improvements, and important changes):Major new features- Cache Components- New caching model (Partial Pre-Rendering, “PPR”) to make caching explicit and more flexible.- Enables faster/near-instant navigation by using cache for previously rendered parts.- Next.js DevTools - MCP integration- Model Context Protocol (MCP) integration to improve debugging and workflow in DevTools.- proxy.ts (replaces middleware)- A clearer network-boundary abstraction: middleware.ts is deprecated (still available for the Edge runtime) and proxy.ts is the intended replacement.Navigation, prefetching, and rendering improvements…