Platform API

Credits, spending caps, API key management, and account details.

GET /v1/credits

Get your current credit balance and spending cap status. Requires credits:read scope.

Response fields

FieldTypeDescription
balance.microintegerBalance in microdollars (1 microdollar = $0.000001).
balance.displaystringHuman-readable balance (e.g. "$9.75").
balance.currencystringAlways "USD".
caps.organizationobjectOrganization-level spending cap and usage.
caps.projectobject | nullProject-level spending cap (if set).
caps.keyobject | nullAPI key-level spending cap (if set).

Code examples

curl

curl https://api.fairstack.ai/v1/credits \
  -H "Authorization: Bearer $FAIRSTACK_API_KEY"

Python

from fairstack import FairStack

client = FairStack(api_key="fs_live_YOUR_KEY")

balance = client.credits.get()
print(balance.display)  # "$9.75"
print(balance.micro)    # 9750000

Node.js

import { FairStack } from "fairstack";

const client = new FairStack({ apiKey: "fs_live_YOUR_KEY" });

const balance = await client.credits.get();
console.log(balance.display);  // "$9.75"
console.log(balance.micro);    // 9750000

Response

{
  "balance": {
    "micro": 9750000,
    "display": "$9.75",
    "currency": "USD"
  },
  "caps": {
    "organization": { "micro": 100000000, "display": "$100.00", "used_micro": 250000 },
    "project": null,
    "key": { "micro": 10000000, "display": "$10.00", "used_micro": 250000 }
  }
}

GET /v1/api-keys

List your API keys and their scopes. The full key value is never returned after creation.

Response fields

FieldTypeDescription
idstringKey identifier.
namestringDisplay name you assigned.
prefixstringFirst 12 characters for identification.
scopesstring[]Permitted actions for this key.
cap_total_microinteger | nullSpending cap in microdollars (null = unlimited).
created_atstringISO 8601 creation timestamp.
last_used_atstring | nullLast request timestamp.

Response

{
  "keys": [
    {
      "id": "key_abc123",
      "name": "production",
      "prefix": "fs_live_abc1...",
      "scopes": ["generate", "assets:read", "credits:read"],
      "cap_total_micro": 10000000,
      "created_at": "2026-02-15T10:00:00Z",
      "last_used_at": "2026-03-10T14:30:00Z"
    },
    {
      "id": "key_def456",
      "name": "agent-image-gen",
      "prefix": "fs_live_def4...",
      "scopes": ["generate"],
      "cap_total_micro": 5000000,
      "created_at": "2026-03-01T08:00:00Z",
      "last_used_at": "2026-03-10T12:00:00Z"
    }
  ]
}

POST /v1/api-keys

Create a new API key with specific scopes and an optional spending cap. The full key value is returned only in this response -- store it securely.

Request body

FieldTypeRequiredDescription
namestringYesDisplay name for the key (e.g. "production", "staging").
scopesstring[]YesList of scopes: "generate", "assets:read", "assets:delete", "credits:read".
cap_total_microintegerNoSpending cap in microdollars. Omit for unlimited.

curl

curl -X POST https://api.fairstack.ai/v1/api-keys \
  -H "Authorization: Bearer $FAIRSTACK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"my-agent","scopes":["generate","credits:read"],"cap_total_micro":10000000}'

Python

# Create a scoped API key with a $10 spending cap
key = client.api_keys.create(
    name="my-agent",
    scopes=["generate", "credits:read"],
    cap_total_micro=10_000_000  # $10.00
)
print(key.key)  # fs_live_ghi789... (shown only once)

Node.js

// Create a scoped API key with a $10 spending cap
const key = await client.apiKeys.create({
  name: "my-agent",
  scopes: ["generate", "credits:read"],
  capTotalMicro: 10_000_000, // $10.00
});
console.log(key.key); // fs_live_ghi789... (shown only once)

Response

{
  "id": "key_ghi789",
  "name": "my-agent",
  "key": "fs_live_ghi789xxxxxxxxxxxxxxxxxxxxxxxx",
  "scopes": ["generate", "credits:read"],
  "cap_total_micro": 10000000,
  "created_at": "2026-03-10T15:00:00Z"
}
Save the key immediately. The full key value is only shown once. If lost, delete this key and create a new one.

DELETE /v1/api-keys/:id

Revoke an API key. This is permanent and takes effect immediately.

curl -X DELETE https://api.fairstack.ai/v1/api-keys/key_abc123 \
  -H "Authorization: Bearer $FAIRSTACK_API_KEY"

Returns 204 No Content on success.

Spending caps

FairStack supports three levels of spending caps to prevent runaway costs:

LevelWhat it limitsWhen to use
OrganizationTotal spend across all keysOverall budget control
ProjectSpend within a projectMulti-team organizations
API keySpend for a single keyAgent keys, per-use-case limits

When a cap is reached, generation requests return 402 Payment Required with the cap details in the error response.

Next steps