VERCEL AI SDK + PROXIES.SX

The Vercel AI SDK (the ai package) is a TypeScript toolkit for LLM apps with a unified tool-calling API. Node's built-in fetch ignores proxy env vars, so route tool fetches through an undici ProxyAgent.

Sign up Get an API key

RUNNABLE SAMPLE

Replace ACCOUNT_ID and PROXY_PASSWORD with the values from GET https://api.proxies.sx/v1/gateway/credentials (header X-API-Key: psx_...). The proxy password is set once in the portal and is not your login password.

// npm i ai @ai-sdk/openai undici zod
import { generateText, tool, stepCountIs } from "ai";
import { openai } from "@ai-sdk/openai";
import { ProxyAgent, fetch as proxiedFetch } from "undici";
import { randomUUID } from "node:crypto";
import { z } from "zod";

const sid = randomUUID().slice(0, 12);            // one session id per request
const username = `psx_ACCOUNT_ID-peer-us-rot-sticky-sid-${sid}`;
const dispatcher = new ProxyAgent({
  uri: "http://gw.proxies.sx:7000",
  token: "Basic " + Buffer.from(`${username}:PROXY_PASSWORD`).toString("base64"),
});

const { text } = await generateText({
  model: openai("gpt-4o-mini"),
  prompt: "What IP does https://api.ipify.org?format=json report?",
  stopWhen: stepCountIs(3),
  tools: {
    fetchPage: tool({
      description: "Fetch a URL through a US residential/mobile exit",
      inputSchema: z.object({ url: z.string().url() }),
      execute: async ({ url }) => (await proxiedFetch(url, { dispatcher })).text(),
    }),
  },
});
console.log(text);

AI SDK 5 shown (inputSchema, stopWhen). On AI SDK 4 the tool field is parameters and the loop option is maxSteps.

ROTATION FOR VERCEL AI SDK

Use: sticky per generateText call; ondemand when every tool call is independent. Build the dispatcher once per request with a fresh session id and reuse it for every tool call in that request.

Sticky pins the device for that session id, not the exit IP - mobile carriers re-NAT on their own schedule, so a pinned modem can still surface a new address. Without a -sid-, sticky and auto modes do nothing across connections. Unknown tokens are dropped silently, so -session- is not a substitute for -sid-.

CHANGE COUNTRY OR POOL

Edit the username only: peer-us, peer-jp, mbl-gb. peer covers ~127 countries; mbl is carrier modems in US, GB, FR, NL, PL and GE (Georgia). Check stock before you pick: GET https://api.proxies.sx/v1/gateway/pool/stock. $4/GB, $2.40/GB at 250 GB+, duration free.

MORE

/pool/skill.md (full username DSL and API contract) · /pool/ (Pool Gateway) · all integrations · skill.md for this section