DocsOpen Moon AI
Browse the docs

Balance and request cost

Reference for GET /v1/credits, which returns the balance of the workspace wallet, and GET /v1/generation, which returns the final cost and tokens of a request.

On this page

Two read-only endpoints help you track spend: GET /v1/credits reads the balance of the key’s workspace, and GET /v1/generation reads what a specific request cost. Neither one is billed.

Read the balanceLink to the Read the balance section

HTTP
GET https://api.realmoon.ai/v1/credits

Returns the balance of the API wallet of the workspace the key belongs to.

  • Authentication: an sk-moon-… key with the inference scope (see Authentication).
  • Parameters: none.
  • Response: a credits object.

ExampleLink to the Example section

cURL
curl https://api.realmoon.ai/v1/credits \
  -H "Authorization: Bearer $MOONAI_API_KEY"
Python
import os
import httpx
from openai import OpenAI

client = OpenAI(base_url="https://api.realmoon.ai/v1", api_key=os.environ["MOONAI_API_KEY"])

credits = client.get("/credits", cast_to=httpx.Response).json()
print(credits["balance"])
JavaScript
import OpenAI from 'openai';

const client = new OpenAI({ baseURL: 'https://api.realmoon.ai/v1', apiKey: process.env.MOONAI_API_KEY });

const credits = await client.get('/credits');
console.log(credits.balance);

ResponseLink to the Response section

Response
{ "object": "credits", "balance": 1250000, "currency": "credits" }
FieldTypeDescription
objectstringAlways credits.
balanceintegerBalance in credits: paid credits, free credits and the API credit included in the plan, with the hold of in-flight requests already deducted. It can be negative.
currencystringAlways credits.

The balance goes back up when in-flight requests are settled at their actual cost (see Hold, then actual cost). A negative balance blocks new requests until the next top-up (402 insufficient_credits).

ErrorsLink to the Errors section

Only the errors common to the whole API apply: 401 invalid_api_key, 403 ip_not_allowed, 403 missing_scope, 429 rate_limit_exceeded, 503 service_unavailable. See Errors.

Read the cost of a requestLink to the Read the cost of a request section

HTTP
GET https://api.realmoon.ai/v1/generation?id=gen-…

Returns the final cost and the tokens counted for a request made in the key’s workspace.

  • Authentication: an sk-moon-… key with the inference scope, from the same workspace as the request.
  • Parameter: id, in the query string.
  • Response: a generation object.

ParameterLink to the Parameter section

ParameterTypeRequiredDescription
idstringyesThe request ID: gen- followed by 32 characters.

Where to find the ID:

EndpointID
/v1/chat/completionsThe id field of the response (or of each stream chunk), and the X-Moon-Request-Id header.
Images, speech, transcription, embeddings, OCRThe X-Moon-Request-Id header of the response.
POST /v1/videosThe X-Moon-Request-Id header of the response that starts the video. The video’s id (video_…) is not accepted here.

ExampleLink to the Example section

cURL
curl "https://api.realmoon.ai/v1/generation?id=gen-0123456789abcdef0123456789abcdef" \
  -H "Authorization: Bearer $MOONAI_API_KEY"
Python
import os
import httpx
from openai import OpenAI

client = OpenAI(base_url="https://api.realmoon.ai/v1", api_key=os.environ["MOONAI_API_KEY"])

raw = client.chat.completions.with_raw_response.create(
    model="anthropic/claude-haiku-4.5",
    messages=[{"role": "user", "content": "Hello"}],
)
request_id = raw.headers.get("x-moon-request-id")

cost = client.get(
    "/generation",
    cast_to=httpx.Response,
    options={"params": {"id": request_id}},
).json()
print(cost["credits_charged"])
JavaScript
import OpenAI from 'openai';

const client = new OpenAI({ baseURL: 'https://api.realmoon.ai/v1', apiKey: process.env.MOONAI_API_KEY });

const { response } = await client.chat.completions
  .create({ model: 'anthropic/claude-haiku-4.5', messages: [{ role: 'user', content: 'Hello' }] })
  .withResponse();
const requestId = response.headers.get('x-moon-request-id');

const cost = await client.get('/generation', { query: { id: requestId } });
console.log(cost.credits_charged);

ResponseLink to the Response section

Response
{
  "object": "generation",
  "id": "gen-0123456789abcdef0123456789abcdef",
  "model": "anthropic/claude-haiku-4.5",
  "tokens_prompt": 12,
  "tokens_completion": 41,
  "credits_charged": 0,
  "created_at": 1793836800
}

The credits_charged value is made up.

FieldTypeDescription
objectstringAlways generation.
idstringThe ID you requested.
modelstringThe model called, under the ID you sent.
tokens_promptinteger or nullInput tokens counted. null for an image, a video, speech, a transcription or OCR.
tokens_completioninteger or nullOutput tokens counted, reasoning included. null for all media, embeddings included.
credits_chargedintegerFinal cost in credits: hold, settlement and refunds added together. Never negative.
created_atintegerThe request’s timestamp, in Unix seconds.

When to read the cost againLink to the When to read the cost again section

  • A request settled right away (complete response with its token count, finished media) has its final cost as soon as it responds.
  • A response that was interrupted, or that had no token count, can still be settled at the actual cost reported by the provider for about twenty minutes: read /v1/generation again later.
  • A video is settled when its job ends: its cost is also available in usage.credits of the video object (see Videos).
  • A request’s details can be deleted after 90 days: /v1/generation then returns 404. Daily totals remain in the “Usage” tab of the portal.

ErrorsLink to the Errors section

HTTPcodeMeaning
400missing_required_parameterid is missing (param: "id").
404nullgeneration not found: unknown ID, an ID from another workspace, or one whose details were deleted.

Common errors (key, rate) are in Errors.

See alsoLink to the See also section

Moon AI

Moon AI in action

0:00

Explore

Screenshots of chat.realmoon.ai taken on October 29, 2026, with fictional data.

Moon AI

Your preferences

Visits counted without cookies.

Our server counts visits without cookies or trackers. Your theme and your answer about ad measurement are remembered on this device.

Ad measurement

With your consent, our ad networks’ trackers (Google) measure our ads, from the visit to the sign-up and then to the first subscription and its amount, and may show you our ads. Your answer is valid for 13 months; you can change it here at any time.

No answer saved on this device.

After you decline, no tag is loaded anymore and the site deletes the cookies they had set on realmoon.ai. Those on the ad networks’ own domains are managed with them or in your browser.

The Moon AI app has its own privacy settings.