askTIANaskTIAN
Partner Integration Docs

TIAN Points API

Integrate TIAN Points into your application to verify balances, deduct points for usage, and set up recurring monthly subscriptions. All endpoints are authenticated via API keys.

1. Get Your API Key

Go to the Partners page and create a new integration. You'll receive an API key in the format tc_live_xxxxx.

Keep your API key secret — it has full access to deduct points from users.

2. Authenticate Requests

Include your API key in every request using the X-API-Key header:

bash
curl -X POST https://wallet.asktian.com/api/partner/credits/verify \
  -H "Content-Type: application/json" \
  -H "X-API-Key: tc_live_your_key_here" \
  -d '{"privyId": "did:privy:user123"}'
3. Identify Your Users

Users are identified by their Privy ID (format: did:privy:xxxxx). Obtain this from the Privy SDK on your frontend:

typescript
import { usePrivy } from "@privy-io/react-auth";

function MyComponent() {
  const { user } = usePrivy();
  // user.id = "did:privy:xxxxx" — use this as privyId
  console.log(user?.id);
}
4. Verify Before Serving

Before serving a paid feature, check the user has enough credits:

typescript
// Server-side check (Node.js)
async function checkAndDeductCredits(privyId: string, amount: number) {
  const res = await fetch("https://wallet.asktian.com/api/partner/credits/deduct", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-API-Key": process.env.TIAN_API_KEY,
    },
    body: JSON.stringify({
      privyId,
      amount,           // integer, number of points to deduct
      description: "AI prediction query",
      endpoint: "/predict",
    }),
  });

  if (res.status === 402) {
    throw new Error("Insufficient TIAN Points");
  }

  const data = await res.json();
  return data; // { success: true, creditsDeducted: 1, newBalance: 99 }
}