ByteDance Seedream 5 Image Generation API

ByteDance's most advanced AI image generation model with professional-grade quality and batch processing capabilities

✓ Batch generation up to 15 images

✓ Ultra-high resolution (2K)

✓ Advanced style control

✓ Smart prompt enhancement

✓ Multiple aspect ratios

✓ Fast generation

✓ Professional quality

Autenticazione

Per accedere a Seedream 5 API tramite l'API di Doitong, usa la tua chiave API Doitong. Includila nella mutation GraphQL o negli header della REST API.

Importante: Mantieni la tua chiave API Doitong al sicuro e non esporla mai nel codice client-side. Effettua sempre le chiamate API dal tuo server backend.
// GraphQL Header
{
  "Authorization": "Bearer YOUR_API_KEY"
}

// REST Header
"X-API-Key": "YOUR_API_KEY"

Guida rapida

Inizia a usare Seedream 5 API in pochi minuti. Segui questi semplici passaggi per generare il tuo primo text to image.

Passaggio 1: Ottieni la tua chiave API

Registrati per un account Doitong e vai alla tua dashboard per generare una chiave API.

Passaggio 2: Effettua la tua prima richiesta

Usa uno degli esempi di codice qui sotto per effettuare la tua prima chiamata API.

curl -X POST https://api.doitong.com/graphql \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "query": "mutation Generate($input: GenerateInput!) { generate(input: $input) { id status type provider url metadata creditCost } }",
    "variables": {
      "input": {
        "type": "IMAGE",
        "provider": "seedream",
        "input": {
          "text": "A futuristic city with flying cars and neon lights"
        },
        "options": {
          "width": 1024,
          "height": 1024
        }
      }
    }
  }'
const response = await fetch('https://api.doitong.com/graphql', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer YOUR_API_KEY'
  },
  body: JSON.stringify({
    query: `
      mutation GenerateImage($input: ImageGenerationInput!) {
        generateImage(input: $input) {
          id
          url
          width
          height
        }
      }
    `,
    variables: {
      input: {
        service: 'seedream',
        prompt: 'A futuristic city with flying cars and neon lights',
        width: 1024,
        height: 1024
      }
    }
  })
});

const data = await response.json();
console.log('Image:', data.data.generateImage);
import requests
import json

url = "https://api.doitong.com/graphql"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer YOUR_API_KEY"
}

query = """
mutation Generate($input: GenerateInput!) {
  generate(input: $input) {
    id
    status
    type
    provider
    url
    metadata
    creditCost
  }
}
"""

variables = {
    "input": {
        "type": "IMAGE",
        "provider": "seedream",
        "input": {
            "text": "A futuristic city with flying cars and neon lights"
        },
        "options": {
            "width": 1024,
            "height": 1024
        }
    }
}

response = requests.post(url, json={
    "query": query,
    "variables": variables
}, headers=headers)

data = response.json()
print("Result:", data["data"]["generate"])
mutation Generate($input: GenerateInput!) {
  generate(input: $input) {
    id
    status
    type
    provider
    url
    metadata
    creditCost
    createdAt
  }
}

# Variables
{
  "input": {
    "type": "IMAGE",
    "provider": "seedream",
    "input": {
      "text": "A futuristic city with flying cars and neon lights"
    },
    "options": {
      "width": 1024,
      "height": 1024,
      "version": "seedream-4.0",
      "quality": "high"
    }
  }
}

Prezzi

Seedream 5 API utilizza un modello di prezzo basato su crediti. I crediti vengono consumati in base alla complessità e alla durata del contenuto generato.

Funzionalità Crediti Descrizione
Risoluzione Standard 10-20 Crediti Da 512x512 a 1024x1024 pixel
Alta Risoluzione 30-50 Crediti 2048x2048 pixel e oltre

Endpoint API

Seedream 5 API è disponibile tramite il nostro endpoint GraphQL unificato.

Endpoint GraphQL

POST https://api.doitong.com/graphql

Endpoint REST

POST https://api.doitong.com/v1/text_to_image

Parametri

Parametri disponibili per le richieste Seedream 5 API:

