Home/Tools/@tpmjs/tools-fetch-text

fetchTextTool

@tpmjs/tools-fetch-text

Fetch a URL and return plain text content. Automatically strips HTML tags and returns clean text with metadata including content type, length, and status code. Useful for extracting text from web pages.

Official
web
v0.2.0
MIT

Interactive Playground

Test @tpmjs/tools-fetch-text (fetchTextTool) with AI-powered execution

0/2000 characters

Installation & Usage

Install this tool and use it with the AI SDK

1. Install the package

npm install @tpmjs/tools-fetch-text
pnpm add @tpmjs/tools-fetch-text
yarn add @tpmjs/tools-fetch-text
bun add @tpmjs/tools-fetch-text
deno add npm:@tpmjs/tools-fetch-text

2. Import the tool

import { fetchTextTool } from '@tpmjs/tools-fetch-text';

3. Use with AI SDK

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { fetchTextTool } from '@tpmjs/tools-fetch-text';

const result = await generateText({
  model: openai('gpt-4o'),
  tools: { fetchTextTool },
  prompt: 'Your prompt here...',
});

console.log(result.text);

Parameters

Available configuration options

Auto-extracted
url
Required
Type: string

The URL to fetch (must be http or https)

Schema extracted: 1/1/2026, 8:17:56 AM

README

@tpmjs/tools-fetch-text

Fetch a URL and return plain text content with metadata.

Installation

npm install @tpmjs/tools-fetch-text

Usage

import { fetchTextTool } from '@tpmjs/tools-fetch-text';

// Use with AI SDK
const result = await fetchTextTool.execute({
  url: 'https://example.com',
});

console.log(result.text); // Plain text content
console.log(result.contentType); // 'text/html; charset=utf-8'
console.log(result.contentLength); // 12345
console.log(result.metadata); // { fetchedAt, statusCode, redirected, finalUrl }

Features

  • Fetches any URL and returns plain text
  • Automatically strips HTML tags from HTML content
  • Decodes common HTML entities
  • 30 second timeout for requests
  • Returns metadata including content type, length, status code
  • Tracks redirects and provides final URL
  • Comprehensive error handling

Input

  • url (string, required): The URL to fetch (must be http or https)

Output

Returns a FetchTextResult object:

{
  text: string;           // Plain text content (HTML stripped if applicable)
  url: string;            // Original URL
  contentLength: number;  // Length of raw content in bytes
  contentType: string;    // Content-Type header value
  metadata: {
    fetchedAt: string;    // ISO timestamp of when content was fetched
    statusCode: number;   // HTTP status code
    redirected: boolean;  // Whether the request was redirected
    finalUrl: string;     // Final URL after redirects
  };
}

Requirements

  • Node.js 18+ (uses native fetch API)

License

MIT

Statistics

Downloads/month

0

Quality Score

0%

Bundle Size

NPM Keywords

tpmjs
web
fetch
text
scraping

Maintainers

thomasdavis(thomasalwyndavis@gmail.com)

Frameworks

vercel-ai
fetchTextTool | TPMJS | TPMJS