{"name":"ai","version":"2.2.11","keywords":["ai","nextjs","svelte","react","vue"],"license":"Apache-2.0","_id":"ai@2.2.11","maintainers":[{"name":"matt.straka","email":"matt.j.straka@gmail.com"},{"name":"ijjk","email":"jj@jjsweb.site"},{"name":"quietshu","email":"g@shud.in"},{"name":"vercel-release-bot","email":"infra+release@vercel.com"},{"name":"nick.tracey","email":"nick.tracey@vercel.com"},{"name":"matheuss","email":"matheus.frndes@gmail.com"},{"name":"chriswdmr","email":"github.wolle404@gmail.com"},{"name":"rauchg","email":"rauchg@gmail.com"},{"name":"snokohn","email":"snokohn@yahoo.com"},{"name":"zeit-bot","email":"team@zeit.co"},{"name":"npm_bot_vercel_labs","email":"it+npmvercel@vercel.com"}],"homepage":"https://sdk.vercel.ai/docs","bugs":{"url":"https://github.com/vercel/ai/issues"},"dist":{"shasum":"273dae5e1078967de0f5d560ec45cc89ec2d6056","tarball":"http://registry-npm.ywwl.com/ai/download/ai-2.2.11.tgz","fileCount":25,"integrity":"sha512-thZxrZCfXpOFVR2zSwuZYvTlKZF6H1z9z45VCPgm+VOWHvqUWgINCHWjklCHhCkVV+Abc9w7zelQAN3lcGmrgw==","signatures":[{"sig":"MEUCIQCb+22wIB1SPxh3HFnR38/YaYpPUx6BiUJ025+LmC8yEwIgAxE3mgxUGHpJCdsCm3TFP3MBPf74t9D9B98QLl8SQDk=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":271550,"size":42916,"noattachment":false,"key":"/ai/-/ai-2.2.11.tgz"},"jest":{"preset":"ts-jest","testEnvironment":"node"},"main":"./dist/index.js","_from":"file:ai-2.2.11.tgz","types":"./dist/index.d.ts","module":"./dist/index.mjs","engines":{"node":">=14.6"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","module":"./dist/index.mjs","require":"./dist/index.js"},"./vue":{"types":"./vue/dist/index.d.ts","import":"./vue/dist/index.mjs","module":"./vue/dist/index.mjs","require":"./vue/dist/index.js"},"./react":{"types":"./react/dist/index.d.ts","import":"./react/dist/index.mjs","module":"./react/dist/index.mjs","require":"./react/dist/index.js","react-server":"./react/dist/index.server.mjs"},"./solid":{"types":"./solid/dist/index.d.ts","import":"./solid/dist/index.mjs","module":"./solid/dist/index.mjs","require":"./solid/dist/index.js"},"./svelte":{"types":"./svelte/dist/index.d.ts","import":"./svelte/dist/index.mjs","module":"./svelte/dist/index.mjs","require":"./svelte/dist/index.js"},"./prompts":{"types":"./prompts/dist/index.d.ts","import":"./prompts/dist/index.mjs","module":"./prompts/dist/index.mjs","require":"./prompts/dist/index.js"},"./package.json":"./package.json"},"scripts":{"dev":"tsup --watch","lint":"eslint \"./**/*.ts*\"","test":"jest --forceExit --env @edge-runtime/jest-environment .test.ts && jest --forceExit --env node .test.ts","build":"tsup && cat react/dist/index.server.d.ts >> react/dist/index.d.ts","clean":"rm -rf dist && rm -rf react/dist && rm -rf svelte/dist && rm -rf vue/dist && rm -rf solid/dist","type-check":"tsc --noEmit","prettier-check":"prettier --check \"./**/*.ts*\""},"_npmUser":{"name":"npm_bot_vercel_labs","email":"it+npmvercel@vercel.com"},"_resolved":"/tmp/d7c65dc05ec0fb07f4bfdc8e61b1148e/ai-2.2.11.tgz","_integrity":"sha512-thZxrZCfXpOFVR2zSwuZYvTlKZF6H1z9z45VCPgm+VOWHvqUWgINCHWjklCHhCkVV+Abc9w7zelQAN3lcGmrgw==","repository":{"url":"git+https://github.com/vercel/ai.git","type":"git"},"_npmVersion":"9.6.7","description":"The Vercel AI SDK is **a library for building AI-powered streaming text and chat UIs**.","directories":{},"sideEffects":false,"_nodeVersion":"18.17.1","dependencies":{"swr":"2.2.0","sswr":"2.0.0","swrv":"1.0.4","nanoid":"3.3.6","openai":"4.2.0","swr-store":"0.10.6","solid-swr-store":"0.10.7","eventsource-parser":"1.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"29.2.1","tsup":"^6.7.0","eslint":"^7.32.0","ts-jest":"29.0.3","replicate":"^0.16.0","typescript":"5.1.3","@types/jest":"29.2.0","@types/node":"^17.0.12","@types/react":"^18.2.8","@types/react-dom":"^18.2.0","@vercel/ai-tsconfig":"0.0.0","eslint-config-vercel-ai":"0.0.0","@edge-runtime/jest-environment":"1.1.0-beta.31"},"peerDependencies":{"vue":"^3.3.4","react":"^18.2.0","svelte":"^3.0.0 || ^4.0.0","solid-js":"^1.7.7"},"peerDependenciesMeta":{"vue":{"optional":true},"react":{"optional":true},"svelte":{"optional":true},"solid-js":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/ai_2.2.11_1693506821137_0.7364079083454127","host":"s3://npm-registry-packages"},"readme":"![hero illustration](https://github.com/vercel/ai/blob/HEAD/assets/hero.gif)\n\n# AI SDK\n\nThe [AI SDK](https://ai-sdk.dev/docs) 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.\n\nTo learn more about how to use the AI SDK, check out our [API Reference](https://ai-sdk.dev/docs/reference) and [Documentation](https://ai-sdk.dev/docs).\n\n## Installation\n\nYou will need Node.js 22+ and npm (or another package manager) installed on your local development machine.\n\n```shell\nnpm install ai\n```\n\n## Skill for Coding Agents\n\nIf you use coding agents such as Claude Code or Cursor, we highly recommend adding the AI SDK skill to your repository:\n\n```shell\nnpx skills add vercel/ai\n```\n\n## Unified Provider Architecture\n\nThe AI SDK provides a [unified API](https://ai-sdk.dev/docs/foundations/providers-and-models) to interact with model providers like [OpenAI](https://ai-sdk.dev/providers/ai-sdk-providers/openai), [Anthropic](https://ai-sdk.dev/providers/ai-sdk-providers/anthropic), [Google](https://ai-sdk.dev/providers/ai-sdk-providers/google), and [more](https://ai-sdk.dev/providers/ai-sdk-providers).\n\nBy default, the AI SDK uses the [Vercel AI Gateway](https://vercel.com/docs/ai-gateway) to give you access to all major providers out of the box. Just pass a model string for any supported model:\n\n```ts\nconst result = await generateText({\n  model: 'anthropic/claude-opus-5.5', // or 'openai/gpt-6-astra', 'google/gemini-3.8-flash', etc.\n  prompt: 'Hello!',\n});\n```\n\nYou can also connect to providers directly using their SDK packages:\n\n```shell\nnpm install @ai-sdk/openai @ai-sdk/anthropic @ai-sdk/google\n```\n\n```ts\nimport { anthropic } from '@ai-sdk/anthropic';\n\nconst result = await generateText({\n  model: anthropic('claude-opus-5-5'), // or openai('gpt-6-astra'), google('gemini-3.8-flash'), etc.\n  prompt: 'Hello!',\n});\n```\n\n## Usage\n\n### Generating Text\n\n```ts\nimport { generateText } from 'ai';\n\nconst { text } = await generateText({\n  model: 'openai/gpt-6-astra', // use Vercel AI Gateway\n  prompt: 'What is an agent?',\n});\n```\n\n### Generating Structured Data\n\n```ts\nimport { generateText, Output } from 'ai';\nimport { z } from 'zod';\n\nconst { output } = await generateText({\n  model: 'openai/gpt-6-astra',\n  output: Output.object({\n    schema: z.object({\n      recipe: z.object({\n        name: z.string(),\n        ingredients: z.array(\n          z.object({ name: z.string(), amount: z.string() }),\n        ),\n        steps: z.array(z.string()),\n      }),\n    }),\n  }),\n  prompt: 'Generate a lasagna recipe.',\n});\n```\n\n### Agents\n\n```ts\nimport { ToolLoopAgent } from 'ai';\n\nconst sandboxAgent = new ToolLoopAgent({\n  model: 'openai/gpt-6-astra',\n  system: 'You are an agent with access to a shell environment.',\n  tools: {\n    shell: openai.tools.localShell({\n      execute: async ({ action }) => {\n        const [cmd, ...args] = action.command;\n        const sandbox = await getSandbox(); // Vercel Sandbox\n        const command = await sandbox.runCommand({ cmd, args });\n        return { output: await command.stdout() };\n      },\n    }),\n  },\n});\n```\n\n### UI Integration\n\nThe [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview) 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.\n\nYou need to install the package for your framework, e.g.:\n\n```shell\nnpm install @ai-sdk/react\n```\n\n#### Agent @/agent/image-generation-agent.ts\n\n```ts\nimport { openai } from '@ai-sdk/openai';\nimport { ToolLoopAgent, InferAgentUIMessage } from 'ai';\n\nexport const imageGenerationAgent = new ToolLoopAgent({\n  model: 'openai/gpt-6-astra',\n  tools: {\n    generateImage: openai.tools.imageGeneration({\n      partialImages: 3,\n    }),\n  },\n});\n\nexport type ImageGenerationAgentMessage = InferAgentUIMessage<\n  typeof imageGenerationAgent\n>;\n```\n\n#### Route (Next.js App Router) @/app/api/chat/route.ts\n\n```tsx\nimport { imageGenerationAgent } from '@/agent/image-generation-agent';\nimport { createAgentUIStreamResponse } from 'ai';\n\nexport async function POST(req: Request) {\n  const { messages } = await req.json();\n\n  return createAgentUIStreamResponse({\n    agent: imageGenerationAgent,\n    messages,\n  });\n}\n```\n\n#### UI Component for Tool @/component/image-generation-view.tsx\n\n```tsx\nimport { openai } from '@ai-sdk/openai';\nimport { UIToolInvocation } from 'ai';\n\nexport default function ImageGenerationView({\n  invocation,\n}: {\n  invocation: UIToolInvocation<ReturnType<typeof openai.tools.imageGeneration>>;\n}) {\n  switch (invocation.state) {\n    case 'input-available':\n      return <div>Generating image...</div>;\n    case 'output-available':\n      return <img src={`data:image/png;base64,${invocation.output.result}`} />;\n  }\n}\n```\n\n#### Page @/app/page.tsx\n\n```tsx\n'use client';\n\nimport { ImageGenerationAgentMessage } from '@/agent/image-generation-agent';\nimport ImageGenerationView from '@/component/image-generation-view';\nimport { useChat } from '@ai-sdk/react';\n\nexport default function Page() {\n  const { messages, status, sendMessage } =\n    useChat<ImageGenerationAgentMessage>();\n\n  const [input, setInput] = useState('');\n  const handleSubmit = e => {\n    e.preventDefault();\n    sendMessage({ text: input });\n    setInput('');\n  };\n\n  return (\n    <div>\n      {messages.map(message => (\n        <div key={message.id}>\n          <strong>{`${message.role}: `}</strong>\n          {message.parts.map((part, index) => {\n            switch (part.type) {\n              case 'text':\n                return <div key={index}>{part.text}</div>;\n              case 'tool-generateImage':\n                return <ImageGenerationView key={index} invocation={part} />;\n            }\n          })}\n        </div>\n      ))}\n\n      <form onSubmit={handleSubmit}>\n        <input\n          value={input}\n          onChange={e => setInput(e.target.value)}\n          disabled={status !== 'ready'}\n        />\n      </form>\n    </div>\n  );\n}\n```\n\n## Templates\n\nWe've built [templates](https://ai-sdk.dev/docs/introduction#templates) that include AI SDK integrations for different use cases, providers, and frameworks. You can use these templates to get started with your AI-powered application.\n\n## Community\n\nThe AI SDK community can be found on [the Vercel Community](https://community.vercel.com/c/ai-sdk/62) where you can ask questions, voice ideas, and share your projects with other people.\n\n## Contributing\n\nContributions to the AI SDK are welcome and highly appreciated. However, before you jump right into it, we would like you to review our [Contribution Guidelines](https://github.com/vercel/ai/blob/main/CONTRIBUTING.md) to make sure you have smooth experience contributing to AI SDK.\n\n## Authors\n\nThis library is created by [Vercel](https://vercel.com) and [Next.js](https://nextjs.org) team members, with contributions from the [Open Source Community](https://github.com/vercel/ai/graphs/contributors).\n","publish_time":1693506821310,"_cnpm_publish_time":1693506821310,"dist-tags":{"ai-v5":"5.0.290","ai-v6":"6.0.332","alpha":"5.0.0-alpha.15","beta":"7.0.0-beta.187","canary":"7.0.0-canary.176","latest":"7.0.173","snapshot":"0.0.0-f1630544-20260811180950"}}