Generate All 67 Endpoint Types & Drop In edgedata-client.ts
Use openapi-typescript against our live OpenAPI 3.1 schema for compile-time autocomplete across all 16 platforms, then drop the production EdgeDataClient below into your project. Claim a free key in the wizard below and snippets sync automatically.
# Generate typed paths & schemas for all 67 EdgeData REST endpoints (16 platforms) npx openapi-typescript https://api.upp3.com/v1/openapi-rapidapi.json -o src/edgedata.d.ts # Optional: install official MCP SDK if you also want Streamable HTTP MCP in TypeScript npm install @modelcontextprotocol/sdk
// src/edgedata-client.ts — Zero-dependency typed fetch client for EdgeData (67 REST endpoints)
export type EdgeDataMode = "summary" | "raw";
export interface EdgeDataMeta {
channel?: string;
plan?: string;
items_returned?: number;
credits_charged: number;
credits_remaining?: number;
elapsed_ms?: number;
}
export interface EdgeDataResponse<T = Record<string, unknown>> {
ok: boolean;
source: string;
mode: EdgeDataMode;
data: T;
meta: EdgeDataMeta;
}
export interface EdgeDataClientOptions {
apiKey?: string;
baseUrl?: string;
authHeader?: "X-API-Key" | "Authorization";
maxRetries?: number;
timeoutMs?: number;
}
const RETRYABLE_STATUS = new Set([429, 504]); // Strictly 0 Credits Charged on EdgeData
export class EdgeDataError extends Error {
constructor(
message: string,
public readonly status: number,
public readonly body: unknown,
) {
super(message);
this.name = "EdgeDataError";
}
}
export class EdgeDataClient {
private readonly apiKey: string;
private readonly baseUrl: string;
private readonly authHeader: "X-API-Key" | "Authorization";
private readonly maxRetries: number;
private readonly timeoutMs: number;
constructor(options: EdgeDataClientOptions = {}) {
const key = options.apiKey ?? process.env.EDGEDATA_API_KEY ?? "YOUR_EDGEDATA_API_KEY";
this.apiKey = key.trim();
this.baseUrl = (options.baseUrl ?? "https://api.upp3.com").replace(/\/+$/, "");
this.authHeader = options.authHeader ?? "X-API-Key";
this.maxRetries = options.maxRetries ?? 3;
this.timeoutMs = options.timeoutMs ?? 45_000;
}
private headers(extra?: Record<string, string>): Record<string, string> {
const auth =
this.authHeader === "Authorization"
? { Authorization: `Bearer ${this.apiKey}` }
: { "X-API-Key": this.apiKey };
return { Accept: "application/json", ...auth, ...extra };
}
private async request<T>(
method: "GET" | "POST",
path: string,
opts?: {
query?: Record<string, string | number | boolean | undefined>;
body?: Record<string, unknown>;
},
): Promise<EdgeDataResponse<T>> {
const url = new URL(path, this.baseUrl);
if (opts?.query) {
for (const [k, v] of Object.entries(opts.query)) {
if (v !== undefined) url.searchParams.set(k, String(v));
}
}
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
try {
const res = await fetch(url, {
method,
headers: this.headers(
opts?.body ? { "Content-Type": "application/json" } : undefined,
),
body: opts?.body ? JSON.stringify(opts.body) : undefined,
signal: controller.signal,
});
if (RETRYABLE_STATUS.has(res.status) && attempt < this.maxRetries) {
const retryAfter = Number(res.headers.get("retry-after")) || 0;
const backoffMs = Math.max(retryAfter * 1000, 500 * 2 ** attempt);
await new Promise((r) => setTimeout(r, backoffMs));
continue; // HTTP 504/429 strictly incur 0 Credits Charged
}
const payload = await res.json().catch(() => ({}));
if (!res.ok) {
throw new EdgeDataError(`EdgeData HTTP ${res.status} on ${path}`, res.status, payload);
}
return payload as EdgeDataResponse<T>;
} finally {
clearTimeout(timer);
}
}
throw new EdgeDataError(`Exhausted ${this.maxRetries} retries on ${path}`, 504, null);
}
get<T = Record<string, unknown>>(
path: string,
query?: Record<string, string | number | boolean | undefined>,
): Promise<EdgeDataResponse<T>> {
return this.request<T>("GET", path, { query });
}
post<T = Record<string, unknown>>(
path: string,
body: Record<string, unknown>,
): Promise<EdgeDataResponse<T>> {
return this.request<T>("POST", path, { body });
}
}
X-API-Key or Bearer
Set EDGEDATA_API_KEY in .env.local. Switch authHeader between X-API-Key and Authorization anytime.
Default to mode: "summary"
Pass mode: "summary" on GET query strings or POST JSON bodies to cut LLM input tokens by ~80% at the exact same credit price.
Safe 504/429 Backoff
Because upstream HTTP 504 and HTTP 429 responses strictly incur 0 Credits Charged, retries never burn your balance.