Home/Tools/@tpmjs/tools-redirect-trace

redirectTraceTool

@tpmjs/tools-redirect-trace

Trace all HTTP redirects from a URL to its final destination

Official
web
v0.2.0
MIT

Interactive Playground

Test @tpmjs/tools-redirect-trace (redirectTraceTool) 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-redirect-trace
pnpm add @tpmjs/tools-redirect-trace
yarn add @tpmjs/tools-redirect-trace
bun add @tpmjs/tools-redirect-trace
deno add npm:@tpmjs/tools-redirect-trace

2. Import the tool

import { redirectTraceTool } from '@tpmjs/tools-redirect-trace';

3. Use with AI SDK

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { redirectTraceTool } from '@tpmjs/tools-redirect-trace';

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

console.log(result.text);

Signature

(url: string, maxRedirects?: number) => Promise<unknown>

Tags

destination
final
http
redirect
redirects
tpmjs
trace
url
web

Parameters

Available configuration options

Auto-extracted
url
Required
Type: string

The URL to trace

maxRedirects
Optional
Type: number

Maximum number of redirects to follow (default: 10)

Schema extracted: 2/28/2026, 4:01:27 AM

README

@tpmjs/tools-redirect-trace

Trace all HTTP redirects from a URL to its final destination.

Installation

npm install @tpmjs/tools-redirect-trace

Usage

import { redirectTraceTool } from '@tpmjs/tools-redirect-trace';

// Use with AI SDK
const result = await redirectTraceTool.execute({
  url: 'https://bit.ly/example',
  maxRedirects: 10,
});

console.log(result.steps); // Array of redirect steps
console.log(result.finalUrl); // 'https://example.com/final-page'
console.log(result.redirectCount); // 2
console.log(result.statusCodes); // [301, 302, 200]

Features

  • Traces complete redirect chains from start to finish
  • Captures status codes, headers, and location for each step
  • Handles relative and absolute redirect URLs
  • 10 second timeout per request
  • Configurable max redirects (default: 10, max: 50)
  • Detects redirect loops and max redirect limits
  • Comprehensive error handling

Input

  • url (string, required): The URL to trace (must be http or https)
  • maxRedirects (number, optional): Maximum number of redirects to follow (default: 10, max: 50)

Output

Returns a RedirectTraceResult object:

{
  steps: RedirectStep[];      // Array of redirect steps
  finalUrl: string;           // Final URL after all redirects
  statusCodes: number[];      // Array of status codes
  redirectCount: number;      // Number of redirects (steps - 1)
  totalTimeMs: number;        // Total time to trace all redirects
  metadata: {
    startUrl: string;         // Original URL
    tracedAt: string;         // ISO timestamp
    maxRedirectsReached: boolean; // Whether max redirects limit was hit
  };
}

Each RedirectStep contains:

{
  url: string;                // The URL at this step
  statusCode: number;         // HTTP status code
  statusText: string;         // HTTP status text
  location: string | null;    // Location header (next URL)
  headers: Record<string, string>; // Important response headers
}

Use Cases

  • Debug redirect chains
  • Analyze URL shorteners
  • Verify redirect configurations
  • Track redirect performance
  • Detect redirect loops
  • Understand redirect paths

Requirements

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

License

MIT

Statistics

Downloads/month

11

GitHub Stars

0

Quality Score

74%

Bundle Size

NPM Keywords

tpmjs
web
redirects
http
trace

Maintainers

thomasdavis(thomasalwyndavis@gmail.com)

Frameworks

vercel-ai