Web scraping in Codex
Add the Spicrawl MCP server to Codex. It can then read web pages as clean Markdown.
Set it up
Three steps give Codex the tools, the know-how to write Spicrawl code, and rules for using both. Or do all three with spicrawl init --client codex.
Set your API key:
bashexport SPICRAWL_API_KEY=spicrawl_live_... # add to your shell profileAdd the MCP server. Codex reads the key from
SPICRAWL_API_KEYeach time it connects, so the key never lands in a file:bashcodex mcp add spicrawl --url https://mcp.spicrawl.com/mcp --bearer-token-env-var SPICRAWL_API_KEYThis writes the same thing as this config:
~/.codex/config.toml[mcp_servers.spicrawl] url = "https://mcp.spicrawl.com/mcp" bearer_token_env_var = "SPICRAWL_API_KEY"For one project only, put the table in
.codex/config.toml. Codex reads it only in trusted projects.Install the skill:
bashmkdir -p .agents/skills/spicrawl curl -fsSL https://app.spicrawl.com/skill.md -o .agents/skills/spicrawl/SKILL.mdPaste this section into
AGENTS.mdat the project root:AGENTS.md## Web data (Spicrawl) Use Spicrawl to read web pages: the spicrawl_* MCP tools, the `spicrawl` CLI, or POST https://api.spicrawl.com/v1/scrape with `Authorization: Bearer $SPICRAWL_API_KEY` in code. Docs: https://docs.spicrawl.com/llms.txt (append .md to any page URL for Markdown). - Ask for markdown: `response_format: "markdown"` (API default is html); on spicrawl_scrape, `format: "markdown"`. - Check the site's status, not only the HTTP status: `X-Target-Status` header, or `status` in the JSON envelope (spicrawl_scrape with `format: "json"`). 200 is the page; 404/410 mean it does not exist; 403/429/503 mean the site refused, so escalate. - On an error, switch on `code`. Retry only when `retryable` is true, after `retry_after_seconds`. Read `diagnostics.hint` and change what it names first. Never retry ERR::REQUEST::*, ERR::AUTH::* or ERR::LIMIT::QUOTA_EXCEEDED. - Escalate one step at a time and stop at the first that works: plain fetch (1 credit) -> `js_render: true` (3) -> add the user's own `proxy` if they have one. Empty or skeleton content means render; ERR::UPSTREAM::CHALLENGE or a 403 target status means retry once, then the user's own proxy. - Set `max_cost` on every request to the price of the step you intend. - Keep the cache on (default). Set `cache: false` only for prices, stock or other live data. - Trim tokens with `main_content_only` (on by default for markdown), `include_tags`, `exclude_tags`. - For more than 20 URLs, use a batch job (spicrawl_batch_submit / POST /v1/batch). Batch items return html, markdown or text (spicrawl_batch_submit defaults to markdown, POST /v1/batch to html). Extraction, screenshots, actions and sessions are refused with a 400 before anything is charged: scrape those URLs one by one. - With the CLI, read stdout as JSON and branch on the exit code: 3 auth, 4 bad request, 5 limit, 6 site refused or failed, 7 proxy, 8 engine or extraction, 10 network. - Never print or commit SPICRAWL_API_KEY. Log `X-Request-Id` for failures.Check it with
codex mcp list, or/mcpin a session. You should see 25spicrawl_*tools.
Or use the CLI
Codex works in a shell, so the spicrawl CLI works with no config at all. It prints JSON when piped and exits with a stable code:
spicrawl scrape https://example.com/pricing --format markdown --max-cost 3 | jq -r .contentIn Codex cloud, do not count on the MCP server. Use the CLI or plain HTTP. Set SPICRAWL_API_KEY as an environment variable, not a secret, and allow api.spicrawl.com in the agent’s internet access.
A first task to try
Start codex in the project and ask:
Use Spicrawl to read https://example.com/pricing as markdown. List each plan with its monthly price.
If the page comes back empty, retry with rendering.What it can do
The server gives the agent 25 spicrawl_* tools. Each call runs under your API key, with the same limits and credits as a direct API call.
- Read one page:
spicrawl_scrapereturns Markdown (the default), text, HTML, JSON or PDF. - Read many pages:
spicrawl_batch_submitqueues up to 10,000 URLs. Follow it withspicrawl_batch_statusandspicrawl_batch_results. - Pages behind a login:
spicrawl_session_createkeeps cookies and storage across calls. - Debug a failure:
spicrawl_requests_listandspicrawl_request_get. - Check usage:
spicrawl_usage_summaryand the other usage tools. These need a key with thereadscope. - Look things up:
spicrawl_docs_searchandspicrawl_docs_readsearch and read the Spicrawl docs.
One tool, spicrawl_browser_connect_url, is listed but coming soon. On spicrawl_scrape, the rendering argument is render, not the API’s js_render.
Good to know
- No crawling. Spicrawl does not follow links or find pages. Give the agent the URLs.
- Credits per request. A plain fetch is 1 credit. JavaScript rendering is 3. Full-browser rendering is 8.
- Failures are free. A failed request costs 0 credits.
- The cache saves time, not credits. A cache hit costs the same as the fetch that stored it.
- Cap each call. Set
max_cost, and a request that could cost more is refused before it runs. - Coming soon: managed proxies, stealth mode, a remote browser and AI extraction from a plain-language prompt. Today you can bring your own proxy.
Frequently asked questions
Where does Codex store the server?
In ~/.codex/config.toml. To use it in one project only, put the same table in .codex/config.toml. Codex reads project config only in trusted projects.
Can Codex use the CLI instead of MCP?
Yes. Codex works in a shell, so it can run spicrawl scrape URL --format markdown --max-cost 3. The CLI prints JSON when piped and exits with a stable code.
Does it work in Codex cloud?
Do not count on the MCP server there. Use the CLI or plain HTTP. Set SPICRAWL_API_KEY as an environment variable (not a secret) and allow api.spicrawl.com in the agent’s internet access.
Why does the server return 401?
SPICRAWL_API_KEY was not set in the shell that started codex. Export it and start a new session.
How much does each page cost?
A plain fetch costs 1 credit, JavaScript rendering 3 and full-browser rendering 8. Failed requests cost 0. A cache hit costs the same as the fetch that stored it. Ask the agent to set max_cost on each request so it never spends more than you expect.