Use Blackbox AI’s rich API for Chat, Image, and Video models to directly integrate the power of AI into your applications.

OpenAI Compatibility

Blackbox AI’s API endpoints for chat, images, and video are fully compatible with OpenAI’s API. If you have an application that uses OpenAI’s client libraries, you can configure it to point to Blackbox AI’s API servers and use our models.

Configuring OpenAI to use Blackbox AI’s API

Pass your Blackbox AI API key to the api_key option and set the base_url to https://api.blackbox.ai:
import os
import openai

client = openai.OpenAI(
    api_key=os.environ.get("BLACKBOX_API_KEY"),
    base_url="https://api.blackbox.ai",
)
You can find your API key in your Blackbox AI account settings.

Querying a Chat Model

Query one of our chat models, like GPT-4:
import os
import openai

client = openai.OpenAI(
    api_key=os.environ.get("BLACKBOX_API_KEY"),
    base_url="https://api.blackbox.ai",
)

response = client.chat.completions.create(
    model="blackboxai/openai/gpt-4",
    messages=[
        {
            "role": "system",
            "content": "You are a helpful assistant.",
        },
        {
            "role": "user",
            "content": "What is the capital of France?",
        },
    ],
)

print(response.choices[0].message.content)
Output:
The capital of France is Paris.

Streaming a Chat Response

Use streaming to receive responses incrementally:
import os
import openai

client = openai.OpenAI(
    api_key=os.environ.get("BLACKBOX_API_KEY"),
    base_url="https://api.blackbox.ai",
)

stream = client.chat.completions.create(
    model="blackboxai/openai/gpt-4",
    messages=[
        {
            "role": "system",
            "content": "You are a helpful assistant.",
        },
        {"role": "user", "content": "Explain quantum computing briefly"},
    ],
    stream=True,
)

for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="", flush=True)

Image Generation

Generate images from text prompts using our image models:
from openai import OpenAI
import os

client = OpenAI(
    api_key=os.environ.get("BLACKBOX_API_KEY"),
    base_url="https://api.blackbox.ai",
)

response = client.chat.completions.create(
    model="blackboxai/black-forest-labs/flux-pro",
    messages=[
        {
            "role": "user",
            "content": "A futuristic cityscape at sunset",
        }
    ],
)

print(response.choices[0].message.content)  # URL to the generated image
The response content will be a URL to the generated image.
Generated Image

Video Generation

Generate videos from text prompts using our video models:
from openai import OpenAI
import os

client = OpenAI(
    api_key=os.environ.get("BLACKBOX_API_KEY"),
    base_url="https://api.blackbox.ai",
)

response = client.chat.completions.create(
    model="blackboxai/google/veo-2",
    messages=[
        {
            "role": "user",
            "content": "A Tesla car driving on a highway at dusk",
        }
    ],
)

print(response.choices[0].message.content)  # URL to the generated video
The response content will be a URL to the generated video.