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
| Endpoint | Format | Method |
|---|---|---|
/v1/chat/completions | OpenAI | POST |
/v1/responses | OpenAI Responses | POST |
/v1/messages | Anthropic | POST |
/v1/images/generations | OpenAI | POST |
/v1/videos/generations | OpenAI (LTX-2.3) | POST |
/v1/models | OpenAI | GET |
/health | Grid | GET |
Authentication
Use either header format:
apikey: your-api-keyor (OpenAI SDK compatible):
Authorization: Bearer your-api-keyGet 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
| Parameter | Type | Default | Description |
|---|---|---|---|
model | string | required | Model name (see /v1/models) |
messages | array | required | Chat messages (role + content) |
max_tokens | int | 512 | Maximum tokens to generate |
temperature | float | 0.7 | Randomness (0-2) |
top_p | float | 0.9 | Nucleus sampling (0-1) |
stream | bool | false | Enable SSE streaming |
n | int | 1 | Number 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).
| Parameter | Type | Default | Description |
|---|---|---|---|
prompt | string | required | Image description |
model | string | FLUX.2 Klein 4B FP8 | Image model |
size | string | 1024x1024 | Width x Height |
n | int | 1 | Number 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.
| Endpoint | Limit |
|---|---|
| Chat completions, Responses, Messages | 30 requests/minute |
| Image generation | 10 requests/minute |
| Video generation | 4 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/wsEnable streaming mode in the worker:
# Environment variable
GRID_STREAMING=true
# Or CLI flag
grid-inference-worker --streaming
# Or select during quick setupSee 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.