{
  "openapi": "3.1.0",
  "info": {
    "title": "FreeAIGenerator AI Developer API",
    "version": "1.1",
    "description": "Use a paid workspace API key on your server to generate media, edit an uploaded photo, or continue a text conversation. Obtain the current model and credit quote from the catalog."
  },
  "servers": [
    {
      "url": "https://freeaigenerator.ai/api/v1/developer"
    }
  ],
  "security": [
    {
      "developerKey": []
    }
  ],
  "components": {
    "securitySchemes": {
      "developerKey": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Model": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "mode": {
            "type": "string"
          },
          "version": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "creditCost": {
            "type": "object",
            "properties": {
              "base": {
                "type": "integer"
              },
              "unit": {
                "type": "string"
              }
            }
          }
        }
      },
      "Job": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "mode": {
            "type": "string"
          },
          "outputAssetIds": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "credits": {
            "type": "object"
          },
          "error": {
            "type": [
              "object",
              "null"
            ]
          }
        }
      },
      "Output": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "mimeType": {
            "type": "string"
          },
          "bytes": {
            "type": "integer"
          },
          "downloadUrl": {
            "type": "string",
            "format": "uri-reference"
          },
          "expiresAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      }
    }
  },
  "paths": {
    "/models": {
      "get": {
        "summary": "Read the model catalog",
        "responses": {
          "200": {
            "description": "Collection with model IDs, versions, availability and creditCost.base",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Model"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid or revoked API key"
          },
          "403": {
            "description": "A paid account is required"
          },
          "429": {
            "description": "Rate limit reached"
          }
        }
      }
    },
    "/jobs": {
      "post": {
        "summary": "Submit a generation job or continue a completed text job",
        "responses": {
          "202": {
            "description": "Accepted job with id, status and credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "401": {
            "description": "Invalid or revoked API key"
          },
          "403": {
            "description": "A paid account is required"
          },
          "429": {
            "description": "Rate limit reached"
          },
          "402": {
            "description": "Insufficient credits"
          },
          "409": {
            "description": "The quote or idempotent request changed, or the previous job has not succeeded or used a different model."
          },
          "422": {
            "description": "The model, inputs or conversation length cannot be accepted. For CONTEXT_TOO_LONG, start a new conversation with a shorter summary."
          },
          "400": {
            "description": "Invalid request, missing idempotency key, or unsupported project or private reference asset."
          },
          "404": {
            "description": "The reference asset or previous text job is unavailable to this key."
          },
          "410": {
            "description": "The previous text output is no longer available. Start a new conversation."
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "Idempotency-Key",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "description": "Reuse the same value for retries of the same request."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "mode",
                  "prompt",
                  "modelId",
                  "modelVersion",
                  "quotedCredits"
                ],
                "properties": {
                  "mode": {
                    "type": "string"
                  },
                  "prompt": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 10000
                  },
                  "modelId": {
                    "type": "string"
                  },
                  "modelVersion": {
                    "type": "string"
                  },
                  "quotedCredits": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "parameters": {
                    "type": "object",
                    "description": "Model-specific parameters for one output."
                  },
                  "inputAssetIds": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 1,
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "description": "For qwen-2-1-edit in photo mode, supply the reference ID returned by /assets/uploads with the same key."
                  },
                  "previousJobId": {
                    "type": "string",
                    "pattern": "^job_[0-9a-fA-F]{32}$",
                    "description": "For llm mode, continue a successful job while its text output is available. Use the same key and model."
                  }
                }
              }
            }
          }
        },
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "Edit an uploaded JPEG",
            "source": "api='https://freeaigenerator.ai/api/v1/developer'\nauth=\"Authorization: Bearer ${FREEAIGENERATOR_API_KEY:?}\"\n# Set APPROVED_CREDITS to the integer price you agreed to pay.\nbody=$(curl -fsS -H \"$auth\" \"$api/models\" | jq -ce \\\n  --arg id 'qwen-2-1-edit' --arg prompt 'Change the blue mug to red. Keep the background.' \\\n  --arg asset \"${REFERENCE_ASSET_ID:?}\" --argjson approved \"${APPROVED_CREDITS:?}\" \\\n  '.items[] | select(.id == $id and .status == \"available\" and .creditCost.base == $approved) |\n   {mode, modelId: .id, modelVersion: .version, quotedCredits: $approved, prompt: $prompt, parameters: {}, inputAssetIds: [$asset]}') &&\ncurl -fsS \"$api/jobs\" -H \"$auth\" -H 'Content-Type: application/json' \\\n  -H \"Idempotency-Key: ${JOB_REQUEST_ID:?}\" --data-binary \"$body\""
          },
          {
            "lang": "Shell",
            "label": "Continue a completed text job",
            "source": "api='https://freeaigenerator.ai/api/v1/developer'\nauth=\"Authorization: Bearer ${FREEAIGENERATOR_API_KEY:?}\"\n# Set APPROVED_CREDITS to the integer price you agreed to pay.\nbody=$(curl -fsS -H \"$auth\" \"$api/models\" | jq -ce \\\n  --arg id 'openai-gpt-6-luna' --arg prompt 'What color did I request earlier?' \\\n  --arg parent \"${PREVIOUS_JOB_ID:?}\" --argjson approved \"${APPROVED_CREDITS:?}\" \\\n  '.items[] | select(.id == $id and .status == \"available\" and .creditCost.base == $approved) |\n   {mode, modelId: .id, modelVersion: .version, quotedCredits: $approved, prompt: $prompt, parameters: {}, previousJobId: $parent}') &&\ncurl -fsS \"$api/jobs\" -H \"$auth\" -H 'Content-Type: application/json' \\\n  -H \"Idempotency-Key: ${JOB_REQUEST_ID:?}\" --data-binary \"$body\""
          }
        ]
      }
    },
    "/jobs/{jobId}": {
      "parameters": [
        {
          "in": "path",
          "name": "jobId",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^job_[0-9a-f]{32}$"
          }
        }
      ],
      "get": {
        "summary": "Read a job created with this key",
        "responses": {
          "200": {
            "description": "Job state, output asset IDs and credit accounting",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "401": {
            "description": "Invalid or revoked API key"
          },
          "403": {
            "description": "A paid account is required"
          },
          "429": {
            "description": "Rate limit reached"
          },
          "404": {
            "description": "This key has no job with that ID."
          }
        },
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "Check whether a text job can be used for the next turn",
            "source": "api='https://freeaigenerator.ai/api/v1/developer'\n# JOB_ID is the id from POST /jobs. Repeat this GET later if the job is queued or running.\nPREVIOUS_JOB_ID=$(curl -fsS \"$api/jobs/${JOB_ID:?}\" \\\n  -H \"Authorization: Bearer ${FREEAIGENERATOR_API_KEY:?}\" |\n  jq -er 'select(.status == \"succeeded\" and .mode == \"llm\") | .id')"
          }
        ]
      }
    },
    "/jobs/{jobId}/outputs": {
      "parameters": [
        {
          "in": "path",
          "name": "jobId",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^job_[0-9a-f]{32}$"
          }
        }
      ],
      "get": {
        "summary": "Read private output download links",
        "responses": {
          "200": {
            "description": "Collection containing short-lived download URLs and their expiration times",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Output"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid or revoked API key"
          },
          "403": {
            "description": "A paid account is required"
          },
          "429": {
            "description": "Rate limit reached"
          },
          "404": {
            "description": "This key has no job with that ID."
          }
        },
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "Download the first result of a completed job",
            "source": "origin='https://freeaigenerator.ai'\n# Set OUTPUT_FILE to a new local file path. Rerun the lookup if the download link expires.\nurl=$(curl -fsS \"$origin/api/v1/developer/jobs/${JOB_ID:?}/outputs\" \\\n  -H \"Authorization: Bearer ${FREEAIGENERATOR_API_KEY:?}\" |\n  jq -er --arg origin \"$origin\" '.items[0].downloadUrl | strings |\n    if startswith(\"https://\") then .\n    elif startswith(\"/\") and (startswith(\"//\") | not) then $origin + .\n    else empty end') &&\ncurl --proto '=https' -fsS \"$url\" --output \"${OUTPUT_FILE:?}\""
          }
        ]
      }
    },
    "/assets/uploads": {
      "post": {
        "summary": "Upload one private reference image, up to 10 MiB",
        "parameters": [
          {
            "in": "header",
            "name": "Idempotency-Key",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "description": "Reuse the same value for retries of the same request."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "image/jpeg": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/png": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/webp": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Reference ready. Pass its id in inputAssetIds.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "id"
                  ],
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          },
          "413": {
            "description": "Image exceeds the upload limit."
          },
          "415": {
            "description": "Unsupported image format."
          }
        },
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "Upload a JPEG and capture its asset ID",
            "source": "api='https://freeaigenerator.ai/api/v1/developer'\n# Keep UPLOAD_REQUEST_ID for retries of this same file.\nREFERENCE_ASSET_ID=$(curl -fsS \"$api/assets/uploads\" \\\n  -H \"Authorization: Bearer ${FREEAIGENERATOR_API_KEY:?}\" \\\n  -H \"Idempotency-Key: ${UPLOAD_REQUEST_ID:?}\" \\\n  -H 'Content-Type: image/jpeg' --data-binary \"@${JPEG_PATH:?}\" | jq -er '.id')"
          }
        ]
      }
    }
  }
}
