Endpoints

POST — Generate Image

Submit an image generation job. Returns a job_id immediately — poll the Job Status endpoint until complete.

Overview

POSThttps://api.sharkapi.dev/v1/generate

This endpoint is fully async. It does not wait for image generation to complete. Instead, it returns a job_id that you use to poll for the result every 2 seconds.

Your wallet is only charged once a job reaches status: "complete" and an image_url is returned. Failed or moderated jobs are never charged.

Request

Headers

ParameterTypeRequiredDescription
AuthorizationstringRequiredBearer token. Format: "Bearer sk_live_..."
Content-TypestringRequired"application/json"

Body parameters

ParameterTypeRequiredDescription
promptstringRequiredText description of the image to generate. Max 2000 characters.
modestringRequiredGeneration mode. Must be "1k" (1024×1024) or "2k" (2048×2048).
imagestringOptionalBase64-encoded source image for image-to-image generation. JPEG or PNG, max 10MB.
image_strengthnumberOptionalHow strongly the source image influences the output. Range 0.0–1.0. Default: 0.5.

Response

HTTP 202 Accepted on success.

ParameterTypeRequiredDescription
job_idstringRequiredUnique identifier for this job. Use with GET /v1/jobs/:id to poll status.
statusstringRequiredInitial job status. Always "queued" on creation.
estimated_coststringRequiredEstimated cost of this job (e.g. "$0.30"). Final cost confirmed on completion.
poll_urlstringRequiredConvenience URL for polling this job's status.
created_atstringRequiredISO 8601 timestamp of job creation.
Response
json
{
  "job_id":         "job_8f2a9d3c",
  "status":         "queued",
  "estimated_cost": "$0.02",
  "poll_url":       "https://api.sharkapi.dev/v1/jobs/job_8f2a9d3c",
  "created_at":     "2024-01-15T10:23:44Z"
}

Modes

mode: "1k"$0.01

1024 × 1024

Fast standard resolution. Great for prototyping and high-volume use.

mode: "2k"$0.02

2048 × 2048

High-resolution output. Ideal for print and detail-critical applications.

Image input (img2img)

Pass a Base64-encoded image in the image field to guide generation using a reference image. Supported formats: JPEG, PNG. Maximum size: 10MB.

The image_strength parameter (0.0–1.0) controls how much the source image influences the output. Higher values preserve more of the original image.

Image-to-image request
bash
curl -X POST https://api.sharkapi.dev/v1/generate \
  -H "Authorization: Bearer sk_live_••••••••" \
  -H "Content-Type: application/json" \
  -d '{
    "mode": "2k",
    "prompt": "Transform into a watercolor painting",
    "image": "'"$(base64 -w 0 ./input.jpg)"'",
    "image_strength": 0.6
  }'

Examples

Text-only (cURL)

bash
curl -X POST https://api.sharkapi.dev/v1/generate \
  -H "Authorization: Bearer sk_live_••••••••" \
  -H "Content-Type: application/json" \
  -d '{
    "mode": "2k",
    "prompt": "A great white shark swimming through bioluminescent waters, cinematic, 8K"
  }'

JavaScript / Node.js

javascript
async function generateImage(prompt, mode = "2k") {
  const res = await fetch("https://api.sharkapi.dev/v1/generate", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${process.env.SHARKAPI_TOKEN}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ prompt, mode }),
  });

  if (!res.ok) {
    const err = await res.json();
    throw new Error(err.error.message);
  }

  const { job_id } = await res.json();
  return job_id;
}

Errors

ParameterTypeRequiredDescription
400 Bad RequestHTTPOptionalInvalid or missing request body fields.
402 Payment RequiredHTTPOptionalInsufficient wallet balance. Top up before retrying.
403 ForbiddenHTTPOptionalToken is revoked or account is suspended.
422 Unprocessable EntityHTTPOptionalPrompt or image failed content moderation check.
429 Too Many RequestsHTTPOptionalRate limit exceeded. Slow down your requests.
503 Service UnavailableHTTPOptionalGeneration service is temporarily unavailable. Retry after 30 seconds.