Skip to main content
@decodo/ai-sdk is the npm package that gives Vercel AI SDK models live web data. It adds tools that scrape a page as Markdown, search the web, map a site’s URLs, and crawl a site. All of them run on the Web Data API and work with any AI SDK model provider.
View the ai-sdk repository for the source code, examples, and latest releases.

Features

  • Web scraping – fetch one page as Markdown, optionally rendering JavaScript first
  • Search – search the web and get ranked results
  • Site mapping – list a site’s URLs without fetching their content
  • Crawling – start a crawl, poll its status, read the pages as Markdown, or cancel it
  • AI SDK integration – decodoTools() returns standard AI SDK tools you pass to generateText or pick one by one
  • Errors the model can act on – a failed call reaches the model as a tool error, and generateText keeps running

Requirements

  • Node.js 18 or newer
  • ai v6 or v7, which is a peer dependency
  • A Decodo Web Data API plan. Free trials are available on the dashboard.

Installation

The examples on this page use @ai-sdk/anthropic and read ANTHROPIC_API_KEY. Any AI SDK model provider works.

Authentication

Copy your API key from your Web Data API subscription in the Web Data API playground and store it in the DECODO_API_KEY environment variable:
You can also pass it directly:
decodoTools() throws right away when the API key is missing, or when it contains a line break, space, or other character that can’t be sent in a header.

Usage

Pass all the tools to generateText:
To give the model only some of the tools, destructure them. For example, a crawl needs crawl_start, crawl_status, and crawl_results:
The model polls crawl_status by calling it again, and each call uses a step, so give crawling prompts a higher stepCountIs. While a crawl is pending, crawl_status waits 5 seconds before answering. This slows polling and keeps a long crawl from using up the steps.

Available tools

A crawled page too long for one call is split across calls, and each part carries contentPart with its character range. Every page also comes back with its url, depth, status, and content_error, and the response carries total, so the model can tell how much is left to read.

Inputs

Inputs are strict: a field that isn’t listed is refused rather than ignored. limit, max_depth, select_paths, and exclude_paths keep a crawl off the parts of a site you don’t need, so they’re worth setting in the prompt.

Errors

A failed call reaches the model as a tool error it can read and act on, and generateText keeps running:
  • A rejected API key names DECODO_API_KEY.
  • Rate limits and 5xx responses tell the model to retry later.
  • A timeout tells the model to retry later, except on scrape and crawl_start. Those requests may still have run, so the model is told not to send them again unless asked.
  • Validation errors tell the model to change the input.
  • A page that couldn’t be scraped is an error, even when the API answered 200.
For the full list of API parameters behind these tools, see Parameters.

Support

Need help or just want to say hello? Our support is available 24/7.
You can also reach us anytime via email at support@decodo.com.

Feedback

Can’t find what you’re looking for? Request an article!
Have feedback? Share your thoughts on how we can improve.