Skip to main content
@acedatacloud/sdk is the official TypeScript / JavaScript SDK for Ace Data Cloud, encapsulating all services on api.acedata.cloud into typed methods such as client.openai.chat.completions.create(...), client.images.generate(...), client.search.google(...), etc., with built-in SSE streaming, retry backoff, and typed exceptions. It can be used in Node.js, Deno, Bun, and modern browsers (with bundler). Source code and package address:

Installation

If you need to pay on the X402 chain (without API Token path), install another one:
Clean npm project version check output:
Result explanation:
  • The package version is 2026.504.2 (CalVer, the 2nd revision of the 504th ISO week of 2026).
  • AceDataCloud is the main class used to construct the client, accessible from the default export.

Prepare API Token

Refer to SDK Overview - Apply for API Token to obtain the token, then export it in the shell:
When constructing the client, if apiToken is not passed, the SDK will automatically read the ACEDATACLOUD_API_TOKEN environment variable. If you already have ACEDATACLOUD_API_KEY stored in your environment (as per project repository convention), you can explicitly pass it: new AceDataCloud({ apiToken: process.env.ACEDATACLOUD_API_KEY }).

Example 1: chat.completions (non-streaming)

Program output:
Result explanation:
  • id chatcmpl-DldCcLvkTFaioST8e6SjOl0wJScQA is the OpenAI compatible response ID, which can be found in the console usage history.
  • content ADC_TS_SDK_OK is the fixed identifier returned by the model, proving that the response has not been tampered with by the SDK.
  • One chat completion consumes about 22 tokens, billed at the rate of gpt-4o-mini.
  • The SDK declares the response as Record<string, unknown>, which is a JSON object at runtime; dot access like .id / .choices[0].message.content can run under .mjs, Node REPL, and Bun; strict TypeScript projects may require (res as any).id or turning off noImplicitAny in tsconfig.

Example 2: chat.completions (SSE streaming)

By enabling stream: true, create returns an asynchronous iterator, with each frame being a ChatCompletionChunk.
Program output:
Result explanation:
  • The first frame delay of 2481 ms is the time taken by the model to generate the first token; the subsequent 12 frames arrived within 135 ms.
  • The 13 frames together form "1 2 3 4 5", with each token forming a separate frame + the last frame containing finish_reason.
  • Streaming does not save more tokens than non-streaming, but the first token delay is significantly reduced, making it suitable for real-time UI.

Example 3: images.generate (NanoBanana)

client.images.generate({ provider: 'nano-banana', ... }) returns directly synchronously, no need to pass the wait parameter—the NanoBanana API itself generates synchronously.
Program output:
Result explanation:
  • image_url is a stable address on the CDN, which can be directly used in <img src /> or downloaded.
  • Most of the 16.6 seconds is spent on model inference, with local SDK overhead being negligible.
  • trace_id is the request ID assigned by the platform; if issues arise, providing this ID to customer service can help locate the problem quickly.
  • For asynchronous services (Midjourney, Sora, Veo, etc.), TaskHandle polling is required; see SDK Task Polling and Streaming Responses.

Example 4: Typed Error Handling

The SDK will throw errors as specific subclasses based on HTTP status (AuthenticationError / BadRequestError / RateLimitError / InternalServerError / APIConnectionError, etc.), allowing for precise branching using instanceof.
Program output:
Result explanation:
  • 401 automatically maps to AuthenticationError, business code can use instanceof for precise branching.
  • code: invalid_token comes from PlatformGateway, facilitating comparison with backend logs.
  • Similarly, 429 → RateLimitError, 400 → BadRequestError, 5xx → InternalServerError.

Example 5: Multi-model Routing

The same client can switch freely between multiple services, as long as the model names are consistent.
Program output:
Result explanation:
  • One piece of code, one token, covering OpenAI / Google / DeepSeek / xAI four types of model services.
  • gemini-2.5-flash did not return ADC_OK this time, due to the model’s own output style differences—the SDK did not silently swallow anything, faithfully passing the model’s original words to the business.
  • Pricing is based on each service’s actual token unit price, with the path only going through PlatformGateway once.
Program output:
Result explanation:
  • One request retrieves 10 organic results, with the field name organic (not organic_results).
  • The search goes through the Serp service, billed per request.
  • The same client instance can both chat and search, one token is sufficient.

Configuration Options

Browser Usage

@acedatacloud/sdk is an ESM + ISO (universal) package that can be directly imported in modern browsers with bundlers. Note: Do not hard-code the API Token in frontend code. Recommended for frontend:
  1. Use X402 paymentHandler — user wallets pay per use in USDC, no token required.
  2. Or use the SDK on your own server, with the browser only calling your own backend.

Advanced: Task Polling and Streaming Responses

  • Task-based services (Midjourney, Sora, Veo, Suno): use TaskHandle for polling, unit, timeout, and retry details see SDK Task Polling and Streaming.
  • Streaming chat: already demonstrated in Example 2; streaming audio/video is also supported.

Advanced: X402 Payment Hooks

If you do not want to apply for an API Token and want to pay per use on-chain, you can use paymentHandler:
createX402PaymentHandler accepts { network, evmProvider, evmAddress, preferScheme? } (EVM chain) or { network: 'solana', solanaWallet } (Solana) on the TypeScript side. When the Node server does not have window.ethereum, please use viem’s createWalletClient (based on private key) to wrap an EIP-1193 compatible provider and pass it in; detailed methods and real on-chain results see SDK + X402 Payment Hooks.

How to Check Remaining Quota

You can check the current account’s remaining quota through the Ace Data Cloud Console - Application List. You can view all usage history and billing details through the Ace Data Cloud Console - Usage History.

Learn More