Skip to main content

Overview

The Headless Agent Flow allows an AI agent or automation script to go from zero to generating content in 5 API calls, with no browser interaction required. Card data never touches ModelsLab servers — agents tokenize cards directly with Stripe.
All responses include X-RateLimit-Remaining and X-RateLimit-Reset headers for rate-limit awareness.

Stripe Publishable Key

Agents fetch the Stripe publishable key via the API, then create PaymentMethods directly with Stripe. Card data never touches ModelsLab servers.
Returns { "publishable_key": "pk_live_...", "instructions": "..." }. Always use this endpoint to get the current key — it handles key rotation automatically.

The 5-Step Flow

1

Create Account

A verification email is sent automatically.
2

Verify Email (Headless)

Extract the verification_code from the verification email and verify without a browser.
Returns access_token and api_key directly.
3

Create Payment Method via Stripe

Use the publishable key from Step 1 of the flow (fetched via GET /billing/stripe-config) to tokenize card details. Card data never touches ModelsLab servers.
Returns a payment_method_id (e.g., pm_1Xyz...). Use this ID with ModelsLab endpoints — never send raw card numbers to ModelsLab.
4

Fund Wallet or Subscribe

Use the payment_method_id from Step 3 to either fund the wallet or create a subscription.Option A — Fund wallet (pay-as-you-go):
Option B — Subscribe to a plan:
Use GET /subscriptions/plans first to discover available plan IDs.
5

Generate Content with Existing APIs

Use the existing generation APIs (/api/v6, /api/v7, /api/v8) with the api_key returned in Step 2. See the Image Generation, Video API, and Speech & Audio docs for endpoint details.

Flow Diagram

Alternative: Human-Assisted Payment

If your agent does not have access to card details or the card requires 3D Secure, use the Human-Assisted flow instead. The agent creates a Stripe-hosted payment link and forwards it to a human:
The human completes payment on Stripe Checkout, is redirected to ModelsLab’s success page with a session_id, and relays it to the agent. The agent then confirms:
See Billing & Wallet for full details on the three payment paths.

Handling Card Failures

When a card is declined, the API returns HTTP 402 with a structured error:
If a card requires 3D Secure authentication, the API returns HTTP 202:

Rate Limits

LimiterLimitApplies to
agent-auth20/min per IP+emailSignup, login, verify, forgot-password
agent-billing15/min per IP+userWallet fund, subscriptions, payment methods
agent-general120/min per IP+userAll other authenticated endpoints

Idempotency

All billing mutations support an Idempotency-Key header. If you retry a request with the same key, the cached response is returned with idempotency_replay: true instead of charging again.
Use deterministic idempotency keys (e.g., fund-{amount}-{date}-{nonce}) to prevent duplicate charges on retries.