
The Open Source AI Toolkit for TypeScript. Built by @Vercel.
- Tweets721
- Following4
- Followers37.1K
- Likes86
![Code snippet showing JavaScript imports and a function to generate text from specific pages of a PDF document using the AI SDK: import { generateText } from "ai" import { readFileSync } from "node:fs" const { text } = await generateText({ model: "google/gemini-4-neon", messages: [ { role: "user", content: [ { type: "file", data: readFileSync("report.pdf"), mediaType: "application/pdf", providerOptions: { google: { documentMetadata: { startPage: 2, endPage: 3, contentLayers: ["PAGE_TEXT"], }, }, }, }, { type: "text", text: "Summarize these pages." }, ], }, ] }) console.log(text)](https://pbs.twimg.com/media/HX1sBShbAAA7YVz.jpg?name=small&format=webp)
ALT Code snippet showing JavaScript imports and a function to generate text from specific pages of a PDF document using the AI SDK: import { generateText } from "ai" import { readFileSync } from "node:fs" const { text } = await generateText({ model: "google/gemini-4-neon", messages: [ { role: "user", content: [ { type: "file", data: readFileSync("report.pdf"), mediaType: "application/pdf", providerOptions: { google: { documentMetadata: { startPage: 2, endPage: 3, contentLayers: ["PAGE_TEXT"], }, }, }, }, { type: "text", text: "Summarize these pages." }, ], }, ] }) console.log(text)
![Code snippet showing JavaScript imports and a function to generate text from specific pages of a PDF document using the AI SDK: import { generateText } from "ai" import { readFileSync } from "node:fs" const { text } = await generateText({ model: "google/gemini-4-neon", messages: [ { role: "user", content: [ { type: "file", data: readFileSync("report.pdf"), mediaType: "application/pdf", providerOptions: { google: { documentMetadata: { startPage: 2, endPage: 3, contentLayers: ["PAGE_TEXT"], }, }, }, }, { type: "text", text: "Summarize these pages." }, ], }, ] }) console.log(text)](https://pbs.twimg.com/media/HX1sBShbAAA7YVz.jpg?name=small&format=webp)
ALT Code snippet showing JavaScript imports and a function to generate text from specific pages of a PDF document using the AI SDK: import { generateText } from "ai" import { readFileSync } from "node:fs" const { text } = await generateText({ model: "google/gemini-4-neon", messages: [ { role: "user", content: [ { type: "file", data: readFileSync("report.pdf"), mediaType: "application/pdf", providerOptions: { google: { documentMetadata: { startPage: 2, endPage: 3, contentLayers: ["PAGE_TEXT"], }, }, }, }, { type: "text", text: "Summarize these pages." }, ], }, ] }) console.log(text)
![Code snippet displays spreadsheet metadata, including file type, data source, and dimensions of visible cells: { type: 'file', data: readFileSync('metrics.xlsx'), mediaType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', providerOptions: { google: { spreadsheetMetadata: { sheetIndex: 1, visibleCells: 'A1:C5', contentLayers: ['DATA'] } } } }](https://pbs.twimg.com/media/HX1sCVvacAAAt4X.jpg?name=small&format=webp)
ALT Code snippet displays spreadsheet metadata, including file type, data source, and dimensions of visible cells: { type: 'file', data: readFileSync('metrics.xlsx'), mediaType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', providerOptions: { google: { spreadsheetMetadata: { sheetIndex: 1, visibleCells: 'A1:C5', contentLayers: ['DATA'] } } } }
![Code snippet for extracting invoice data, including a number and contact names, from a document using an AI model: import { experimental_extract as extract } from 'ai' const { answers } = await extract({ model: 'scaledown/extract-1', state: 'Invoice INV-2041 from Acme Corp. Contacts: Ana, Bo.', fields: { invoiceNumber: { type: 'text', instructions: 'The invoice number' }, contacts: { type: 'list', items: 'text', instructions: 'Contact names' }, }, }) console.log(answers.invoiceNumber.value) // 'INV-2041' console.log(answers.invoiceNumber.confidence) // 0.999 console.log(answers.contacts.value) // ['Ana', 'Bo']](https://pbs.twimg.com/media/HXmSJTdbYAA5JEw.jpg?name=small&format=webp)
ALT Code snippet for extracting invoice data, including a number and contact names, from a document using an AI model: import { experimental_extract as extract } from 'ai' const { answers } = await extract({ model: 'scaledown/extract-1', state: 'Invoice INV-2041 from Acme Corp. Contacts: Ana, Bo.', fields: { invoiceNumber: { type: 'text', instructions: 'The invoice number' }, contacts: { type: 'list', items: 'text', instructions: 'Contact names' }, }, }) console.log(answers.invoiceNumber.value) // 'INV-2041' console.log(answers.invoiceNumber.confidence) // 0.999 console.log(answers.contacts.value) // ['Ana', 'Bo']
![Code snippet for extracting data from a PDF, focusing on invoice number and contact names using an AI model: import { experimental_extract as extract } from 'ai' import { readFileSync } from 'node:fs' const { answers } = await extract({ model: 'scaledown/extract-1', state: [ { type: 'file', mediaType: 'application/pdf', data: readFileSync('invoice.pdf') }, ], fields: { invoiceNumber: { type: 'text', instructions: 'The invoice number' }, contacts: { type: 'list', items: 'text', instructions: 'Contact names' }, }, }) console.log(answers.invoiceNumber.value) // 'INV-2041' console.log(answers.contacts.value) // ['Ana', 'Bo']](https://pbs.twimg.com/media/HXmSKSuaQAAemfz.jpg?name=small&format=webp)
ALT Code snippet for extracting data from a PDF, focusing on invoice number and contact names using an AI model: import { experimental_extract as extract } from 'ai' import { readFileSync } from 'node:fs' const { answers } = await extract({ model: 'scaledown/extract-1', state: [ { type: 'file', mediaType: 'application/pdf', data: readFileSync('invoice.pdf') }, ], fields: { invoiceNumber: { type: 'text', instructions: 'The invoice number' }, contacts: { type: 'list', items: 'text', instructions: 'Contact names' }, }, }) console.log(answers.invoiceNumber.value) // 'INV-2041' console.log(answers.contacts.value) // ['Ana', 'Bo']
















