SafeGen API Docs

Create a free account, generate a v2 API key in your portal, and send prompts to SafeGen for infringement risk scoring and intent-preserving sanitized rewrites.

Quick Start

1. Sign Up

Create a free SafeGen account with 500 monthly API calls.

2. Create Key

Open your account portal and create a v2 API key. Copy it when shown.

3. Call API

Send prompts to /api/v2/analyze using the x-api-key header.

Analyze Prompt

POST /api/v2/analyze

Use this endpoint with your customer API key. Your account's usage limits and permissions apply.

curl -X POST https://safegenapi.com/api/v2/analyze \
  -H "Content-Type: application/json" \
  -H "x-api-key: sg_your_customer_key" \
  -d '{"prompt":"create a louis vuitton style shirt with the exact LV logo"}'

Request Body

prompt

Required string. The user prompt SafeGen should analyze and sanitize if needed.

context

Optional object for the existing unversioned endpoint. It does not grant content permissions.

Decisions

Read the explicit decision. A risk score or returned description alone does not authorize generation.

{
  "prompt": "make a disney princess style design for a kids hoodie",
  "context": {
    "source": "storefront",
    "productType": "hoodie"
  }
}

Response

SafeGen returns structured fields your app can use to approve, rewrite, block, or send a request to review.

{
  "riskScore": 2,
  "flagged": true,
  "decision": "rewrite",
  "reasons": [
    "Potential protected brand or character reference"
  ],
  "sanitizedPrompt": "Create an original fairytale princess-inspired kids hoodie design with a magical castle mood, soft colors, and no protected characters or brand references.",
  "matchedRules": [
    { "term": "disney", "category": "franchise", "risk_level": 2 }
  ],
  "aiFallbackUsed": true
}

Review Decisions

A review or license_required decision requires action before generation. SafeGen does not automatically create a human-review queue. Your application must explain the requirement and provide its own authenticated review or permission workflow. A block decision stops generation even if an unversioned response includes text.

Versioned Text Analysis

Prepared for opt-in rollout; availability must be confirmed before enabling it in production. Existing unversioned customers keep their current response format. To request the stricter contract on POST /api/v2/analyze, send X-SafeGen-Contract: teegen-safety/1.0 alongside your x-api-key. This version uses a nested analysis response.

{
  "prompt": "Two cats gaming in a chair, no text or border",
  "hasReference": true,
  "referenceMode": "edit",
  "generationStyle": "realistic",
  "autoTheme": false,
  "localizeWords": false,
  "language": "en"
}

All fields are required for this opt-in version. Description: nonempty string, at most 10,000 characters. Reference mode: edit, people, inspiration, or prompt_only when hasReference is false. Style: standard, logo, cartoon, realistic. Languages: en, es, zh, pl, uk. Boolean autoTheme permits decoration; localizeWords permits localization of requested wording.

{
  "ok": true,
  "contractVersion": "teegen-safety/1.0",
  "requestId": "sg_example",
  "analysis": {
    "decision": "allow",
    "riskScore": 0,
    "flagged": false,
    "allowed": true,
    "rewriteApplied": false,
    "sanitizedPrompt": null,
    "concerns": [],
    "changes": [],
    "coverage": {"text": "checked", "image": "not_checked"},
    "controls": {
      "hasReference": true,
      "referenceMode": "edit",
      "generationStyle": "realistic",
      "autoTheme": false,
      "localizeWords": false,
      "language": "en"
    },
    "reasons": []
  }
}

allow retains your original description. rewrite supplies a nonempty changed analysis.sanitizedPrompt; other decisions return null. block, review and license_required do not authorize generation. Only real accepted description changes belong in rewrite reporting.

Each concern has code, detail, matchedText and source. Each declared change has before, after and concernCode. Applying the unique, nonoverlapping replacements must exactly reproduce the returned description. Preserve and reapply your original controls independently. A separate semantic check reduces unwanted changes but cannot guarantee generated-image fidelity.

This endpoint checks text only. A reference flag does not submit or inspect an image. Empty descriptions return TEXT_REQUIRED; use a separate image workflow where needed and never label unchecked images cleared by this service.

{
  "ok": false,
  "contractVersion": "teegen-safety/1.0",
  "requestId": "sg_example",
  "error": {
    "code": "REWRITE_VALIDATION_FAILED",
    "message": "The safety rewrite could not be verified to preserve your request.",
    "retryable": true
  }
}

HTTP 400: invalid request, missing text or unsupported version; 401/403: authentication/scope; 429: account/rate limit; 502: invalid analysis or rewrite-validation failure; 503: analysis unavailable. Processing errors are not content blocks. Stop on errors, missing/unknown decisions, malformed JSON, contradictory fields, a wrong version or changed control echoes. Never silently fall back to risk zero. Respect Retry-After where supplied; monthly quota requires account action. Allow at least 75 seconds for this two-stage analysis and provide timeout feedback.

Partner Integrations

Some platform integrations use private server-to-server provisioning and account isolation flows. Those contracts are shared directly with approved partners and are not part of the public API surface.

Limits And Accounts

Free Plan

Free accounts start with 500 monthly API calls for beta testing.

Starter

$29/month for 5,000 monthly prompt checks once the Stripe price ID is configured.

Growth

$99/month for 25,000 monthly prompt checks once the Stripe price ID is configured.

Accounts And Billing

Customer Keys

Logged-in customers only see their own account, usage, request logs, settings, and API keys.

Admin Access

The admin panel is separate and only available through the SafeGen admin login.

Stripe Checkout

Paid upgrade buttons are wired to Stripe Checkout after Stripe secret and price IDs are added to the server env.

Webhook endpoint: https://safegenapi.com/api/stripe/webhook