Generation API

Generation API

Text, image, and video generation through OpenAI and Anthropic compatible endpoints.


Overview

The Grid Generation API provides real token-by-token streaming for text — not fake chunking — plus OpenAI-compatible image and video generation endpoints. When you request stream: true, text tokens arrive as they’re generated by the GPU worker in real time.

Base URL: https://api.aipowergrid.io

EndpointFormatMethod
/v1/chat/completionsOpenAIPOST
/v1/responsesOpenAI ResponsesPOST
/v1/messagesAnthropicPOST
/v1/images/generationsOpenAIPOST
/v1/videos/generationsOpenAI (LTX-2.3)POST
/v1/modelsOpenAIGET
/healthGridGET

Authentication

Use either header format:

apikey: your-api-key

or (OpenAI SDK compatible):

Authorization: Bearer your-api-key

Get your API key from a Google-, GitHub-, or wallet-authenticated account at console.aipowergrid.io. Durable keys are not issued anonymously.


Chat Completions (OpenAI Format)

Streaming

curl -N https://api.aipowergrid.io/v1/chat/completions \
  -H "Authorization: Bearer YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-oss-120b",
    "messages": [{"role": "user", "content": "What is AI Power Grid?"}],
    "max_tokens": 256,
    "stream": true
  }'

Response (Server-Sent Events):

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1234,"model":"gpt-oss-120b","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1234,"model":"gpt-oss-120b","choices":[{"index":0,"delta":{"content":"AI"},"finish_reason":null}]}

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1234,"model":"gpt-oss-120b","choices":[{"index":0,"delta":{"content":" Power"},"finish_reason":null}]}

data: [DONE]

Non-Streaming

Set "stream": false (or omit it). Returns a single JSON response after generation completes.

curl https://api.aipowergrid.io/v1/chat/completions \
  -H "Authorization: Bearer YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-oss-120b",
    "messages": [{"role": "user", "content": "Hello"}],
    "max_tokens": 128
  }'

Parameters

ParameterTypeDefaultDescription
modelstringrequiredModel name (see /v1/models)
messagesarrayrequiredChat messages (role + content)
max_tokensint512Maximum tokens to generate
temperaturefloat0.7Randomness (0-2)
top_pfloat0.9Nucleus sampling (0-1)
streamboolfalseEnable SSE streaming
nint1Number of completions

Messages (Anthropic Format)

curl -N https://api.aipowergrid.io/v1/messages \
  -H "x-api-key: YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-oss-120b",
    "messages": [{"role": "user", "content": "What is AI Power Grid?"}],
    "max_tokens": 256,
    "stream": true
  }'

Streaming response uses Anthropic SSE event types: message_start, content_block_start, content_block_delta, content_block_stop, message_delta, message_stop.


Image Generation

curl https://api.aipowergrid.io/v1/images/generations \
  -H "Authorization: Bearer YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "a cat astronaut floating in space",
    "size": "1024x1024"
  }'

Default model: FLUX.2 Klein 4B FP8 (4 steps, sub-second generation).

ParameterTypeDefaultDescription
promptstringrequiredImage description
modelstringFLUX.2 Klein 4B FP8Image model
sizestring1024x1024Width x Height
nint1Number of images (1-4)

List Models

curl https://api.aipowergrid.io/v1/models \
  -H "Authorization: Bearer YOUR_KEY"

Returns models from currently connected streaming workers.


SDK Examples

Python (OpenAI SDK)

from openai import OpenAI
 
client = OpenAI(
    base_url="https://api.aipowergrid.io/v1",
    api_key="your-key",
)
 
# Streaming
stream = client.chat.completions.create(
    model="gpt-oss-120b",
    messages=[{"role": "user", "content": "Hello!"}],
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")
 
# Non-streaming
response = client.chat.completions.create(
    model="gpt-oss-120b",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)

Python (Anthropic SDK)

from anthropic import Anthropic
 
client = Anthropic(
    base_url="https://api.aipowergrid.io",
    api_key="your-key",
)
 
with client.messages.stream(
    model="gpt-oss-120b",
    messages=[{"role": "user", "content": "Hello!"}],
    max_tokens=512,
) as stream:
    for text in stream.text_stream:
        print(text, end="")

JavaScript / TypeScript

import OpenAI from 'openai';
 
const client = new OpenAI({
  baseURL: 'https://api.aipowergrid.io/v1',
  apiKey: 'your-key',
});
 
const stream = await client.chat.completions.create({
  model: 'gpt-oss-120b',
  messages: [{ role: 'user', content: 'Hello!' }],
  stream: true,
});
 
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || '');
}

Rate Limits

Authenticated requests are bucketed by hashed API key; missing or malformed keys fall back to the caller IP. Redis shares the bucket across API processes, with a per-process in-memory fallback during a Redis outage.

EndpointLimit
Chat completions, Responses, Messages30 requests/minute
Image generation10 requests/minute
Video generation4 requests/minute

Worker Den and Customer Credits

Workers accrue den work units for completed text, image, and video jobs. Text den scales with:

  • Output tokens — more tokens = more den
  • Model size — 120B model earns ~60x more than a 3B model
  • Context length — longer prompts cost exponentially more den

Den is supply-side accounting used to divide worker payout periods. It is not a customer balance or transferable asset. Customer requests are metered against a separate USD-denominated account-credit ledger; inspect GET /v1/account/credits for the spendable total.


Check what’s online

List the models currently served by connected workers:

curl https://api.aipowergrid.io/v1/models
{
  "object": "list",
  "data": [
    {"id": "gpt-oss-120b", "object": "model"}
  ]
}

An empty data array means no streaming workers are connected for any model right now — requests will return 503 until a worker comes online.


Worker Connection (For GPU Operators)

Workers connect via WebSocket to receive jobs and stream tokens:

WSS api.aipowergrid.io/v1/workers/ws

Enable streaming mode in the worker:

# Environment variable
GRID_STREAMING=true
 
# Or CLI flag
grid-inference-worker --streaming
 
# Or select during quick setup

See LLM Worker for full setup instructions.


Legacy API — Retired

The poll-based /api/v2/ horde endpoints have been retired. Use the OpenAI-compatible streaming /v1/ endpoints documented above for all integrations.