Parametro Tipo Obbligatorio Descrizione
service Stringa Yes Identificatore del servizio: "seedream"
prompt Stringa Yes Descrizione testuale di cosa generare
width Intero No Larghezza immagine in pixel (predefinito: 1024)
height Intero No Altezza immagine in pixel (predefinito: 1024)
version Stringa No Model version: "seedream-4.0"
webhookUrl Stringa No URL per ricevere le notifiche di completamento

Formato della risposta

Tutte le risposte API seguono un formato coerente:

Risposta di successo

{
  "data": {
    "generateimage": {
      "id": "abc123xyz",
      "status": "processing",
      "url": null,
      "webhookUrl": "https://your-webhook.com/callback",
      "createdAt": "2024-01-01T00:00:00Z"
    }
  }
}

Risposta completata

{
  "data": {
    "generateimage": {
      "id": "abc123xyz",
      "status": "completed",
      "url": "https://cdn.doitong.com/outputs/abc123xyz.jpg",
      "duration": null,
      "createdAt": "2024-01-01T00:00:00Z"
    }
  }
}

Gestione degli errori

L'API utilizza codici di stato HTTP standard e restituisce messaggi di errore dettagliati.

Codici di errore comuni

Codice di stato Tipo di errore Descrizione
400 Bad Request Invalid parameters or malformed request
401 Unauthorized Missing or invalid API key
402 Payment Required Insufficient credits
429 Too Many Requests Rate limit exceeded
500 Internal Server Error Server error, please retry

Formato risposta di errore

{
  "errors": [
    {
      "message": "Insufficient credits for this operation",
      "extensions": {
        "code": "INSUFFICIENT_CREDITS",
        "creditsRequired": 100,
        "creditsAvailable": 50
      }
    }
  ]
}

Webhook

Ricevi notifiche in tempo reale quando la generazione di text to image è completata.

Configurazione dei Webhook

Include a <code>webhookUrl</code> parameter in your request to receive a POST notification when processing is complete.

Payload del Webhook

{
  "id": "abc123xyz",
  "status": "completed",
  "url": "https://cdn.doitong.com/outputs/abc123xyz.jpg",
  "service": "seedream",
  "createdAt": "2024-01-01T00:00:00Z",
  "completedAt": "2024-01-01T00:01:00Z",
  "metadata": {
    "duration": null,
    "width": 1920,
    "height": 1080
  }
}

Sicurezza dei Webhook

Tutte le richieste webhook includono un header di firma per la verifica:

X-Doitong-Signature: sha256=abc123...

Limiti di frequenza

Per garantire un utilizzo equo e la stabilità del sistema, si applicano i seguenti limiti di frequenza:

Piano Richieste/Minuto Processi simultanei Limite giornaliero
Gratis 10 1 100
Starter 30 3 1,000
Pro 60 10 10,000
Enterprise Personalizzato Personalizzato Illimitato
Header dei limiti di frequenza: Controlla gli header della risposta per lo stato attuale dei limiti:
  • X-RateLimit-Limit: Maximum requests per window
  • X-RateLimit-Remaining: Requests remaining
  • X-RateLimit-Reset: Window reset timestamp

Best practice

1. Ottimizza i tuoi prompt

Scrivi prompt chiari e descrittivi per ottenere i migliori risultati:

  • Be specific about visual elements, style, and mood
  • Include details about lighting, camera angles, and composition
  • Avoid contradictory or impossible requests

2. Gestisci l'elaborazione asincrona

La generazione è asincrona. Implementa un sistema di polling o i webhook:

// Polling example
async function pollStatus(jobId) {
  let status = 'processing';
  while (status === 'processing') {
    await sleep(2000); // Wait 2 seconds
    const result = await checkJobStatus(jobId);
    status = result.status;
  }
  return result;
}

3. Recupero dagli errori

Implementa una logica di retry con backoff esponenziale:

async function retryWithBackoff(fn, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await fn();
    } catch (error) {
      if (i === maxRetries - 1) throw error;
      await sleep(Math.pow(2, i) * 1000);
    }
  }
}

4. Monitora l'uso dei crediti

Tieni traccia del consumo di crediti per evitare interruzioni:

  • Check credit balance before large batch operations
  • Set up alerts for low credit thresholds
  • Implement credit-aware request queuing

Pronto per iniziare?

Unisciti a migliaia di sviluppatori che usano Seedream 5 API per creare contenuti incredibili

Ottieni chiave API Vedi i prezzi