{% extends "base.html" %} {% block title %}API Documentation - {{ project_name }}{% endblock %} {% block content %}

API Documentation

Integrate with {{ project_name }} using our REST API

Getting Started

The {{ project_name }} API provides programmatic access to our services. To get started, you'll need an API key.

Authentication

All API requests must include your API key in the Authorization header:

Authorization: Bearer YOUR_API_KEY
{% if user.is_authenticated %}

Ready to get started? Manage Your API Keys

{% else %}

Need an API key? Sign up or log in to generate your API keys.

{% endif %}

Base URL

All API requests should be made to:

https://api.{{ request.get_host }}/v1/

Response Format

All responses are returned in JSON format with the following structure:

Success Response

{
  "success": true,
  "data": {
    // Response data here
  },
  "message": "Operation completed successfully"
}

Error Response

{
  "success": false,
  "error": {
    "code": "ERROR_CODE",
    "message": "Human-readable error description"
  }
}

HTTP Status Codes

Status Code Description
200 Success - Request completed successfully
201 Created - Resource created successfully
400 Bad Request - Invalid request parameters
401 Unauthorized - Invalid or missing API key
403 Forbidden - Insufficient credits or permissions
404 Not Found - Resource not found
429 Too Many Requests - Rate limit exceeded
500 Internal Server Error - Server error occurred

API Endpoints

Account Information

GET /account/profile

Retrieve your account profile and credit balance.

Example Response
{
  "success": true,
  "data": {
    "user": {
      "email": "user@example.com",
      "full_name": "John Doe",
      "created_at": "2024-01-15T10:30:00Z"
    },
    "credit_balance": {
      "total": 1500.00,
      "subscription": 1000.00,
      "pay_as_you_go": 500.00
    }
  }
}

Services

GET /services

List all available services and their credit costs.

Example Response
{
  "success": true,
  "data": {
    "services": [
      {
        "id": 1,
        "name": "Text Processing",
        "description": "Advanced text analysis and processing",
        "credit_cost": 10.00,
        "is_active": true
      },
      {
        "id": 2,
        "name": "Image Analysis",
        "description": "AI-powered image recognition and analysis",
        "credit_cost": 25.00,
        "is_active": true
      }
    ]
  }
}

POST /services/{service_id}/use

Use a service (consumes credits based on service cost).

Request Body
{
  "input_data": {
    // Service-specific input parameters
  }
}
Example Response
{
  "success": true,
  "data": {
    "result": {
      // Service-specific output
    },
    "credits_consumed": 10.00,
    "remaining_balance": 1490.00
  }
}

Credit Management

GET /credits/balance

Get current credit balance with detailed breakdown.

Example Response
{
  "success": true,
  "data": {
    "total_balance": 1500.00,
    "subscription_credits": {
      "amount": 1000.00,
      "expires_at": "2024-02-15T23:59:59Z"
    },
    "pay_as_you_go_credits": {
      "amount": 500.00,
      "expires_at": null
    }
  }
}

GET /credits/transactions

List recent credit transactions with pagination.

Query Parameters
  • page - Page number (default: 1)
  • limit - Items per page (default: 20, max: 100)
  • type - Filter by transaction type (purchase, subscription, consumption, admin)
Example Response
{
  "success": true,
  "data": {
    "transactions": [
      {
        "id": 123,
        "amount": -10.00,
        "description": "Text Processing service usage",
        "type": "consumption",
        "created_at": "2024-01-20T14:30:00Z"
      }
    ],
    "pagination": {
      "current_page": 1,
      "total_pages": 5,
      "total_items": 95
    }
  }
}

Rate Limiting

API requests are subject to rate limiting to ensure fair usage:

  • Free Tier: 100 requests per hour
  • Paid Plans: 1,000+ requests per hour (varies by plan)

Rate limit information is included in response headers:

X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1640995200

SDKs and Code Examples

# Get account profile
curl -X GET "https://api.{{ request.get_host }}/v1/account/profile" \
     -H "Authorization: Bearer YOUR_API_KEY" \
     -H "Content-Type: application/json"

# Use a service
curl -X POST "https://api.{{ request.get_host }}/v1/services/1/use" \
     -H "Authorization: Bearer YOUR_API_KEY" \
     -H "Content-Type: application/json" \
     -d '{"input_data": {"text": "Hello, world!"}}'
import requests

# Configuration
API_BASE_URL = "https://api.{{ request.get_host }}/v1"
API_KEY = "YOUR_API_KEY"

headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json"
}

# Get account profile
response = requests.get(f"{API_BASE_URL}/account/profile", headers=headers)
profile = response.json()

# Use a service
service_data = {
    "input_data": {
        "text": "Hello, world!"
    }
}
response = requests.post(f"{API_BASE_URL}/services/1/use", 
                        json=service_data, headers=headers)
result = response.json()
// Configuration
const API_BASE_URL = "https://api.{{ request.get_host }}/v1";
const API_KEY = "YOUR_API_KEY";

const headers = {
    "Authorization": `Bearer ${API_KEY}`,
    "Content-Type": "application/json"
};

// Get account profile
const getProfile = async () => {
    const response = await fetch(`${API_BASE_URL}/account/profile`, {
        method: 'GET',
        headers: headers
    });
    return await response.json();
};

// Use a service
const useService = async (serviceId, inputData) => {
    const response = await fetch(`${API_BASE_URL}/services/${serviceId}/use`, {
        method: 'POST',
        headers: headers,
        body: JSON.stringify({ input_data: inputData })
    });
    return await response.json();
};
 [
        "text" => "Hello, world!"
    ]
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiBaseUrl . "/services/1/use");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($serviceData));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$result = json_decode($response, true);
curl_close($ch);
?>

Quick Links

Need Help?

If you have questions about the API or need assistance integrating with our services, please don't hesitate to contact our support team.

Contact Support

API Status

API Status:
Operational
Response Time:
~150ms
{% endblock %}