Docs/Reference

charge.ai.chat() reference

Every option, the reply object and the other calls.

Signature
charge.ai.chat(input, options?) → Promise<Reply>

input

A string, or an array of { role: 'system' | 'user' | 'assistant', content: string }.

options

  • lang: two-letter language of the reply, like hi, ta or en.
  • tier: 'standard' (₹0.10, default) or 'premium' (₹0.25, cloud only).
  • mode: 'cloud' (default), 'auto' (the free on-device model first, then the cloud) or 'device' (on-device only).
  • stream: true returns an async iterable of text, with a .result promise.
  • onStage(stage, status, detail): progress updates for a loading state.
  • signal: an AbortSignal that stops the reply, like fetch's. A cloud reply stopped mid-way is billed for what it had written.
  • files: File or Blob objects (PNG, JPEG, WebP, PDF; about 3 MB in all) for the model to read, added to the last message.
  • schema: a JSON Schema the reply must match; the parsed reply is reply.json. Not streamed.

Reply

Reply
{
  text: string,
  route: 'device' | 'cloud',
  model: string,
  region: 'in' | 'abroad' | 'device',
  costPaise: number,     // what the user paid; 100 paise = ₹1
  inputTokens: number,   // cloud replies: what the model read and wrote
  outputTokens: number,
  json?: unknown,        // with a schema: the parsed reply
  latencyMs: number,
}

Other calls

  • await charge.ai.embed(texts, { model?, dimensions? }): vectors for search and RAG, { vectors, inputTokens, costPaise }. See Search your own content.
  • charge.signIn() and charge.signOut(): sign the user in or out of your app.
  • charge.signedIn: whether the user is signed in to your app.
  • await charge.balance(): the user's balance in paise, or null.
  • charge.topUp(): open the UPI top-up sheet.
  • charge.account(): open the user's ChargeMyAI account in a new tab.
  • charge.configure({ lang }): language of the sign-in and payment sheets (en, hi, ta).
  • charge.baseURL, charge.fetch, charge.connect() and charge.resolve(error): use your own OpenAI-style code. See Keep your AI code.
  • await charge.authorizeServer(): ask the user to let your server use AI for them; returns { code }. See Call from your server.

Read next

Still stuck? Talk to us and we'll help.