GuidesFeatured

Code Examples

cURL, JavaScript, Python, and PHP integration samples.

All documentation

Copy-paste samples for the most common languages. Replace your-api-key-here with a real key from Dashboard → Settings → API Keys.

cURL

Text generation

curl -X POST "https://abzar-ai.com/api/external/ai" \
  -H "X-API-Key: your-api-key-here" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Write a product description for wireless headphones",
    "model": "deepseek-chat",
    "provider": "deepseek",
    "type": "text",
    "max_tokens": 500,
    "temperature": 0.7
  }'

Image generation

curl -X POST "https://abzar-ai.com/api/external/ai" \
  -H "X-API-Key: your-api-key-here" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Minimal product photo of wireless headphones on white background",
    "model": "dall-e-3",
    "provider": "openai",
    "type": "image",
    "size": "1024x1024",
    "quality": "hd",
    "style": "natural"
  }'

JavaScript (Node / browser-safe server)

const API_URL = "https://abzar-ai.com/api/external/ai"
const API_KEY = process.env.ABZAR_AI_API_KEY

async function generateText(prompt) {
  const response = await fetch(API_URL, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-API-Key": API_KEY
    },
    body: JSON.stringify({
      prompt,
      model: "deepseek-chat",
      provider: "deepseek",
      type: "text",
      max_tokens: 1000,
      temperature: 0.7
    })
  })

  const result = await response.json()
  if (!result.success) {
    throw new Error(result.error || "Generation failed")
  }
  return result.data.content
}

async function generateImage(prompt) {
  const response = await fetch(API_URL, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-API-Key": API_KEY
    },
    body: JSON.stringify({
      prompt,
      model: "dall-e-3",
      provider: "openai",
      type: "image",
      size: "1024x1024",
      quality: "standard",
      style: "vivid"
    })
  })

  const result = await response.json()
  if (!result.success) {
    throw new Error(result.error || "Image generation failed")
  }
  return result.data.image_url
}

Python

import os
import requests

API_URL = "https://abzar-ai.com/api/external/ai"
API_KEY = os.environ["ABZAR_AI_API_KEY"]

headers = {
    "X-API-Key": API_KEY,
    "Content-Type": "application/json",
}

def generate_text(prompt: str) -> str:
    payload = {
        "prompt": prompt,
        "model": "deepseek-chat",
        "provider": "deepseek",
        "type": "text",
        "max_tokens": 1000,
        "temperature": 0.7,
    }
    response = requests.post(API_URL, json=payload, headers=headers, timeout=60)
    data = response.json()
    if not data.get("success"):
        raise RuntimeError(data.get("error", "Generation failed"))
    return data["data"]["content"]

def generate_image(prompt: str) -> str:
    payload = {
        "prompt": prompt,
        "model": "dall-e-3",
        "provider": "openai",
        "type": "image",
        "size": "1024x1024",
        "quality": "hd",
        "style": "natural",
    }
    response = requests.post(API_URL, json=payload, headers=headers, timeout=120)
    data = response.json()
    if not data.get("success"):
        raise RuntimeError(data.get("error", "Image generation failed"))
    return data["data"]["image_url"]

PHP

<?php
function call_abzar_ai(string $prompt, string $api_key, array $options = []): array {
    $payload = array_merge([
        'type' => 'text',
        'model' => 'deepseek-chat',
        'provider' => 'deepseek',
        'max_tokens' => 1000,
        'temperature' => 0.7,
        'prompt' => $prompt,
    ], $options);

    $ch = curl_init('https://abzar-ai.com/api/external/ai');
    curl_setopt_array($ch, [
        CURLOPT_POST => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => [
            'Content-Type: application/json',
            'X-API-Key: ' . $api_key,
        ],
        CURLOPT_POSTFIELDS => json_encode($payload),
        CURLOPT_TIMEOUT => 60,
    ]);

    $body = curl_exec($ch);
    if ($body === false) {
        throw new RuntimeException(curl_error($ch));
    }
    curl_close($ch);

    $data = json_decode($body, true);
    if (!($data['success'] ?? false)) {
        throw new RuntimeException($data['error'] ?? 'Request failed');
    }
    return $data['data'];
}

// Text
$text = call_abzar_ai('Write a short product blurb', getenv('ABZAR_AI_API_KEY'));

// Image
$image = call_abzar_ai(
    'Studio photo of a ceramic mug',
    getenv('ABZAR_AI_API_KEY'),
    [
        'type' => 'image',
        'model' => 'dall-e-3',
        'provider' => 'openai',
        'size' => '1024x1024',
        'quality' => 'hd',
        'style' => 'natural',
    ]
);

WordPress helper

function call_abzar_ai($prompt, $api_key, $options = []) {
    $options = array_merge([
        'type' => 'text',
        'model' => 'deepseek-chat',
        'provider' => 'deepseek',
        'max_tokens' => 1000,
        'temperature' => 0.7,
        'prompt' => $prompt,
    ], $options);

    $response = wp_remote_post('https://abzar-ai.com/api/external/ai', [
        'headers' => [
            'X-API-Key' => $api_key,
            'Content-Type' => 'application/json',
        ],
        'body' => wp_json_encode($options),
        'timeout' => 60,
    ]);

    if (is_wp_error($response)) {
        return ['success' => false, 'error' => $response->get_error_message()];
    }

    return json_decode(wp_remote_retrieve_body($response), true);
}

Next steps