AI Magicx
Getting Started

API Overview

API Overview

Technical Specifications

Base URL

Code
https://beta.aimagicx.com/api/v1

Protocol

  • HTTPS only - All API requests must use TLS 1.3
  • REST architecture - Standard HTTP methods and status codes
  • JSON format - Request and response bodies use JSON

API Versioning

  • Current version: v1
  • Version included in base URL path
  • Breaking changes will increment version number
  • Legacy versions supported for 12 months minimum

API Endpoints

Core Endpoints

EndpointMethodDescriptionCredit Cost
/chatPOSTCreate AI chat completions1 + tools used
/ai-image/generatePOSTGenerate images from prompts1 per image
/ai-image/logoPOSTCreate professional logos1 per logo
/modelsGETList available AI models1
/toolsGETList available AI tools1

Account & Billing Endpoints

EndpointMethodDescriptionCredit Cost
/accountGETRetrieve account details1
/creditsGETGet credit balance & history1
/usageGETDetailed usage statistics1
/overage/statusGETCheck overage configuration1

Authentication

All API requests require authentication via API key in the Authorization header:

Code
Authorization: Bearer mgx-sk-your-api-key

See Authentication Guide for detailed security implementation.

Request Standards

Headers

Required headers for all requests:

Code
Authorization: Bearer mgx-sk-your-api-key Content-Type: application/json Accept: application/json

Request Body

  • UTF-8 encoding required
  • Maximum payload size: 10MB
  • Nested objects supported up to 5 levels

Query Parameters

  • URL encoding required for special characters
  • Array parameters use param[]=value syntax
  • Boolean values: true or false (lowercase)

Response Format

Success Response

Code(json)
{ "success": true, "data": { // Endpoint-specific response data }, "meta": { "requestId": "req_abc123", "timestamp": "2025-01-10T12:00:00Z", "processingTime": 234 } }

Error Response

Code(json)
{ "success": false, "error": { "code": "ERROR_CODE", "message": "Human-readable error message", "details": { // Additional context }, "documentation": "https://docs.aimagicx.com/errors/ERROR_CODE" }, "meta": { "requestId": "req_abc123", "timestamp": "2025-01-10T12:00:00Z" } }

Response Headers

Standard Headers

All responses include these headers:

Code
X-Request-ID: Unique request identifier X-Processing-Time: Request processing time in milliseconds X-API-Version: Current API version

Rate Limit Headers

Code
X-RateLimit-Limit: Requests allowed per window X-RateLimit-Remaining: Requests remaining in current window X-RateLimit-Reset: Unix timestamp when window resets X-RateLimit-Window: Rate limit window duration (seconds)

Credit Usage Headers

Code
X-Credits-Used: Credits consumed by this request X-Credits-Remaining: Credits remaining in current period X-Credits-Reset: When monthly credits reset X-Overage-Active: Whether overage billing is active X-Overage-Rate: Current overage rate per credit

Rate Limiting

Rate Limit Tiers

PlanRequests/MinuteBurst LimitConcurrent Requests
API Starter30605
API Professional12024020
Professional6012010
EnterpriseCustomCustomCustom

Rate Limit Behavior

  • Limits applied per API key
  • 429 status code when exceeded
  • Exponential backoff recommended
  • Burst allowance for temporary spikes

Best Practices

Code(javascript)
// Example exponential backoff async function makeRequestWithRetry(url, options, maxRetries = 3) { for (let i = 0; i < maxRetries; i++) { try { const response = await fetch(url, options); if (response.status === 429) { const retryAfter = response.headers.get('Retry-After') || Math.pow(2, i); await new Promise(resolve => setTimeout(resolve, retryAfter * 1000)); continue; } return response; } catch (error) { if (i === maxRetries - 1) throw error; } } }

Error Codes

Client Errors (4xx)

CodeDescriptionResolution
INVALID_REQUESTMalformed request syntaxCheck request format
UNAUTHORIZEDInvalid or missing API keyVerify API key
FORBIDDENValid key but insufficient permissionsCheck plan limits
NOT_FOUNDRequested resource doesn't existVerify endpoint URL
RATE_LIMIT_EXCEEDEDToo many requestsImplement backoff
INSUFFICIENT_CREDITSCredit balance exhaustedEnable overage or add credits
PAYMENT_REQUIREDOverage disabled, credits exhaustedEnable pay-as-you-go

Server Errors (5xx)

CodeDescriptionResolution
INTERNAL_ERRORUnexpected server errorRetry with backoff
SERVICE_UNAVAILABLETemporary service issueRetry after delay
TIMEOUTRequest processing timeoutReduce payload size

Idempotency

For critical operations, use idempotency keys to prevent duplicate processing:

Code
Idempotency-Key: unique-request-identifier

Idempotency keys are stored for 24 hours and guarantee exactly-once processing.

Streaming Responses

Chat completions support server-sent events (SSE) for real-time streaming:

Code
POST /api/v1/chat Accept: text/event-stream

Stream format:

Code
data: {"token": "Hello", "index": 0} data: {"token": " world", "index": 1} data: [DONE]

Next Steps


For additional support, contact contact@aimagicx.com

Last modified on