OpenGen routes image, video, and audio generations across 12 serving providers through one canonical JSON contract. Check gateway liveness, inspect an exact model variant and its published pricing, run a stateless dry-run cost estimate, verify your workspace balance, and submit once with a persisted Idempotency-Key to receive private signed media delivery.
Reviewed 2026-12-02
AGENT PROMPT · PASTE INTO YOUR AGENT OR AUTO-READ
Follow https://opengen.dev/docs/quickstart to run a safe, budget-checked OpenGen generation:
1. Check gateway health at GET https://opengen.dev/health and discover models via GET https://opengen.dev/v1/models (or MCP find_models on https://opengen.dev/mcp/readonly with zero auth).
2. Inspect an exact variant such as openai/gpt-image-2 via GET https://opengen.dev/v1/models/openai/gpt-image-2?operation=text-to-image (or MCP get_model).
3. Estimate cost without spending via POST https://opengen.dev/v1/pricing/estimate (or MCP estimate_cost) and check balance via GET https://opengen.dev/v1/balance (or MCP balance).
4. Ask the user to confirm the exact model, route, and maxCostMicros spend cap before submitting.
5. Persist a unique Idempotency-Key before calling POST https://opengen.dev/v1/generations with Prefer: wait=20 (or MCP generate with waitMs=20000). Never blind-retry on timeout; recover with GET https://opengen.dev/v1/generations/lookup?idempotencyKey=... or job_get({ idempotencyKey }).
OpenGen exposes a single canonical HTTP API, Streamable HTTP MCP servers (/mcp and zero-auth /mcp/readonly), and a zero-dependency portable CLI (@opengen-dev/cli on npm, Node.js 22.12+). Standalone third-party SDK packages are deferred — use standard curl, fetch, Python httpx, MCP, or the CLI directly.
Before submitting paid work, set two environment variables:
OPENGEN_API_URL: defaults to https://opengen.dev (or your self-hosted gateway origin).
OPENGEN_API_KEY: a scoped workspace API key (og_sk_...) created in /app/keys with read and generate scopes, or authenticate interactively via opengen login (OAuth 2.1 DCR + PKCE). Never send a third-party provider key as an OpenGen Bearer token.
1. Check gateway liveness and discover models
Catalog discovery endpoints are unauthenticated, CORS-enabled (Access-Control-Allow-Origin: *), and CDN-cacheable (Cache-Control: public, max-age=60, s-maxage=300). By default, GET /v1/models returns compact summaries (~25 KB across all 54 catalog variants) without embedded input schemas. Use GET /v1/models/{provider}/{model} to fetch one exact variant's full schemas, regional routes, privacy disclosures, deployments, and published pricing in a single call.
export OPENGEN_API_URL="https://opengen.dev"
# Check gateway liveness
curl --fail-with-body "$OPENGEN_API_URL/health"
# Search compact image model summaries
curl --fail-with-body "$OPENGEN_API_URL/v1/models?modality=image&q=gpt-image-2"
# Inspect one exact variant, its schemas, routes, privacy disclosures, and pricing
curl --fail-with-body \
"$OPENGEN_API_URL/v1/models/openai/gpt-image-2?operation=text-to-image"
For full details on collections, filters, and exact variant identity, see Models & Catalog.
2. Estimate cost and check workspace balance
Before spending credit, run a stateless dry-run estimate against POST /v1/pricing/estimate. It validates the exact request payload against the canonical schema, computes per-route estimatedCostMicros and recommendedMaxCostMicros (in integer micro-USD, where 1 USD = 1,000,000 micro-USD), and reports workspaceEligibility when authenticated — without reserving funds or contacting upstream providers.
Every POST /v1/generations call requires a caller-generated Idempotency-Key header (1–200 characters). Persist both the key and the exact request payload into a private per-submission file before sending, and refuse to overwrite an existing unresolved submission record so retries never create a second paid job.
OpenGen is queue-first (202 Accepted by default). For fast image models, add RFC 7240 Prefer: wait=20 (clamped 0–25 seconds; or MCP waitMs=20000 / CLI --wait 20). If the generation finishes with available private delivery within the wait window, OpenGen returns 200 OK with signed output URLs in one round-trip; otherwise it returns 202 Accepted with a Location: /v1/generations/{id} header so you can poll or stream updates.
When a request returns 202 Accepted (or deliveryStatus: "pending"), follow status via Server-Sent Events (GET /v1/generations/{id}/events), compact long-polling (GET /v1/generations/{id}/status), or webhooks (webhookUrl), then fetch the full job via GET /v1/generations/{id} once deliveryStatus is "available" or "partial".
All user outputs remain private to the owning workspace. Each item in outputs[] carries a short-lived, query-free first-party signed URL (https://opengen.dev/media/v1.<payload>.<hmac>.<ext>) served with Cache-Control: private, no-store, Referrer-Policy: no-referrer, and X-Robots-Tag: noindex, nofollow, noarchive. If a link expires, re-read GET /v1/generations/{id} (or MCP job_get) to mint a fresh link while outputs are retained.
# Read full job and fresh signed download URLs
curl --fail-with-body "$OPENGEN_API_URL/v1/generations/$JOB_ID" \
-H "Authorization: Bearer $OPENGEN_API_KEY"
# Download the private output file cleanly (follows 302 for videos and >3.5 MiB images)
curl --fail -L -o output.png "$SIGNED_OUTPUT_URL"
Next steps
Configure workspace API keys, OAuth 2.1 grants, and least-privilege scopes in Authentication & Scopes.