API Docs

API Documentation

Welcome to the Melancholy AI API. Build powerful applications using our state-of-the-art models for text, image, and video generation.

Overview

The Melancholy AI API provides a unified interface to access multiple leading AI models, including OpenAI's GPT, Anthropic's Claude, Google's Gemini, xAI's Grok, Mistral, Meta Llama, and more.

Our API follows standard REST principles and returns JSON-encoded responses. It is designed to be highly compatible with existing OpenAI SDKs to make migration as seamless as possible.

Base URL

All API requests should be made relative to the following base URL:

https://app.melancholyai.fun/api/v1/

Authentication

Learn how to authenticate your API requests.

Bearer Token

The Melancholy API uses Bearer Tokens for authentication. You can find your API key in the API Key section of your dashboard.

You must include your API key in the Authorization header of every request.

HTTP
Authorization: Bearer YOUR_API_KEY

Chat Completions

Generate text and converse with cutting-edge models.

Create chat completion

Creates a model response for the given chat conversation.

POST /chat/completions

Request Body

Parameter Type Description
model Required string ID of the model to use (e.g., gpt-4o, qwen3-max). See your dashboard for the full list of supported models.
messages Required array A list of messages comprising the conversation so far. Each item should have a role (e.g., system, user, assistant) and content.
stream boolean If set, partial message deltas will be sent in Server-Sent Events (SSE). Defaults to false.

Standard Request Example (Python)

Python
import requests

response = requests.post(
    url="https://app.melancholyai.fun/api/v1/chat/completions/",
    headers={
        "Authorization": "Bearer YOUR_API_KEY",
        "Content-Type": "application/json"
    },
    json={
        "model": "qwen3-max",
        "messages": [
            {"role": "user", "content": "Hello, how are you?"}
        ]
    }
)

print(response.json())

Streaming Request Example (Python)

For building real-time UI applications, enable streaming to receive tokens as they are generated.

Python
import requests

response = requests.post(
    url="https://app.melancholyai.fun/api/v1/chat/completions/",
    headers={
        "Authorization": "Bearer YOUR_API_KEY",
        "Content-Type": "application/json"
    },
    json={
        "model": "qwen3-max",
        "messages": [
            {"role": "user", "content": "Write a short poem."}
        ],
        "stream": True
    },
    stream=True
)

for chunk in response.iter_lines():
    if chunk:
        print(chunk.decode('utf-8'))

Image Generation

Create images from text prompts using DALL-E 3, Flux, and more.

Create Image

Creates an image given a prompt.

POST /images/generations

Request Example (Python)

Python
import requests

response = requests.post(
  url="https://app.melancholyai.fun/api/v1/images/generations/",
  headers={
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
    "User-Agent": "MelancholyAI-Client" 
  },
  json={
    "prompt": "A futuristic city at sunset with flying cars",
    "n": 1,
    "model": "flux",
    "size": "1024x1024"
  }
)

print(response.json())

Video Generation

Generate high-quality videos using models like Google Veo.

Create Video Task

Video generation is fully asynchronous. You first submit a task, which returns a Task ID. You then poll the status of this task until it is completed.

POST /video/generations

Create Task Example (Python)

Python
import requests

response = requests.post(
  url="https://app.melancholyai.fun/api/v1/video/generations/",
  headers={
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
    "User-Agent": "MelancholyAI-Client" 
  },
  json={
    "model": "google/veo-3-1-fast",
    "input": {
        "prompt": "A drone shot flying over a tropical beach with crystal clear water",
        "aspect_ratio": "LANDSCAPE",
        "video_generate_type": "text_to_video"
    }
  }
)

print(response.json())
# Will return: { "task_id": "YOUR_TASK_ID" }

Check Task Status

Use the Task ID obtained from the previous request to poll the status.

GET /video/generations/{task_id}

Check Status Example (Python)

Python
import requests
import time

task_id = "YOUR_TASK_ID"

while True:
    response = requests.get(
        url=f"https://app.melancholyai.fun/api/v1/video/generations/{task_id}",
        headers={
            "Authorization": "Bearer YOUR_API_KEY",
            "Content-Type": "application/json",
            "User-Agent": "MelancholyAI-Client"
        }
    )
    
    data = response.json()
    status = data.get("status")
    
    if status == "COMPLETED":
        print("Video generated successfully!")
        print("Video URL:", data.get("video_url"))
        break
    elif status == "FAILED":
        print("Generation failed:", data.get("error"))
        break
        
    print(f"Status: {status}... checking again in 5 seconds")
    time.sleep(5)