Billing API¶
Manage workspace billing, metering, and payment methods. The billing API tracks action usage against plan limits, handles payment method collection via Stripe, and manages plan lifecycle transitions from trial through active subscription.
Get Billing Status¶
GET /api/billing
Returns the current billing status for the workspace, including plan state, usage counters, and payment method status.
Response (200 OK)¶
{
"plan_status": "trial",
"actions_used": 142,
"actions_limit": 1000,
"period_start": "2026-03-01T00:00:00Z",
"period_end": "2026-03-31T00:00:00Z",
"days_remaining": 24,
"has_payment_method": false
}
Response Fields¶
| Field | Type | Description |
|---|---|---|
plan_status | string | Current plan state: trial, promo, active, readonly, suspended, or deleted |
actions_used | integer | Number of actions consumed in the current billing period |
actions_limit | integer | Maximum actions allowed in the current billing period |
period_start | string | ISO 8601 timestamp for the start of the current billing period |
period_end | string | ISO 8601 timestamp for the end of the current billing period |
days_remaining | integer | Days remaining in the current period |
has_payment_method | boolean | Whether a valid payment method is attached to the workspace |
Get Daily Usage¶
GET /api/billing/usage/daily
Returns daily action usage for the last 30 days. Useful for rendering usage charts and identifying consumption trends.
Response (200 OK)¶
[
{"date": "2026-03-06", "count": 47},
{"date": "2026-03-05", "count": 63},
{"date": "2026-03-04", "count": 32}
]
Response Fields (per entry)¶
| Field | Type | Description |
|---|---|---|
date | string | Date in YYYY-MM-DD format |
count | integer | Number of actions executed on that date |
Create Setup Intent¶
POST /api/billing/setup-intent
Creates a Stripe SetupIntent for securely collecting a payment method. Use the returned client_secret with Stripe Elements on the frontend to confirm the card details without charging the user.
Response (200 OK)¶
Response Fields¶
| Field | Type | Description |
|---|---|---|
client_secret | string | Stripe SetupIntent client secret for frontend confirmation |
Tip
Pass the client_secret to stripe.confirmCardSetup() in your frontend. After successful confirmation, call the Attach Payment Method endpoint with the resulting payment_method_id.
Attach Payment Method¶
POST /api/billing/payment-method
Attaches a payment method to the workspace after a SetupIntent has been confirmed on the frontend. For workspaces on the trial plan, this automatically transitions the plan to promo (3 months free).
Request Body¶
| Field | Type | Required | Description |
|---|---|---|---|
payment_method_id | string | Yes | Stripe PaymentMethod ID from the confirmed SetupIntent |
Response (200 OK)¶
Response Fields¶
| Field | Type | Description |
|---|---|---|
status | string | The new plan status after attaching the payment method |
Info
If the workspace is already on promo or active, the payment method is updated but the plan status does not change.
Create Checkout Session¶
POST /api/billing/subscribe
Creates a Stripe Checkout session for subscribing to a paid plan. Redirects the user to Stripe's hosted checkout page.
Request Body¶
| Field | Type | Required | Description |
|---|---|---|---|
success_url | string | Yes | URL to redirect to after successful checkout |
cancel_url | string | Yes | URL to redirect to if the user cancels checkout |
import requests
resp = requests.post(
"https://api.runagents.io/api/billing/subscribe",
headers={"Authorization": f"Bearer {api_key}"},
json={
"success_url": "https://app.runagents.io/settings?billing=success",
"cancel_url": "https://app.runagents.io/settings?billing=cancel",
},
)
print(resp.json())
Response (200 OK)¶
Response Fields¶
| Field | Type | Description |
|---|---|---|
url | string | Stripe Checkout URL to redirect the user to |
Create Billing Portal Session¶
POST /api/billing/portal
Creates a Stripe Billing Portal session. The portal allows users to manage their subscription, update payment methods, and view invoice history.
Request Body¶
| Field | Type | Required | Description |
|---|---|---|---|
return_url | string | Yes | URL to redirect to when the user exits the portal |
Response (200 OK)¶
Response Fields¶
| Field | Type | Description |
|---|---|---|
url | string | Stripe Billing Portal URL to redirect the user to |
Get Publishable Key¶
GET /api/billing/publishable-key
Returns the Stripe publishable key for initializing Stripe Elements on the frontend. This key is safe to expose in client-side code.
Response (200 OK)¶
Response Fields¶
| Field | Type | Description |
|---|---|---|
publishable_key | string | Stripe publishable key for frontend use |
Plan Lifecycle¶
Workspace plans follow a state machine with automatic transitions based on time, usage, and payment events.
flowchart TD
trial["Trial<br/>(30 days, 1000 actions)"]
readonly["ReadOnly<br/>(30-day grace)"]
promo["Promo<br/>(3 months free)"]
active["Active<br/>($24/mo)"]
suspended["Suspended"]
deleted["Deleted"]
trial -->|"No payment method"| readonly
readonly -->|"Grace expires"| deleted
trial -->|"Payment method added"| promo
promo -->|"Promo period ends"| active
active -->|"Payment failure"| suspended
suspended -->|"Payment resolved"| active
active -->|"Cancel subscription"| deleted Transitions¶
| From | To | Trigger |
|---|---|---|
trial | promo | Payment method attached via /api/billing/payment-method |
trial | readonly | Trial period (30 days) or action limit (1,000) exceeded without a payment method |
promo | active | Promotional period (3 months) expires; first charge at $24/month |
active | suspended | Stripe payment fails (card declined, expired, etc.) |
active | deleted | User cancels subscription via Stripe Billing Portal |
readonly | deleted | Grace period (30 days) expires without a payment method being added |
suspended | active | Payment method updated and outstanding invoice paid |
Warning
In readonly status, existing agents continue running but new deployments and configuration changes are blocked. In suspended status, all agent execution is paused until payment is resolved.
Plan Status Reference¶
| Status | Description | Agent Execution | New Deployments | Duration |
|---|---|---|---|---|
trial | Free trial period | Yes | Yes | 30 days or 1,000 actions |
promo | Promotional period after adding payment method | Yes | Yes | 3 months |
active | Paid subscription | Yes | Yes | Ongoing ($24/month) |
readonly | Trial expired, grace period | Yes (existing only) | No | 30 days |
suspended | Payment failed | No | No | Until payment resolved |
deleted | Workspace deactivated | No | No | Permanent |