text-to-image
Skill15 starsChanged 58 days agoMITView on GitHub
Generate images from text prompts using 0G Compute Network providers (serviceType: text-to-image). Supports multiple resolutions and batch generation. To edit an existing image rather than generate a new one, use Image Editing (serviceType: image-editing) instead. Discover at runtime; do not hardcode. At last verification 0G mainnet had one text-to-image provider whose default model was z-image-turbo. Testnet had no text-to-image provider — check availability before targeting testnet. Image models are billed per generated image rather than per token. Look at m.pricing?.image…
- Reads credentials
- Sends data out
2 other projects use a version of this.
Adopted by
Most recently taken up by
- meitu/meitu-skillstheir own version, first seen Jun 15, 2026
- alphaqiu/bifang-skillstheir own version, first seen May 2, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- meitu/meitu-skills★ 33same name
- alphaqiu/bifang-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository26 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- agent-accountsSkill
- agent-reputationSkill
- deploy-agentSkill
- interact-agentSkill
- manage-agentSkill
- deploy-contractSkill
- interact-contractSkill
- scaffold-projectSkill
- account-managementSkill
- embeddingsSkill
- fine-tuningSkill
- image-editingSkill
- provider-discoverySkill
- speech-to-textSkill
- streaming-chatSkill
- video-generationSkill
- compute-plus-storageSkill
- storage-plus-chainSkill
- 0g-pc-setupSkill
- 0g-pc-switch-modelSkill
- 0g-pc-uninstallSkill
- download-fileSkill
- merkle-verificationSkill
- upload-fileSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 49
Call processResponse() after every generation
- Very specific: line 50
Use correct processResponse() param order: (providerAddress, chatID, usageData)
- Distinctive: line 52
Start with smaller dimensions for cost-effective testing
- Distinctive: line 60
Use ethers v5 syntax
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Text-to-Image Generation
Metadata
- Category: compute
- SDK:
@0gfoundation/0g-compute-ts-sdk^0.9.0,ethers6.13.1 - Activation Triggers: "generate image", "text-to-image", "image generation", "create image"
Purpose
Generate images from text prompts using 0G Compute Network providers (serviceType: text-to-image).
Supports multiple resolutions and batch generation.
To edit an existing image rather than generate a new one, use
Image Editing (serviceType: image-editing) instead.
Models
Discover at runtime; do not hardcode. At last verification 0G mainnet had one text-to-image
provider whose default model was z-image-turbo. Testnet had no text-to-image provider —
check availability before targeting testnet.
Image models are billed per generated image rather than per token. Look at m.pricing?.image /
m.pricing_usd?.image from getProviderModels().
Prerequisites
- Node.js >= 20
@0gfoundation/0g-compute-ts-sdkandethersinstalled- Funded and acknowledged provider with
text-to-imageservice .envwithPRIVATE_KEY,RPC_URL,PROVIDER_ADDRESS
Quick Workflow
- Initialize broker
- Get service metadata (endpoint, model)
- Build request body with prompt, size, and count
- Generate auth headers with request body (required for signing)
- Make image generation request
- Extract ChatID from
ZG-Res-Keyheader ONLY (no body fallback) - Call
processResponse(providerAddress, chatID)— no usage data needed
Core Rules
ALWAYS
- Include request body when generating auth headers (signing requirement)
- Get ChatID from
ZG-Res-Keyheader only (no body fallback for images) - Call
processResponse()after every generation - Use correct
processResponse()param order:(providerAddress, chatID, usageData) - Acknowledge provider before first use
- Start with smaller dimensions for cost-effective testing
NEVER
- Skip including the body in
getRequestHeaders()for image requests - Try to extract ChatID from the response body (images only have header)
- Generate large batches without checking balance first
- Hardcode private keys
- Use ethers v5 syntax
Code Examples
Basic Image Generation
import { ethers } from 'ethers';
import { createZGComputeNetworkBroker } from '@0gfoundation/0g-compute-ts-sdk';
import * as fs from 'fs';
import 'dotenv/config';
async function generateImage(prompt: string, size = '1024x1024'): Promise<string> {
const provider = new ethers.JsonRpcProvider(process.env.RPC_URL);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider);
const broker = await createZGComputeNetworkBroker(wallet);
const providerAddress = process.env.PROVIDER_ADDRESS!;
const { endpoint, model } = await broker.inference.getServiceMetadata(providerAddress);
const requestBody = { model, prompt, n: 1, size };
// IMPORTANT: Include body for request signing
const headers = await broker.inference.getRequestHeaders(
providerAddress,
JSON.stringify(requestBody),
);
const response = await fetch(`${endpoint}/images/generations`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', ...headers },
body: JSON.stringify(requestBody),
});
const data = await response.json();
const imageUrl = data.data[0].url;
// ChatID from header ONLY for images
const chatID = response.headers.get('ZG-Res-Key') || response.headers.get('zg-res-key');
if (chatID) {
await broker.inference.processResponse(providerAddress, chatID);
}
return imageUrl;
}
// Usage
const imageUrl = await generateImage('A futuristic city skyline at sunset');
console.log('Image URL:', imageUrl);Generate and Save Locally
async function generateAndSave(
prompt: string,
outputPath: string,
size = '512x512',
): Promise<void> {
const provider = new ethers.JsonRpcProvider(process.env.RPC_URL);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider);
const broker = await createZGComputeNetworkBroker(wallet);
const providerAddress = process.env.PROVIDER_ADDRESS!;
const { endpoint, model } = await broker.inference.getServiceMetadata(providerAddress);
const requestBody = { model, prompt, n: 1, size };
const headers = await broker.inference.getRequestHeaders(
providerAddress,
JSON.stringify(requestBody),
);
const response = await fetch(`${endpoint}/images/generations`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', ...headers },
body: JSON.stringify(requestBody),
});
const data = await response.json();
// Process response for fee settlement
const chatID = response.headers.get('ZG-Res-Key') || response.headers.get('zg-res-key');
if (chatID) {
await broker.inference.processResponse(providerAddress, chatID);
}
// Download and save image
const imageData = data.data[0];
if (imageData.b64_json) {
fs.writeFileSync(outputPath, Buffer.from(imageData.b64_json, 'base64'));
} else if (imageData.url) {
const imgResponse = await fetch(imageData.url);
const buffer = Buffer.from(await imgResponse.arrayBuffer());
fs.writeFileSync(outputPath, buffer);
}
console.log(`Image saved to ${outputPath}`);
}Batch Generation
async function batchGenerate(
prompts: string[],
outputDir: string,
size = '512x512',
): Promise<string[]> {
const provider = new ethers.JsonRpcProvider(process.env.RPC_URL);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider);
const broker = await createZGComputeNetworkBroker(wallet);
const providerAddress = process.env.PROVIDER_ADDRESS!;
const { endpoint, model } = await broker.inference.getServiceMetadata(providerAddress);
if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
const results: string[] = [];
for (let i = 0; i < prompts.length; i++) {
console.log(`Generating ${i + 1}/${prompts.length}: "${prompts[i]}"`);
const requestBody = { model, prompt: prompts[i], n: 1, size };
const headers = await broker.inference.getRequestHeaders(
providerAddress,
JSON.stringify(requestBody),
);
const response = await fetch(`${endpoint}/images/generations`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', ...headers },
body: JSON.stringify(requestBody),
});
const data = await response.json();
const chatID = response.headers.get('ZG-Res-Key') || response.headers.get('zg-res-key');
if (chatID) {
await broker.inference.processResponse(providerAddress, chatID);
}
const outputPath = `${outputDir}/image-${i + 1}.png`;
if (data.data[0].url) {
const imgResponse = await fetch(data.data[0].url);
fs.writeFileSync(outputPath, Buffer.from(await imgResponse.arrayBuffer()));
}
results.push(outputPath);
}
return results;
}Error Handling
async function safeGenerateImage(prompt: string, size = '512x512'): Promise<string | null> {
const provider = new ethers.JsonRpcProvider(process.env.RPC_URL);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider);
const broker = await createZGComputeNetworkBroker(wallet);
const providerAddress = process.env.PROVIDER_ADDRESS!;
try {
const { endpoint, model } = await broker.inference.getServiceMetadata(providerAddress);
const requestBody = { model, prompt, n: 1, size };
const headers = await broker.inference.getRequestHeaders(
providerAddress,
JSON.stringify(requestBody),
);
const response = await fetch(`${endpoint}/images/generations`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', ...headers },
body: JSON.stringify(requestBody),
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${await response.text()}`);
}
const data = await response.json();
const chatID = response.headers.get('ZG-Res-Key') || response.headers.get('zg-res-key');
if (chatID) {
await broker.inference.processResponse(providerAddress, chatID);
}
return data.data[0].url || null;
} catch (error) {
console.error('Image generation failed:', error);
return null;
}
}Supported Sizes
| Size | Cost (approx.) | Best For |
256x256 | ~0.001 0G | Thumbnails, testing |
512x512 | ~0.002 0G | Standard images |
1024x1024 | ~0.003 0G | High quality |
Anti-Patterns
// BAD: Missing body in getRequestHeaders for images
const headers = await broker.inference.getRequestHeaders(providerAddress);
// Must include: getRequestHeaders(providerAddress, JSON.stringify(requestBody))
// BAD: Trying to get chatID from response body
const chatID = data.id; // WRONG for images — use header only
// BAD: Large batch without balance check
await batchGenerate(hundredPrompts, './out'); // May run out of funds
// BAD: Hardcoding private keys
const wallet = new ethers.Wallet('0xabc123...', provider); // NEVER do this
// BAD: ethers v5 syntax
const provider = new ethers.providers.JsonRpcProvider(url); // v5!Common Errors & Fixes
| Error | Cause | Fix |
Insufficient balance | Sub-account empty | Transfer more funds |
Invalid request headers | Missing body in header generation | Include body in getRequestHeaders() |
Fee verification failed | Missing chatID | Ensure ZG-Res-Key header exists |
invalid size | Unsupported dimensions | Use 256x256, 512x512, or 1024x1024 |
Related Skills
- Provider Discovery — find image providers
- Account Management — fund accounts
- Compute + Storage — generate and store
References
- Compute Patterns
- Network Config
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

