Stable Diffusion API

व्यापक कस्टमाइज़ेशन के साथ उद्योग मानक ओपन-सोर्स मॉडल

✓ ओपन सोर्स

✓ कस्टमाइज़ करने योग्य

✓ ControlNet

✓ LoRA सपोर्ट

प्रमाणीकरण

Doitong API के माध्यम से Stable Diffusion को एक्सेस करने के लिए, अपनी Doitong API key का उपयोग करें। इसे GraphQL mutation या REST API headers में शामिल करें।

महत्वपूर्ण: अपनी Doitong API key को सुरक्षित रखें और इसे कभी भी क्लाइंट-साइड कोड में सार्वजनिक न करें। हमेशा अपने बैकएंड सर्वर से API कॉल करें।
// GraphQL Header
{
  "Authorization": "Bearer YOUR_API_KEY"
}

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

क्विक स्टार्ट

बस कुछ ही मिनटों में Stable Diffusion API के साथ शुरुआत करें। अपना पहला text to image जेनरेट करने के लिए इन सरल चरणों का पालन करें।

चरण 1: अपनी API Key प्राप्त करें

Doitong अकाउंट के लिए साइन अप करें और API key जेनरेट करने के लिए अपने डैशबोर्ड पर जाएं।

चरण 2: अपनी पहली रिक्वेस्ट भेजें

अपनी पहली 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": "stable-diffusion",
        "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: 'stable-diffusion',
        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": "stable-diffusion",
        "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": "stable-diffusion",
    "input": {
      "text": "A futuristic city with flying cars and neon lights"
    },
    "options": {
      "width": 1024,
      "height": 1024,
      "version": "sd-2.1",
      "quality": "high"
    }
  }
}

प्राइसिंग

Stable Diffusion API क्रेडिट-आधारित प्राइसिंग मॉडल का उपयोग करता है। जेनरेट किए गए कंटेंट की जटिलता और अवधि के आधार पर क्रेडिट खर्च होते हैं।

फीचर क्रेडिट विवरण
स्टैंडर्ड रेजोल्यूशन 10-20 क्रेडिट 512x512 से 1024x1024 पिक्सल
हाई रेजोल्यूशन 30-50 क्रेडिट 2048x2048 पिक्सल और उससे अधिक

API एंडपॉइंट्स

Stable Diffusion API हमारे एकीकृत GraphQL एंडपॉइंट के माध्यम से उपलब्ध है।

GraphQL एंडपॉइंट

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

REST एंडपॉइंट

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

पैरामीटर्स

Stable Diffusion API रिक्वेस्ट के लिए उपलब्ध पैरामीटर्स:

पैरामीटर प्रकार अनिवार्य विवरण
service String Yes सर्विस आइडेंटिफ़ायर: "stable-diffusion"
prompt String Yes क्या जेनरेट करना है, इसका टेक्स्ट विवरण
width Integer No पिक्सल में इमेज की चौड़ाई (डिफ़ॉल्ट: 1024)
height Integer No पिक्सल में इमेज की ऊंचाई (डिफ़ॉल्ट: 1024)
version String No Model version: "sd-xl", "sd-2.1"
webhookUrl String No जनरेशन पूरा होने के नोटिफिकेशन प्राप्त करने के लिए URL

रिस्पॉन्स फॉर्मेट

सभी API रिस्पॉन्स एक सुसंगत फॉर्मेट का पालन करते हैं:

सफलता रिस्पॉन्स

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

पूर्ण रिस्पॉन्स

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

एरर हैंडलिंग

API मानक HTTP स्टेटस कोड का उपयोग करता है और विस्तृत एरर मैसेज देता है।

सामान्य एरर कोड

स्टेटस कोड एरर टाइप विवरण
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

एरर रिस्पॉन्स फॉर्मेट

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

वेबहुक्स

जब आपका text to image जनरेशन पूरा हो जाए, तो रीयल-टाइम नोटिफिकेशन प्राप्त करें।

वेबहुक्स सेटअप करना

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

वेबहुक पेलोड

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

वेबहुक सुरक्षा

सभी वेबहुक रिक्वेस्ट में वेरिफिकेशन के लिए एक सिग्नेचर हेडर शामिल होता है:

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

रेट लिमिट्स

निष्पक्ष उपयोग और सिस्टम स्थिरता सुनिश्चित करने के लिए, निम्नलिखित रेट लिमिट्स लागू होती हैं:

प्लान रिक्वेस्ट/मिनट समवर्ती जॉब्स दैनिक सीमा
फ्री 10 1 100
स्टार्टर 30 3 1,000
प्रो 60 10 10,000
एंटरप्राइज कस्टम कस्टम असीमित
रेट लिमिट हेडर: वर्तमान लिमिट स्टेटस के लिए रिस्पॉन्स हेडर चेक करें:
  • X-RateLimit-Limit: Maximum requests per window
  • X-RateLimit-Remaining: Requests remaining
  • X-RateLimit-Reset: Window reset timestamp

सर्वोत्तम अभ्यास

1. अपने प्रॉम्प्ट्स को ऑप्टिमाइज़ करें

सर्वोत्तम परिणामों के लिए स्पष्ट और वर्णनात्मक प्रॉम्प्ट लिखें:

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

2. एसिंक प्रोसेसिंग को हैंडल करें

जनरेशन एसिंक्रोनस है। उचित पोलिंग या वेबहुक लागू करें:

// 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. एरर रिकवरी

एक्सपोनेंशियल बैकऑफ़ के साथ रिट्राय लॉजिक लागू करें:

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. क्रेडिट उपयोग की निगरानी करें

रुकावटों से बचने के लिए अपने क्रेडिट खर्च को ट्रैक करें:

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

क्या आप शुरू करने के लिए तैयार हैं?

बेहतरीन कंटेंट बनाने के लिए Stable Diffusion API का उपयोग करने वाले हज़ारों डेवलपर्स में शामिल हों

API Key प्राप्त करें प्राइसिंग देखें