Skip to main content
This page is written for AI agents and the people who set them up. Each recipe runs as written once 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 with pdk_. 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 the id, and poll until the batch finishes.
The batch 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

Use model ids exactly as 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:
Any MCP client that can send a header connects the same way. Then call 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 holds STRIPE_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:
Payments run in Stripe test mode while you build; use card 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

A person signs in once in a browser; on a machine without one, the CLI prints a link to open on another device. There is no unattended mode yet, so an agent cannot start the CLI on its own. Sign-in with an API key, for unattended runs, is coming. See the CLI.

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: id for browser runs, specId for specifications, and the generation id (pdg-…) and x-predev-request-id for AI calls.
  • Poll at a bounded interval, such as every 5 seconds, and stop on a terminal status: completed or failed for specifications and browser runs. Do not infer completion from array lengths or the completed count.
  • A timeout or a dropped stream does not mean the work stopped. Fetch it by id before submitting again, and send one Idempotency-Key per 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. Request includeEvents=true only 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 from GET /v1/generation afterwards.

Errors

REST errors are JSON with an error 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:
Branch on 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.

What the API does not do

The public REST API has no endpoint to start a coding session, deploy, cancel work, register webhooks, or schedule runs. Build with the coding agent on the web or in the CLI, and schedule API calls in your own application. Browser tasks do not expose a reusable login session or cookie profile.