Image Generation API Now Live: One Key, 5 Models, Pay-as-you-go
Author: CodeGateway team · Tested on May 2026
TL;DR: Adding image generation to your app used to mean three setup hurdles: register with the provider, attach an international credit card, configure a service account. The night you wanted to ship code, you ended up stuck in IAM dashboards instead.
Today CodeGateway ships its image generation API. Your existingsk-cg-key now calls 5 upstream models: Google Imagen 4 (fast / std / ultra), Google Gemini 2.5 Flash Image, OpenAI gpt-image-2 / 1.5. Fully OpenAI Images API compatible. $2 starter credit on signup — about 100 images at the cheapest tier.
Table of Contents
- The one-line announcement
- 5 models + real pricing
- 3-step integration example
- Pick a model by scenario (decision table)
- Compared to going direct to Google / OpenAI
- Real receipt: 4 blog posts, 16 images dogfooded
- FAQ
- Get started
The one-line announcement
CodeGateway proxies both Google and OpenAI image generation upstreams behind a single /v1/images/generations endpoint. Wire-protocol fully OpenAI Images API compatible: any project that already uses the OpenAI SDK can switch by changing OPENAI_BASE_URL to https://api.codegateway.dev/v1 and the key to sk-cg-.... Nothing else changes.
5 models + real pricing
Model ID | Route | Pricing | Strengths |
|---|---|---|---|
| Vertex (Imagen) | $0.02/image | Speed, cost, photoreal/concept illustration |
| Vertex (Imagen) | $0.04/image | Standard quality |
| Vertex (Imagen) | $0.06/image | Premium quality |
| Vertex (Gemini) | per-token (~$0.04–0.08/image) | Text rendering, infographic labels |
| OpenAI | $0.005–$0.211/image (quality × aspect) | UI / cartoon, native 16:9 |
| OpenAI | $0.009–$0.200/image | Same idea, slightly weaker — useful as fallback |
Prices reflect upstream public rates plus CodeGateway's tiered markup (1.5x starter, 1.2x floor). Full pricing: /pricing.
3-step integration example
Step 1: Sign up + get a key (~2 min)
Open https://www.codegateway.dev, sign up with email, Dashboard → API Keys → Create Key. No international card needed, new accounts get a $2 starter credit.
Step 2: Call the API (use any OpenAI SDK)
Python:
from openai import OpenAI
client = OpenAI(
api_key="sk-cg-xxxxx",
base_url="https://api.codegateway.dev/v1"
)
response = client.images.generate(
model="imagen-4.0-generate-001",
prompt="A serene mountain landscape at sunset",
n=1,
response_format="b64_json",
)curl:
curl https://api.codegateway.dev/v1/images/generations \
-H "Authorization: Bearer sk-cg-xxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "imagen-4.0-generate-001",
"prompt": "A serene mountain landscape at sunset",
"n": 1,
"response_format": "b64_json"
}'Node.js:
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "sk-cg-xxxxx",
baseURL: "https://api.codegateway.dev/v1",
});
const response = await client.images.generate({
model: "imagen-4.0-generate-001",
prompt: "A serene mountain landscape at sunset",
n: 1,
response_format: "b64_json",
});Step 3: Save the image
The response's data[0].b64_json is base64-encoded PNG. Decode and save:
import base64
image_data = base64.b64decode(response.data[0].b64_json)
with open("output.png", "wb") as f:
f.write(image_data)Pick a model by scenario (decision table)
Each model has a clear strength zone. Drop this into your spec comments:
Scenario | First pick | Backup | Per-image cost |
|---|---|---|---|
Blog hero (1:1) | Imagen 4 std | Imagen 4 fast | $0.04 / $0.02 |
Blog hero (16:9 horizontal) | gpt-image-2 medium | — | $0.041 |
Body illustration (photoreal) | Imagen 4 fast | Imagen 4 std | $0.02 / $0.04 |
Body infographic (with text labels) | gpt-image-2 medium | Gemini 2.5 Flash Image | $0.041 |
Step / flow diagram | gpt-image-2 medium | Gemini 2.5 Flash Image | $0.041 |
Product UI mockup | gpt-image-2 medium | Gemini | $0.041 |
Pure decoration / abstract / bg | Imagen 4 fast | — | $0.02 |
OG / social card (1.91:1) | gpt-image-2 medium | Imagen 4 std + crop | $0.041 |
Full reasoning + 5 prompts side-by-side in Imagen 4 vs Gemini 2.5 Flash Image vs GPT Image: real-run comparison.
Compared to going direct to Google / OpenAI
Dimension | Direct Google Vertex AI | Direct OpenAI Images | CodeGateway |
|---|---|---|---|
Onboarding | GCP project + service account | OpenAI API account | Email only |
Card | International credit card (GCP billing) | International (OpenAI billing) | Stripe / Alipay / WeChat all work |
Setup time | 30+ min (IAM, quotas, budgets) | 5–10 min | 2 min |
Starter credit | None | None | $2 free |
Protocol | Vertex native (not OpenAI compatible) | OpenAI Images API | OpenAI Images API (one codebase, both providers) |
Cross-provider switch | Re-register + rewrite | Re-register + rewrite | Change the |
Billing | Per-upstream rules | OpenAI rules | Per-upstream + tiered markup (floor 1.2x) |
The core value here: with CodeGateway, "switch model" is one field change; "switch provider" is also one field change. No lock-in — that's the core engineering value of this launch.
Real receipt: 4 blog posts, 16 images dogfooded
Pre-launch, we used this API to generate 16 cover and body images for 4 of our own blog posts:
- 4 heroes via
imagen-4.0-generate-001: $0.16 - 3 photoreal illustrations via
imagen-4.0-fast-generate-001: $0.06 - 9 labeled infographics via
gemini-2.5-flash-image: $0.54 - 4 16:9-horizontal hero regenerations via
gpt-image-2 medium: $0.164
Total: $0.92 / 16 images / 4 mixed models / one key. Full retrospective + reproducible spec in An honest receipt: 16 blog hero images for $0.92 in an hour.
The full generation script is open-sourced at Whitedit/code-gateway-cookbook — generate.py + spec-example.yaml, MIT licensed, copy and adapt.
FAQ
Q: One CodeGateway key really calls all 5 upstream models?
A: Yes. The gateway routes by the model field in the request body — imagen-* / gemini-* go through the Vertex AI route; gpt-image-* goes through OpenAI. Client code doesn't change.
Q: Who owns the generated image's copyright?
A: You do. Both Google and OpenAI's ToS allow commercial use (Google Generative AI Terms / OpenAI Usage Policies). CodeGateway as a gateway makes no claim. But copyright ≠ compliance — don't generate public figures / trademark infringement / platform-policy violations.
Q: Do failed requests get charged?
A: No. 4xx / 5xx responses are not billed. Only successful responses with b64_json or url deduct from balance. Our Sprint 4b dogfood 16 images all passed first try.
Q: Will upstream models go away or be repriced?
A: Upstream Google / OpenAI announce on their own cycle. The CodeGateway gateway tracks upstream — when prices change, our CMS price table updates and new prices appear at /pricing immediately. In-flight requests settle at the price at submission.
Q: How does the tier markup interact with image API usage?
A: Image API spend rolls into your 90-day rolling cumulative spend window — pooled with text API usage. New accounts at 1.5x; cumulative $10 drops to 1.4x; floor at 1.2x. Mixing image + text API hits lower tiers faster than going single-sided. See Tier markup explainer.
Q: Imagen 4's backend really hardcoded to 1024×1024?
A: Yes. The Imagen 4 route is currently fixed at 1024×1024; passing aspect_ratio is "accepted but ignored." For 16:9 / 9:16 horizontal/vertical, switch to gpt-image-2 (OpenAI route natively supports size).
Q: Can existing OpenAI SDK code migrate with zero changes?
A: Yes. Change OPENAI_BASE_URL to https://api.codegateway.dev/v1 and OPENAI_API_KEY to sk-cg-xxx. Application code stays the same. Cursor, Aider, and similar tools work the same way.
Q: What models are coming next?
A: Roadmap: FLUX series, Stable Diffusion 3.x, DALL-E 4 (when OpenAI announces), custom LoRA fine-tune routing. See /roadmap.
Get started
- Sign up: https://www.codegateway.dev (email only, $2 starter credit)
- Pricing: /pricing
- Model catalog: /models
- Open-source generation script: Whitedit/code-gateway-cookbook · image-gen/
Further reading
- Imagen 4 vs Gemini 2.5 Flash Image vs GPT Image — 5-prompt side-by-side comparison
- An honest receipt: 16 blog hero images for $0.92 in an hour — full dogfood retrospective
- Codex CLI vs Claude Code: pick by task — same "pick by scenario" framework
- Top-up and billing guide — Stripe / Alipay / WeChat
- Tier markup explainer — 90-day rolling, floor 1.2x
- Google Cloud — Imagen 4 model card
- OpenAI — Image Generation guide
The job of a tool is to let you configure less and create more. One key, 5 models, $2 starter — collapse "which API to pick, how to sign up, how to bill" into a single motion. The energy you save goes back into the work that actually matters.
