PixHub
Examples

Examples

The examples below use YOUR_API_KEY as a placeholder - replace it with the real key from My Account → API Key.

Uploading a file

cURL

curl -X POST https://pixhub.ro/api/upload \
  -H "X-Api-Key: YOUR_API_KEY" \
  -F "file=@/path/to/photo.jpg"

JavaScript (fetch)

const formData = new FormData();
formData.append('file', fileInput.files[0]);

const response = await fetch('https://pixhub.ro/api/upload', {
  method: 'POST',
  headers: { 'X-Api-Key': 'YOUR_API_KEY' },
  body: formData,
});

const { upload } = await response.json();
console.log(upload.url);        // Page URL
console.log(upload.direct_url); // Direct file URL

Python (requests)

import requests

with open('/path/to/photo.jpg', 'rb') as f:
    response = requests.post(
        'https://pixhub.ro/api/upload',
        headers={'X-Api-Key': 'YOUR_API_KEY'},
        files={'file': f},
    )

response.raise_for_status()
upload = response.json()['upload']
print(upload['url'])
print(upload['direct_url'])

Listing files (with pagination)

cURL

curl "https://pixhub.ro/api/uploads?page=2" \
  -H "X-Api-Key: YOUR_API_KEY"

JavaScript

const response = await fetch('https://pixhub.ro/api/uploads?page=1', {
  headers: { 'X-Api-Key': 'YOUR_API_KEY' },
});
const data = await response.json();
data.data.forEach(u => console.log(u.slug, u.url));

Deleting a file

cURL

curl -X DELETE https://pixhub.ro/api/uploads/aB3kX9 \
  -H "X-Api-Key: YOUR_API_KEY"

JavaScript

await fetch('https://pixhub.ro/api/uploads/aB3kX9', {
  method: 'DELETE',
  headers: { 'X-Api-Key': 'YOUR_API_KEY' },
});

Handling rate limits

JavaScript with automatic retry

async function apiRequest(url, options = {}) {
  const response = await fetch(url, {
    ...options,
    headers: { 'X-Api-Key': 'YOUR_API_KEY', ...options.headers },
  });

  if (response.status === 429) {
    const wait = parseInt(response.headers.get('Retry-After') ?? '60', 10);
    await new Promise(r => setTimeout(r, wait * 1000));
    return apiRequest(url, options); // retry
  }

  if (!response.ok) {
    const { error } = await response.json();
    throw new Error(error);
  }

  return response.json();
}

// Usage
const stats = await apiRequest('https://pixhub.ro/api/stats');

Python with automatic retry

import requests, time

def api_request(path, api_key, retries=3):
    for attempt in range(retries):
        r = requests.get(
            f'https://pixhub.ro/api{path}',
            headers={'X-Api-Key': api_key},
        )
        if r.status_code == 429:
            wait = int(r.headers.get('Retry-After', 60))
            time.sleep(wait)
            continue
        r.raise_for_status()
        return r.json()
    raise RuntimeError('Rate limit not resolved after retries')

stats = api_request('/stats', 'YOUR_API_KEY')
print(stats)