LogoApinfer Docs

API Guide

Integrate Apinfer AI models into your applications

API Guide

Base URL

https://apinfer.com/api/v1

Authentication

Include your API key in the Authorization header:

Authorization: Bearer YOUR_API_KEY

Generate Image

Endpoint: POST /generate-image

Request:

{
  "prompt": "A beautiful sunset over mountains",
  "negative_prompt": "blurry, low quality",
  "width": 1024,
  "height": 1024,
  "seed": 12345,
  "model": "qwen-image"
}

Generate Video (Async)

Endpoint: POST /api/generate-video then poll GET /api/generations/{id}

  1. Enqueue video generation

Request:

{
  "image": "data:image/png;base64,<base64_data>",
  "prompt": "clouds moving, leaves swaying",
  "negative_prompt": "",
  "video_length": 60,
  "fps": 20,
  "width": 1280,
  "height": 720,
  "model": "wan2.2"
}

Response (202):

{
  "success": true,
  "data": { "job_id": "<id>", "status": "queued", "credit_cost": 12.34 },
  "message": "Video generation enqueued using model wan2.2"
}
  1. Poll job status

Request: GET /api/generations/<job_id>

Responses:

  • Pending:
{ "success": true, "data": { "status": "queued" } }
  • Succeeded (credits are deducted here):
{
  "success": true,
  "data": {
    "status": "succeeded",
    "type": "video",
    "model": "wan2.2",
    "result": { "video": "<base64>", "seed": 12345 },
    "credit_cost": 12.34
  }
}
  • Failed:
{ "success": false, "error": "Generation failed", "message": "..." }

cURL

# Enqueue
curl -X POST "https://apinfer.com/api/generate-video" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "image": "data:image/png;base64,<base64>",
    "prompt": "clouds moving, leaves swaying",
    "video_length": 60,
    "fps": 20,
    "width": 1280,
    "height": 720,
    "model": "wan2.2"
  }'

# Poll
curl -X GET "https://apinfer.com/api/generations/<job_id>" \
  -H "Authorization: Bearer YOUR_API_KEY"

Python

import requests, time

enqueue = requests.post(
    "https://apinfer.com/api/generate-video",
    headers={"Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json"},
    json={
        "image": "data:image/png;base64,<base64>",
        "prompt": "clouds moving, leaves swaying",
        "video_length": 60,
        "fps": 20,
        "width": 1280,
        "height": 720,
        "model": "wan2.2"
    }
)
job_id = enqueue.json()["data"]["job_id"]

for _ in range(60):
    r = requests.get(
        f"https://apinfer.com/api/generations/{job_id}",
        headers={"Authorization": "Bearer YOUR_API_KEY"}
    )
    d = r.json()
    s = d.get("data", {}).get("status")
    if s in ("queued", "processing"):
        time.sleep(1)
        continue
    if s == "succeeded":
        print("video base64:", d["data"]["result"]["video"])
    else:
        print("failed:", d.get("message") or d.get("error"))
    break

JavaScript

// Enqueue
const q = await fetch('https://apinfer.com/api/generate-video', {
  method: 'POST',
  headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' },
  body: JSON.stringify({ image: 'data:image/png;base64,<base64>', prompt: 'clouds moving', video_length: 60, fps: 20, width: 1280, height: 720, model: 'wan2.2' })
});
const qd = await q.json();

// Poll
async function poll() {
  const r = await fetch('https://apinfer.com/api/generations/' + qd.data.job_id, {
    headers: { 'Authorization': 'Bearer YOUR_API_KEY' }
  });
  return r.json();
}

let s;
do {
  const d = await poll();
  s = d?.data?.status;
  if (s === 'queued' || s === 'processing') await new Promise(r => setTimeout(r, 1000));
  else if (s === 'succeeded') console.log('video:', d.data.result.video);
  else console.error('failed:', d?.message || d?.error);
} while (s === 'queued' || s === 'processing');

Response:

{
  "success": true,
  "data": {
    "images": ["base64_image_data"],
    "seed": 12345,
    "model": "qwen-image",
    "processing_time": 2500,
    "credit_cost": 10
  },
  "message": "Successfully generated 1 image(s)"
}

Error Handling

401 Unauthorized:

{
  "success": false,
  "error": "Invalid or expired API key",
  "message": "Please check your API key and try again"
}

402 Insufficient Credits:

{
  "success": false,
  "error": "Insufficient credits",
  "message": "You need 10 credits for 1024x1024 image. You have 5 credits."
}

Code Examples

cURL

curl -X POST "https://apinfer.com/api/v1/generate-image" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A beautiful sunset over mountains",
    "width": 1024,
    "height": 1024,
    "model": "qwen-image"
  }'

Python

import requests

response = requests.post(
    "https://apinfer.com/api/v1/generate-image",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json={
        "prompt": "A beautiful sunset over mountains",
        "width": 1024,
        "height": 1024,
        "model": "qwen-image"
    }
)

data = response.json()
if data["success"]:
    print(f"Generated image with {data['data']['credit_cost']} credits")
else:
    print(f"Error: {data['message']}")

JavaScript

const response = await fetch('https://apinfer.com/api/v1/generate-image', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    prompt: 'A beautiful sunset over mountains',
    width: 1024,
    height: 1024,
    model: 'qwen-image'
  })
});

const data = await response.json();
if (data.success) {
  console.log(`Generated image with ${data.data.credit_cost} credits`);
} else {
  console.error(`Error: ${data.message}`);
}

API Key Management

Creating API Keys

  1. Go to your dashboard
  2. Navigate to API Keys
  3. Click "Create New API Key"
  4. Enter a name and click "Generate Key"
  5. Copy and store securely

Security

  • Store API keys in environment variables
  • Never commit keys to version control
  • Rotate keys regularly
  • Monitor usage in dashboard

Support