Skip to content

About

Cloudflare Workers TypeScript edge endpoint for browser apps: SpecStream live search, cited answers and page reads with the key as a secret, CORS allowlist, per visitor rate limit and edge cache. fetch only, tsc verified.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

SpecStream at the edge for browser apps, on Cloudflare Workers

Give a website or a browser extension live web search, cited answers and page reads without shipping a key. This Worker holds your SpecStream key as a secret, answers your origins only, holds each visitor to a rate you set, and sends the browser small JSON:

const reply = await fetch("https://search.example.com/search?q=" + encodeURIComponent("best lidar sensors 2026"));
const { sources } = await reply.json();   // [{ url, title, site, snippet, published }]
Route SpecStream call Browser gets Price
GET /search?q=&num= POST /v1/web-search, fast tier sources: url, title, site, snippet, published $1 per 1,000
GET /answer?q= POST /v1/web-search, default tier answer: value and the page it was read from, or null; sources $5 per 1,000
POST /extract {"urls": [...], "query": "..."} POST /v1/extract, up to 5 URLs pages: url, status, title, published, text as Markdown $0.80 per 1,000 pages read

One file, src/index.ts, with fetch only and no runtime dependencies. It typechecks with tsc --noEmit against @cloudflare/workers-types.

What keeps it safe in public

  • The key never leaves the Worker. It is a secret binding; a visitor can send no key and never sees one, nor the price or request id of a call.
  • Your origins only. ALLOWED_ORIGINS lists the sites that may call it from a browser; any other origin gets 403 before a call is made, and preflight OPTIONS is answered.
  • A rate per visitor. With the VISITOR_LIMITER rate limiting binding in wrangler.toml, each IP gets 30 requests a minute and then 429 with Retry-After.
  • Bounded calls. A query is 1 to 500 characters, a search at most 10 results, an extract at most 5 URLs, all checked before any call.
  • Edge cache. A repeated search or answer is served from the Cloudflare cache for SEARCH_CACHE_SECONDS (300 by default) and paid once. The Cache API works on a custom domain, not on workers.dev.
  • Quiet failures. If SpecStream is busy (503), the Worker waits as told and tries once more, then answers 503 with Retry-After. A refused key or an empty balance is logged for you and shown to the visitor only as "Search is unavailable right now."

Deploy

npx wrangler secret put SPECSTREAM_API_KEY     # https://specstream.ai/workspace, $2 of credit with no card
# set ALLOWED_ORIGINS in wrangler.toml to your site
npx wrangler deploy

For npx wrangler dev, copy .env.example to .env; Wrangler reads it as local secrets.

Test

npm install
npm test        # tsc --noEmit, then the compiled worker under node --test

The tests call the Worker's fetch handler against a local stand-in for the SpecStream API, with no network: the small JSON shape and the fast tier, sources with null fields, a search with no sources and no answer, a cited answer on the default tier, a page read with a blocked page left empty and an Idempotency-Key, refusals of bad input before any call, CORS preflight and a 403 for an unknown origin, the rate limiting binding's 429, a 503 waited out once and passed on the second time, a refused key hidden from the visitor, and a cached search paid once. They need no key and spend nothing. Passed on Node 22 with TypeScript 5.9.

For drop in Google Custom Search, Bing v7, Tavily and Exa routes at the edge, see cloudflare-workers-specstream.

Prices

Price
Fast search (speed: "fast"), up to 10 results $1 per 1,000 searches, 937 ms median over 6,548 live calls in the 7 days to December 1, 2026
Default search, with a cited answer when the question has one $5 per 1,000 searches
Extract, a page read as Markdown $0.80 per 1,000 pages read
Free credit on sign up $2, which is 2,000 fast searches or 2,500 pages read, no card
Monthly Pro Pass $49 a month: 5,000 ready list rows a month and $49 of API credit

SpecStream is the live web data engine: first on WideSearch and 99 on SimpleQA Verified (benchmarks).

Links

License

MIT

About

Cloudflare Workers TypeScript edge endpoint for browser apps: SpecStream live search, cited answers and page reads with the key as a secret, CORS allowlist, per visitor rate limit and edge cache. fetch only, tsc verified.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages