Credits and spending

Reading data and managing posts cost nothing. AI work costs credits: images, videos, voice-overs and Studio runs. The API treats every spend as something that must be limited in the request itself, because no person is there to confirm it.

The rules

  1. Scope. The key needs create.spend. It is off unless you chose it when you made the key, and it needs the role member or higher.
  2. max_credits on every spend. Put the most credits the request may cost in the JSON body. Without it the answer is 422 max_credits_required. A whole number, 0 or more.
  3. Quote first. GET /quote tells you the price before you spend. Use the credits it returns as your max_credits.
  4. A price above your limit is refused. If the real price is higher than max_credits, the answer is 402 quote_exceeded and nothing is charged.
  5. Only purchased credits pay. Welcome, bonus and referral credits are not used over the API. GET /credits/balance shows paid_available, the credits the API can spend.
  6. The same prices as the dashboard. The API adds no surcharge, and calls themselves are free.

Operations that spend: image_generate, image_edit, video_generate, video_tool_run, voice_generate, studio_make_with_ai and studio_sticker_make. The reference marks them.

Step by step

1. Check the balance

curl
curl "https://iqcore.ai/api/public/v1/credits/balance" -H "Authorization: Bearer $IQCORE_KEY"
JavaScript
const headers = { Authorization: `Bearer ${process.env.IQCORE_KEY}` };
const balance = await (await fetch("https://iqcore.ai/api/public/v1/credits/balance", { headers })).json();
console.log(balance.paid_available);
Python
import os
import requests

headers = {"Authorization": f"Bearer {os.environ['IQCORE_KEY']}"}
balance = requests.get("https://iqcore.ai/api/public/v1/credits/balance", headers=headers, timeout=30).json()
print(balance["paid_available"])

2. Ask for the price

GET /quote?kind=image&count=2&size=1K (kind is image, video, voice or studio_ai; add model, seconds, characters or action as needed). The answer has credits, approx_eur, paid_only, the balance that would pay and insufficient.

curl
curl "https://iqcore.ai/api/public/v1/quote?kind=image&count=2&size=1K" -H "Authorization: Bearer $IQCORE_KEY"
JavaScript
const quote = await (await fetch("https://iqcore.ai/api/public/v1/quote?kind=image&count=2&size=1K", { headers })).json();
console.log(quote.credits, quote.insufficient);
Python
quote = requests.get("https://iqcore.ai/api/public/v1/quote", headers=headers, timeout=30,
                     params={"kind": "image", "count": 2, "size": "1K"}).json()
print(quote["credits"], quote["insufficient"])

3. Spend, with a limit

curl
curl -X POST "https://iqcore.ai/api/public/v1/images" \
  -H "Authorization: Bearer $IQCORE_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"prompt": "A ceramic mug on a wooden table, soft morning light", "count": 2, "size": "1K", "max_credits": 20}'
JavaScript
const res = await fetch("https://iqcore.ai/api/public/v1/images", {
  method: "POST",
  headers: { ...headers, "Content-Type": "application/json", "Idempotency-Key": crypto.randomUUID() },
  body: JSON.stringify({
    prompt: "A ceramic mug on a wooden table, soft morning light",
    count: 2,
    size: "1K",
    max_credits: quote.credits,
  }),
});
const started = await res.json();
console.log(res.status, started.job.id, started.credits_reserved);
Python
import uuid

res = requests.post(
    "https://iqcore.ai/api/public/v1/images",
    headers={**headers, "Idempotency-Key": str(uuid.uuid4())},
    json={"prompt": "A ceramic mug on a wooden table, soft morning light",
          "count": 2, "size": "1K", "max_credits": quote["credits"]},
    timeout=30,
)
started = res.json()
print(res.status_code, started["job"]["id"], started["credits_reserved"])

The answer is 201 with a job (kind, id, status) and credits_reserved. The credits are reserved now. The real charge is settled when the job finishes, and it is never more than the reservation.

4. Follow the job

AI work runs in the background. Poll GET /jobs/{id} (add kind to make it faster), or the per-kind endpoints GET /images/{id}, GET /videos/{id} and GET /voice-overs/{id}. The job status goes through queued, submitting, processing and rendering to completed, failed or cancelled. When it is done, files lists the Media library ids of the results, and credits_charged shows what was charged. A failed job charges nothing.

curl
curl "https://iqcore.ai/api/public/v1/jobs/JOB_ID?kind=image" -H "Authorization: Bearer $IQCORE_KEY"
JavaScript
let job;
do {
  await new Promise((r) => setTimeout(r, 3000));
  job = await (await fetch(`https://iqcore.ai/api/public/v1/jobs/${started.job.id}?kind=image`, { headers })).json();
} while (!["completed", "failed", "cancelled"].includes(job.status));
console.log(job.status, job.files, job.credits_charged);
Python
import time

while True:
    time.sleep(3)
    job = requests.get(f"https://iqcore.ai/api/public/v1/jobs/{started['job']['id']}", headers=headers,
                       params={"kind": "image"}, timeout=30).json()
    if job["status"] in ("completed", "failed", "cancelled"):
        break
print(job["status"], job.get("files"), job["credits_charged"])

Use the file ids in media_ids of a post, after you checked them with media_validate.

Credit errors

All of these answer 402 (except the first) and charge nothing.

Code Meaning What to do
max_credits_required (422) You sent no max_credits. Add it.
quote_exceeded The price is higher than your max_credits. Quote again and send a higher limit, or ask for less. The error has credits and max_credits.
insufficient_credits Not enough purchased credits. Buy credits at billing_url. The error has credits, balance and billing_url.
spend_cap_reached A daily API cap was reached. Wait until resets_at, or ask an owner or admin to change the cap. The error has limit, cap, used and resets_at.

A retry with the same Idempotency-Key is safe after any of these: the key is given back. A 500 outcome_unknown on a spend means IQCore cannot tell whether the work started. Check your jobs and credit usage (GET /usage/records) before you spend again.

Daily caps

Besides max_credits per call, two daily caps protect an organization from a runaway script:

Cap Default Counted per
Per key 1,000 credits a day API key
Per organization 2,000 credits a day Organization, all keys together

IQCore admins can set other values, also for one organization. The caps count spends at their price while they run, and at the charged amount once settled. They apply on top of the limit of 10 spends per minute per key (see Rate limits). A cap cannot be approved around: the API has no approval step for it.

Switches that spend credits later

Three settings switch on AI work that runs later, by itself, and spends the organization's credits each time:

Operation What it switches on
POST /channels/{channel}/auto-reply (social_auto_reply_set) The AI answers comments and messages of a social channel by itself.
POST /whatsapp/numbers/{number}/ai (whatsapp_number_ai_set) The AI answers the customers of a WhatsApp number.
PATCH /reports/settings with suggestions: true (report_settings_update) AI suggestions in every monthly report.

The switch itself costs nothing, so it has no max_credits. The work it starts later is paid like the same work in the dashboard, and it does not count against max_credits or the daily caps of the key that switched it on. That is why these operations need the settings.write scope, which only owners and admins can give a key, and why a test key can never use them. Give settings.write only to tools you trust with the organization's credits, and watch the credit usage (GET /usage, or the dashboard) after you switch one on.

MCP

An AI app connected over MCP uses the same prices and a different flow: it gets a quote, then a person's rules decide (see MCP).

Next: Rate limits, Errors.