Node
The official TypeScript and Node.js SDK (@spyglasshq/sdk on npm, spyglass-so/spyglass-typescript on GitHub) provides a fully typed client for Node.js 18+, Bun, Deno, Vercel Functions, and Cloudflare Workers with zero external runtime dependencies.
Installation
Install @spyglasshq/sdk with your package manager:
Usage
- Get an API key from Settings → API in the dashboard.
- Set the key as an environment variable named
SPYGLASS_API_KEYor pass it directly tonew Spyglass({ token }).
Searching Brands & Creators
Search brands
Search brands by name (names), social handle (igUsername, tiktokUsername), known IDs (ids), or a natural-language brief (query):
Search creators
Search creators by handle, name, or natural-language brief, and filter by demographic and profile attributes (gender, ageRange, ethnicity, location, language):
Searching Ad Creatives & Social Media
Pass accountId to inspect a specific brand or creator’s creatives, or omit accountId and pass query to search across the entire Spyglass index:
Insights, Campaigns, Landing Pages & Comments
Creative insights, campaigns, and landing pages
Pull clustered creative themes (HOOK, USP, PERSONA, MEDIA_MIX), campaigns or offers, and ranked destination landing pages for any account:
Post comments
Fetch public comments from Instagram posts/reels (by shortcode or URL) and TikTok videos (by video ID or URL):
Indexing an Account
If Spyglass does not have a brand or creator yet, submit its website or social profile URL (POST /account/index is free) and poll until status is "ready":
TypeScript Types
All request and response types are exported under the spyglass namespace:
Error Handling
When the API returns a non-2xx status code, the SDK throws a SpyglassError (or a status-specific subclass such as PaymentRequiredError or TooManyRequestsError):
Retries, Timeouts & Raw Responses
The SDK defaults to a 60-second timeout and 2 automatic retries with exponential backoff on 408, 429, and 5xx responses. Configure these on the client or override them per request:
Chain .withRawResponse() on any request promise to inspect HTTP status codes and headers alongside parsed data: