PREDEV_API_KEY is set.
Interfaces
Two more ways in: the CLI,
predev, runs the coding agent in a local repository and needs a person to sign in; the docs MCP server, https://docs.pre.dev/mcp, searches and reads this documentation with no key.
Get a key
Copy your pre.dev API key from Integrations → Built-in in the dashboard: pre.dev/projects/integrations for your personal workspace, or the Integrations page of a team workspace. Workspace keys start withpdk_.
Projects built on pre.dev already have the key as
PREDEV_API_KEY. It spends the workspace’s credits, so keep it on a server.
Plan access
Browser tasks and AI Gateway calls work on every plan, Free included: a Free personal account can spend 2 credits on browser tasks, and a Free workspace 5 credits on AI calls, before it needs a plan. Specifications and the MCP server need Premium, Pro, Team or Enterprise; Plus and team workspaces without a plan get 3 trial specifications. See API and MCP access.Choose an interface
Both official SDKs are named
predev-api: from predev_api import PredevAPI in Python and import { PredevAPI } from 'predev-api' in Node. They cover specifications and browser tasks.
Recipe 1: run a browser task over REST
Submit asynchronously, save theid, and poll until the batch finishes.
status is lowercase: processing, completed or failed. Each task has its own uppercase status; read data only when it is SUCCESS, because a completed batch can contain failed tasks. See submit tasks.
Recipe 2: call a model with the OpenAI SDK
GET /v1/models lists them; each row carries its credit prices in a predev object. The same key works with the Anthropic SDK at base URL https://api.pre.dev. See the AI Gateway.
Recipe 3: generate a specification over MCP
Add the MCP server with the key in a header. This works headless, with no browser sign-in:fast_spec:
executiveSummary says what to build, in at least 10 characters. Add existingContext (text describing an existing codebase) and docURLs when they help. If the result gives a spec id before the spec is finished, call get_spec with it every few seconds until the status is completed or failed. get_spec and list_specs use no credits. See MCP setup and the tool reference.
Recipe 4: take a payment in an app built on pre.dev
The project’s environment already holdsSTRIPE_SECRET_KEY (a project-tagged pre.dev key), STRIPE_API_HOST and STRIPE_WEBHOOK_SECRET. Point the Stripe SDK at pre.dev and write ordinary Stripe code in the app’s server:
4242 4242 4242 4242. The preview shows the app in a frame, where Checkout will not render, so open url in a new tab when framed. Server routes like these run in the project’s sandbox, including after you publish. See payments and webhooks.
Recipe 5: use the coding agent from a terminal
Keep names distinct
Pass existing context as text describing the codebase. It is not an ID that loads another project.
Long-running work
- Save every id as soon as you get it:
idfor browser runs,specIdfor specifications, and the generationid(pdg-…) andx-predev-request-idfor AI calls. - Poll at a bounded interval, such as every 5 seconds, and stop on a terminal status:
completedorfailedfor specifications and browser runs. Do not infer completion from array lengths or thecompletedcount. - A timeout or a dropped stream does not mean the work stopped. Fetch it by id before submitting again, and send one
Idempotency-Keyper logical browser submission; retries within 24 hours return the original run. - Browser runs stream from
GET /browser-agent/{id}/stream; the end of a stream is not a success signal. RequestincludeEvents=trueonly when you need the step timeline, since it can hold large screenshots. - AI Gateway calls stream with
stream: true. Lines that start with:are keep-alives. Streamed responses carry no credits header; read the charge fromGET /v1/generationafterwards.
Errors
REST errors are JSON with anerror message and, where one applies, a machine-readable code such as INSUFFICIENT_CREDITS, SUBSCRIPTION_REQUIRED or QUEUE_FULL on browser submissions. Some MCP results are text without isError; confirm a specification’s status with get_spec.
The AI Gateway raises its own errors in the OpenAI error shape, so the OpenAI and Anthropic SDKs raise their usual exceptions:
error.code: missing_api_key or invalid_api_key (401), insufficient_credits or subscription_required (402, nothing ran), rate_limit_exceeded (429, wait Retry-After seconds), balance_unavailable (503, retry), and upstream_unavailable (502, retry or send models fallbacks). Errors from the model keep their own status and message. See errors and retries.
Limits
The AI Gateway also refuses more than 30 failed key attempts a minute from one IP address, and accepts request bodies up to 100 MB of JSON or 60 MB for file and audio uploads.

