Skip to main content

Image Generation

This guide walks you through generating images with the neuroflash API — from checking your quota to generating images and tracking usage.

What you'll build

By the end of this guide, you will:

  • Authenticate with the neuroflash API
  • Fetch your workspace
  • Check your workspace's image generation quota
  • List available image models
  • Generate an image using the image generation endpoint
  • Track usage deducted from your quota

Prerequisites

  • A neuroflash account with API access and image generation credits
  • Your client_id and client_secret (see Authentication)

Step 1: Authenticate

curl -X POST https://id.neuroflash.com/oauth/v2/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_id=YOUR_CLIENT_ID" \
-d "client_secret=YOUR_CLIENT_SECRET" \
-d "scope=openid"

Step 2: Get Your Workspace

Fetch your available workspaces and select the first one. The workspace ID is required for quota and usage calls:

curl "https://app.neuroflash.com/api/workspace-service/v1/workspaces" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Step 3: Check Your Quota

Before generating images, check how many credits you have available:

curl "https://app.neuroflash.com/api/usage-service/v1/workspaces/{workspace_id}/quotas?usageTypeKey=images" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Response:

{
"data": [
{
"id": "quota-abc-123",
"workspaceId": "your-workspace-id",
"usageTypeKey": "images",
"bonusAmount": 0,
"spilloverAmount": 0,
"usedAmount": 12,
"usedAmountDaily": 3,
"availableAmount": 88,
"limitAmount": 100,
"limitAmountDaily": 50,
"fairUseLimitReached": false
}
],
"page": {
"size": 20,
"totalElements": 1,
"totalPages": 1,
"currentPage": 1
}
}

Step 4: List Image Models

Fetch the available image generation models to see which ones you can use:

curl "https://app.neuroflash.com/api/ds-prototypes/image_generation/models" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "x-workspace-id: YOUR_WORKSPACE_ID"

Response:

[
{
"id": "nano-banana-2",
"name": "Nano Banana 2",
"provider": "fal.ai",
"description": "Fast and efficient image generation model",
"capabilities": ["text2image", "image2image"],
"max_images": 4,
"aspect_ratios": ["21:9", "16:9", "3:2", "4:3", "5:4", "1:1", "4:5", "3:4", "2:3", "9:16"],
"output_formats": ["jpeg", "png", "webp"],
"allowed": true,
"order": 1
}
]

Step 5: Generate an Image

Use the image generation endpoint with a text prompt:

curl -X POST "https://app.neuroflash.com/api/ds-prototypes/image_generation/" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "x-workspace-id: YOUR_WORKSPACE_ID" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A professional hero image for a blog post about sustainable technology. Modern, clean design with green and blue tones.",
"model": "nano-banana-2",
"num_images": 1,
"aspect_ratio": "16:9",
"output_format": "png"
}'

Response:

{
"images": [
{
"url": "https://storage.example.com/generated/image-abc123.png",
"content_type": "image/png",
"width": 1024,
"height": 576,
"image_id": "3c4ce5dc-00be-4451-9559-0324f9fc4c88"
}
],
"prompt": "A professional hero image for a blog post about sustainable technology...",
"batch_id": "6872b83c-901e-47c5-8b90-96a3d9839d06"
}

Step 6: Track Usage

After image generation, usage is automatically deducted from your workspace quota. You can verify by checking the quota again:

curl "https://app.neuroflash.com/api/usage-service/v1/workspaces/{workspace_id}/quotas?usageTypeKey=images" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Usage Tracking

Image generation automatically records usage events. The usedAmount on your quota increases with each generation, and usedAmountDaily resets daily.

Step: Edit an existing image (image-to-image)

The /edit endpoint re-generates an image from a source image plus a prompt. The source is identified by the relative path returned in output_image_url from /history — not an absolute URL.

Use relative paths from history, not absolute URLs

Pass the relative path (e.g. /api/ds-prototypes/image_generation/{image_id}/view) from the /history response. Absolute URLs cause a 500 error because the image service resolves these paths internally.

Typical flow:

  1. GET /api/ds-prototypes/history and pick an item
  2. Extract its output_image_url — a relative path
  3. Pass that path in image_urls to POST /edit
curl -X POST "https://app.neuroflash.com/api/ds-prototypes/edit" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "x-workspace-id: YOUR_WORKSPACE_ID" \
-H "Content-Type: application/json" \
-d '{
"prompt": "Make the sky a deep sunset orange",
"image_urls": ["/api/ds-prototypes/image_generation/b64b61f6-a7d2-4fa0-9f88-289dae46c41f/view"]
}'

Step: Delete an image

Use the image_id from the output_image_id field of the history response — not the batch_id.

curl -X DELETE "https://app.neuroflash.com/api/ds-prototypes/history/{image_id}" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "x-workspace-id: YOUR_WORKSPACE_ID"

Next Steps