Base URL: https://aibuddy.life/wp-json/aibuddy-code/v2


📋 Available API Endpoints

Your Postman collection includes 11 test requests covering 3 core API endpoints:


1️⃣ GET /user – User Information

Endpoint: /user?api_key={your_api_key}
Method: GET
Authentication: API Key (query parameter)

Purpose:

  • Validate API key
  • Get user’s credit balance
  • Check account status

Response:

{
  "success": true,
  "user": {
    "id": 1,
    "email": "user@example.com",
    "credits": 1500.00,
    "status": "active",
    "created_at": "2025-10-15 10:30:00",
    "last_used": "2025-11-02 14:25:00"
  }
}

When to use:

  • Extension startup (to validate API key)
  • Before making AI requests
  • Display credit balance in Extension UI
  • After credit purchases

2️⃣ GET /health – Provider Health Check

Endpoint: /health
Method: GET
Authentication: None (public endpoint)

Purpose:

  • Check which AI providers are available
  • Monitor provider status
  • Get response times

Response:

{
  "success": true,
  "providers": {
    "openai": {
      "status": "healthy",
      "last_check": "2025-11-02 14:30:00",
      "response_time": 0.45
    },
    "claude": {
      "status": "healthy",
      "last_check": "2025-11-02 14:30:05",
      "response_time": 0.52
    },
    "gemini": {
      "status": "disabled",
      "last_check": "2025-11-02 14:30:10",
      "response_time": null
    }
  }
}

Status Values:

  • healthy ✅ – Provider working
  • error ❌ – Provider has issues
  • disabled 🔒 – Provider turned off

When to use:

  • Extension startup (optional)
  • After inference failures
  • Show status in Extension UI

3️⃣ POST /inference – AI Inference (MAIN API)

Endpoint: /inference
Method: POST
Authentication: API Key (in request body)

Purpose:

  • Send prompts to AI
  • Get AI responses
  • Generate code
  • Explain code
  • Answer questions

Request:

{
  "api_key": "your_api_key_here",
  "messages": [
    {
      "role": "user",
      "content": "Your prompt here"
    }
  ],
  "model": "auto"
}

Response:

{
  "success": true,
  "response": "AI generated response here...",
  "provider": "openai",
  "model": "gpt-4",
  "tokens_used": 150,
  "credits_deducted": 0.15,
  "remaining_credits": 1499.85
}

Supported Models:

  • auto – Automatic provider selection (recommended)
  • openai – Force OpenAI
  • claude – Force Claude
  • gemini – Force Gemini

When to use:

  • User asks AI for help
  • Code generation
  • Code explanation
  • Multi-turn conversations

🧪 Postman Collection – Test Scenarios

Your collection includes 11 pre-configured tests:

✅ Core Tests (2)

  1. Get User Info – Validate API key and check credits
  2. Check Provider Health – Monitor AI provider status

✅ Inference Tests (7)

  1. Simple Question – Basic AI test (“What is 2+2?”)
  2. Code Generation – Generate Python function
  3. Code Explanation – Explain JavaScript code
  4. Multi-turn Conversation – Context-aware responses
  5. Force OpenAI – Test OpenAI provider specifically
  6. Force Claude – Test Claude provider specifically
  7. Force Gemini – Test Gemini provider specifically

✅ Error Tests (2)

  1. Invalid API Key – Test 401 error handling
  2. Missing API Key – Test validation

🔐 Authentication Methods

For Extension:

// Option 1: Query parameter (GET requests)
const url = `${baseUrl}/user?api_key=${apiKey}`;
// Option 2: Request body (POST requests)
const body = {
  api_key: apiKey,
  messages: [...]
};

💡 Integration Tips

1. Extension Startup Flow

// 1. Validate API key and get credits
const userInfo = await fetch(`${baseUrl}/user?api_key=${apiKey}`);
console.log('Credits:', userInfo.user.credits);
// 2. Check provider health (optional)
const health = await fetch(`${baseUrl}/health`);
console.log('Providers:', health.providers);

2. AI Request Flow

// Send inference request
const response = await fetch(`${baseUrl}/inference`, {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    api_key: apiKey,
    messages: [{role: 'user', content: prompt}],
    model: 'auto'
  })
});
const data = await response.json();
console.log('AI Response:', data.response);
console.log('Credits remaining:', data.remaining_credits);

3. Error Handling

if (response.status === 401) {
  // Invalid API key
  showError('Please check your API key in settings');
}
if (response.status === 402) {
  // Insufficient credits
  showError('Low credits! Buy more at https://aibuddy.life/pricing/');
}

📊 Credit System

How it works:

  • Each AI request deducts credits based on tokens used
  • Typical costs:
    • Simple question: ~0.01-0.05 credits
    • Code generation: ~0.10-0.30 credits
    • Long response: ~0.30-1.00 credits

Check balance:

  • Call /user endpoint before/after requests
  • Display in Extension status bar
  • Warn user when credits < 10

Buy credits:

  • Direct user to: https://aibuddy.life/pricing/

🎯 Summary

3 API Endpoints:

  1. ✅ GET /user – User info & credits
  2. ✅ GET /health – Provider status
  3. ✅ POST /inference – AI requests (MAIN)

Base URL:

https://aibuddy.life/wp-json/aibuddy-code/v2

Authentication:

api_key: your_api_key_here

Postman Collection:

  • 11 pre-configured test requests
  • Automatic validation tests
  • Error scenario coverage
  • Ready to import and test

🔗 Important Links

For Users:

  • Dashboard: https://aibuddy.life/extension-dashboard/
  • Buy Credits: https://aibuddy.life/pricing/
  • Login: https://aibuddy.life/extension-login/
  • Get API Key: Dashboard → API Key tab

For Testing:


All APIs tested and working! ✅ Ready for Extension integration! 🚀