Skip to content

[CI only] feat(web-fetch): AI/ML API Toolbox scraping backend - #2

Closed
hugoaimlapi wants to merge 5 commits into
mainfrom
feat/aimlapi-toolbox-web-fetch
Closed

hugoaimlapi wants to merge 5 commits into
mainfrom
feat/aimlapi-toolbox-web-fetch

Conversation

@hugoaimlapi

Copy link
Copy Markdown
Member

CI validation run for the upstream PR to Twigpine/openclaude. Not for merge; will be closed once PR Checks finish.

WebFetch can already replace its raw HTTP fetch with Firecrawl's scrape
endpoint. This adds the AI/ML API Toolbox as a second scraping backend,
selected with WEB_FETCH_PROVIDER=aimlapi and authenticated with the
existing AIMLAPI_API_KEY.

Toolbox runs are billed per page, so the backend is opt-in only: an
AI/ML API key on its own never changes how WebFetch fetches pages. When
selected it takes precedence over a Firecrawl key.

- Runs the search1api/crawl tool, chosen by measurement against the
  other page-to-Markdown tools ($0.0013 per run, main-content Markdown
  with links, unbilled is_error runs for missing pages), with
  max_cost_usd capped at $0.005.
- Polls queued (202) runs, reports is_error runs and over-cost
  refusals as WebFetch errors, and retries 429/502/503/504 with the
  same idempotency key so a retry is never charged twice.
- Sends the key and the X-AIMLAPI-Source / X-AIMLAPI-Partner-ID
  attribution headers only to the fixed tools.aimlapi.com endpoint.
- Like the Firecrawl path, a failed scrape is reported rather than
  retried over plain HTTP.
An aimlapi provider profile that points at the user's own proxy exports
the proxy's credential as AIMLAPI_API_KEY. The WebFetch Toolbox backend
now treats that key as not configured when the route is aimlapi and
OPENAI_BASE_URL (or OPENAI_API_BASE) is not the canonical
https://api.aimlapi.com/v1, so it is never sent to tools.aimlapi.com.
…ndling

Apply the same hardening Twigpine#2465 gave the AI/ML API web search backend:

- send only the first usable key of a comma-separated AIMLAPI_API_KEY pool
  (firstUsableCredential), instead of the whole list as one Bearer token;
- treat the OPENAI_API_BASE alias like OPENAI_BASE_URL when deciding that an
  aimlapi profile points at a proxy, so its credential is withheld;
- send both Toolbox requests with redirect: 'error', so the key and the
  attribution headers never reach another host;
- redact the active key from Toolbox error text before it is shown.

Tests cover each case.
… use

Word the $0.005 max_cost_usd as a limit each run requests, as the merged
search docs do, and note that a pooled AIMLAPI_API_KEY contributes only its
first usable key.
…etup guide

Describe the requested $0.005 cost limit, the OPENAI_API_BASE alias in the
proxy check, first-key use of a pooled AIMLAPI_API_KEY, and that Toolbox
requests never follow redirects.
@hugoaimlapi hugoaimlapi reopened this Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants