SJinn
Credits Usage API

Credits Usage API

Query paginated credit usage records through the SJinn API.

Credits Usage API Overview

The Credits Usage API returns your account's credit ledger records. It is designed for large accounts: results are cursor-paginated and the response does not include a total count or aggregate total.

Use this endpoint to audit credit consumption across Tool API, Agent API, and other credit-consuming SJinn workflows.

Query Credits Usage

Supports both GET and POST methods.

Request

GET Method:

GET /api/un-api/query_credits_usage?limit=50
Authorization: Bearer YOUR_API_KEY

POST Method:

POST /api/un-api/query_credits_usage
Content-Type: application/json
Authorization: Bearer YOUR_API_KEY

Parameters

ParameterTypeRequiredDescription
limitnumberNoPage size. Defaults to 50; maximum is 200.
cursorstringNoCursor returned by the previous response. Treat this value as opaque.
start_timestringNoInclusive lower bound for create_time, in ISO/RFC3339 format.
end_timestringNoInclusive upper bound for create_time, in ISO/RFC3339 format.
task_typestringNoExact cost_record.task_type filter, for example tool_seedance20-video-api. Maximum length is 128 characters; allowed characters are letters, numbers, underscores, and hyphens.

Example Request (GET)

curl -X GET "https://sjinn.ai/api/un-api/query_credits_usage?limit=20" \
  -H "Authorization: Bearer YOUR_API_KEY"

Example Request (POST)

curl -X POST https://sjinn.ai/api/un-api/query_credits_usage \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "limit": 20,
    "start_time": "2026-06-01T00:00:00Z",
    "end_time": "2026-06-02T23:59:59Z",
    "task_type": "tool_seedance20-video-api"
  }'

Success Response

{
  "success": true,
  "errorMsg": "",
  "error_code": 0,
  "data": {
    "records": [
      {
        "id": "7f7a1111-2222-4333-8444-555555555555",
        "task_type": "tool_seedance20-video-api",
        "task_id": "550e8400-e29b-41d4-a716-446655440000",
        "chat_id": null,
        "cost_credits": 420,
        "create_time": "2026-06-02T10:30:00.123456+00:00"
      }
    ],
    "next_cursor": "eyJjcmVhdGVfdGltZSI6IjIwMjYtMDYtMDJUMTA6MzA6MDAuMTIzNDU2KzAwOjAwIiwiaWQiOiI3ZjdhMTExMS0yMjIyLTQzMzMtODQ0NC01NTU1NTU1NTU1NTUifQ",
    "has_more": true
  }
}

Response Fields

  • data.records (array) - Credit usage records for the current page.
  • data.records[].id (string) - Unique credit record ID.
  • data.records[].task_type (string or null) - Credit source type. Tool API records usually start with tool_.
  • data.records[].task_id (string or null) - Related task ID when available.
  • data.records[].chat_id (string or null) - Related agent chat ID when available.
  • data.records[].cost_credits (number) - Credits consumed by the record. A value of 0 can appear for refunded task records.
  • data.records[].create_time (string) - Record creation timestamp.
  • data.next_cursor (string or null) - Cursor for the next page. Send it as cursor in the next request.
  • data.has_more (boolean) - Whether more records are available.

The response intentionally does not include total_count or total credits. This keeps the endpoint fast for accounts with large usage history.

Pagination Example

const API_KEY = 'YOUR_API_KEY';
const BASE_URL = 'https://sjinn.ai/api/un-api';

async function listCreditUsage(maxPages = 3) {
  let cursor = null;
  const allRecords = [];

  for (let page = 0; page < maxPages; page++) {
    const params = new URLSearchParams({ limit: '100' });
    if (cursor) params.set('cursor', cursor);

    const response = await fetch(`${BASE_URL}/query_credits_usage?${params.toString()}`, {
      headers: {
        'Authorization': `Bearer ${API_KEY}`,
      },
    });

    const result = await response.json();
    if (!result.success) {
      throw new Error(result.errorMsg);
    }

    allRecords.push(...result.data.records);

    if (!result.data.has_more) break;
    cursor = result.data.next_cursor;
  }

  return allRecords;
}

Notes

  • Cursors are opaque. Do not parse or modify them in client code.
  • Results are ordered by newest first.
  • task_type filters use exact matching and only support letters, numbers, underscores, and hyphens.
  • Keep API keys on the server side. Do not expose them in browser code or public repositories.

Error Response

{
  "success": false,
  "errorMsg": "Invalid cursor",
  "error_code": 0
}

Common error cases:

  • Missing or invalid API key returns HTTP 401.
  • Invalid cursor, start_time, end_time, or task_type returns HTTP 400.
  • Member verification errors return success: false with error_code: 103.
  • Non-member access returns success: false with error_code: 1002.