Chameleon

User APIs

User-related API endpoints

User APIs

APIs for user account management, credits, and profile information.

Get User Info

Get current logged-in user's profile information.

Endpoint

POST /api/get-user-info

Authentication

Required: User must be logged in (session-based)

Request

POST /api/get-user-info
Content-Type: application/json

No request body required.

Response

{
  "code": 0,
  "message": "success",
  "data": {
    "uuid": "550e8400-e29b-41d4-a716-446655440000",
    "email": "user@example.com",
    "nickname": "John Doe",
    "avatar_url": "https://avatar.url",
    "invite_code": "a7Bx9Q",
    "invited_by": "referrer-uuid",
    "is_affiliate": true,
    "created_at": "2024-01-01T00:00:00.000Z"
  }
}

Error Responses

{
  "code": 1,
  "message": "no auth, please sign-in",
  "data": null
}

Example

const getUserInfo = async () => {
  const response = await fetch("/api/get-user-info", {
    method: "POST",
  });
  
  const data = await response.json();
  
  if (data.code === 0) {
    console.log("User:", data.data.email);
    console.log("Invite Code:", data.data.invite_code);
  }
};

Get User Credits

Get current credit balance and total earned credits.

Endpoint

POST /api/get-user-credits

Authentication

Required: User must be logged in

Request

POST /api/get-user-credits
Content-Type: application/json

Response

{
  "code": 0,
  "message": "success",
  "data": {
    "left_credits": 850,
    "total_credits": 1100
  }
}

Fields:

  • left_credits: Current available balance
  • total_credits: Lifetime earned credits

Example

const checkCredits = async () => {
  const response = await fetch("/api/get-user-credits", {
    method: "POST",
  });
  
  const data = await response.json();
  
  if (data.code === 0) {
    const { left_credits, total_credits } = data.data;
    console.log(`Balance: ${left_credits} / ${total_credits}`);
  }
};

Get User Subscription

Get user's active subscription details.

Endpoint

POST /api/get-user-subscription

Authentication

Required: User must be logged in

Request

POST /api/get-user-subscription
Content-Type: application/json

Response

With active subscription:

{
  "code": 0,
  "message": "success",
  "data": {
    "order_no": "order_123456",
    "product_id": "starter",
    "product_name": "Starter Plan",
    "interval": "month",
    "amount": 1900,
    "status": "paid",
    "sub_id": "sub_1NXxxx",
    "created_at": "2024-01-01T00:00:00.000Z"
  }
}

No active subscription:

{
  "code": 0,
  "message": "success",
  "data": null
}

Example

const getSubscription = async () => {
  const response = await fetch("/api/get-user-subscription", {
    method: "POST",
  });
  
  const data = await response.json();
  
  if (data.code === 0 && data.data) {
    console.log("Active plan:", data.data.product_name);
    console.log("Billing:", data.data.interval);
  } else {
    console.log("No active subscription");
  }
};

Daily Check-In (Ping)

Earn 1 credit per day by calling this endpoint.

Endpoint

POST /api/ping

Authentication

Required: User must be logged in

Request

POST /api/ping
Content-Type: application/json

Response

First ping of the day:

{
  "code": 0,
  "message": "Ping success, 1 credit added"
}

Already pinged today:

{
  "code": 0,
  "message": "You have already pinged today"
}

Behavior

  • Maximum 1 credit per day per user
  • Resets at midnight (UTC)
  • Credits expire in 1 year

Example

const dailyCheckIn = async () => {
  const response = await fetch("/api/ping", {
    method: "POST",
  });
  
  const data = await response.json();
  
  if (data.code === 0) {
    alert(data.message);
  }
};

Use Cases

  • Daily engagement reward
  • Gamification element
  • Keep users coming back
  • Simple loyalty program

Update Invite Settings

Enable or disable affiliate status.

Endpoint

POST /api/update-invite

Authentication

Required: User must be logged in

Request

POST /api/update-invite
Content-Type: application/json

{
  "is_affiliate": true
}

Response

{
  "code": 0,
  "message": "success",
  "data": {
    "uuid": "user-uuid",
    "email": "user@example.com",
    "is_affiliate": true
  }
}

Example

const enableAffiliate = async () => {
  const response = await fetch("/api/update-invite", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ is_affiliate: true }),
  });
  
  const data = await response.json();
  
  if (data.code === 0) {
    console.log("Affiliate enabled!");
  }
};

Add Feedback

Submit user feedback.

Endpoint

POST /api/add-feedback

Authentication

Required: User must be logged in

Request

POST /api/add-feedback
Content-Type: application/json

{
  "content": "Great product! Love the AI features.",
  "rating": 5
}

Fields:

  • content (required): Feedback text
  • rating (required): 1-5 stars

Response

{
  "code": 0,
  "message": "feedback added successfully"
}

Example

const submitFeedback = async (content: string, rating: number) => {
  const response = await fetch("/api/add-feedback", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ content, rating }),
  });
  
  return await response.json();
};

Error Handling

Common Errors

Error MessageCauseSolution
no auth, please sign-inNot logged inRedirect to /auth/signin
invalid paramsMissing required fieldsCheck request body
user not foundUser doesn't existVerify user_uuid
insufficient creditsNot enough creditsRecharge at /pricing

Example Error Handling

const callAPI = async () => {
  try {
    const response = await fetch("/api/get-user-info", {
      method: "POST",
    });
    
    const data = await response.json();
    
    if (data.code !== 0) {
      // Handle error
      console.error("API Error:", data.message);
      
      if (data.message.includes("no auth")) {
        window.location.href = "/auth/signin";
      }
      
      return;
    }
    
    // Success
    console.log("Data:", data.data);
    
  } catch (error) {
    console.error("Network error:", error);
  }
};

Rate Limiting

Currently no rate limiting is enforced, but recommended limits:

EndpointRecommended Limit
/api/ping1 request per day per user
/api/get-user-info100 requests per hour
/api/generator/generate10 requests per minute
Other endpoints60 requests per minute

API Client Example

TypeScript Client

class ChameleonAPI {
  private baseUrl: string;
  private apiKey?: string;
  
  constructor(baseUrl: string, apiKey?: string) {
    this.baseUrl = baseUrl;
    this.apiKey = apiKey;
  }
  
  private async request(endpoint: string, body?: any) {
    const headers: HeadersInit = {
      "Content-Type": "application/json",
    };
    
    if (this.apiKey) {
      headers["X-API-Key"] = this.apiKey;
    }
    
    const response = await fetch(`${this.baseUrl}${endpoint}`, {
      method: "POST",
      headers,
      body: body ? JSON.stringify(body) : undefined,
    });
    
    return await response.json();
  }
  
  async getUserInfo() {
    return await this.request("/api/get-user-info");
  }
  
  async getUserCredits() {
    return await this.request("/api/get-user-credits");
  }
  
  async generateAI(params: {
    ai_type: "image" | "video",
    provider: string,
    model: string,
    prompt: string,
  }) {
    return await this.request("/api/generator/generate", params);
  }
}

// Usage
const api = new ChameleonAPI("https://your-domain.com");
const credits = await api.getUserCredits();

Next Steps