Stable Diffusion API
ਵਿਆਪਕ ਕਸਟਮਾਈਜ਼ੇਸ਼ਨ ਦੇ ਨਾਲ ਉਦਯੋਗਿਕ ਸਟੈਂਡਰਡ ਓਪਨ-ਸੋਰਸ ਮਾਡਲ
✓ ਓਪਨ ਸੋਰਸ
✓ ਕਸਟਮਾਈਜ਼ੇਬਲ
✓ ControlNet
✓ LoRA ਸਹਾਇਤਾ
ਪ੍ਰਮਾਣਿਕਤਾ
Doitong API ਰਾਹੀਂ Stable Diffusion ਤੱਕ ਪਹੁੰਚਣ ਲਈ, ਆਪਣੀ Doitong API key ਦੀ ਵਰਤੋਂ ਕਰੋ। ਇਸਨੂੰ GraphQL mutation ਜਾਂ REST API headers ਵਿੱਚ ਸ਼ਾਮਲ ਕਰੋ।
// 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
}
}
]
}
Webhooks
ਜਦੋਂ ਤੁਹਾਡੀ text to image ਬਣ ਕੇ ਤਿਆਰ ਹੋ ਜਾਵੇ, ਤਾਂ ਰੀਅਲ-ਟਾਈਮ ਨੋਟੀਫਿਕੇਸ਼ਨ ਪ੍ਰਾਪਤ ਕਰੋ।
Webhooks ਸੈੱਟਅੱਪ ਕਰਨਾ
Include a <code>webhookUrl</code> parameter in your request to receive a POST notification when processing is complete.
Webhook ਪੇਲੋਡ
{
"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
}
}
Webhook ਸੁਰੱਖਿਆ
ਸਾਰੀਆਂ webhook ਬੇਨਤੀਆਂ ਵਿੱਚ ਪੁਸ਼ਟੀਕਰਨ ਲਈ ਇੱਕ ਸਿਗਨੇਚਰ ਹੈਡਰ ਸ਼ਾਮਲ ਹੁੰਦਾ ਹੈ:
X-Doitong-Signature: sha256=abc123...
ਦਰ ਸੀਮਾਵਾਂ
ਨਿਰਪੱਖ ਵਰਤੋਂ ਅਤੇ ਸਿਸਟਮ ਸਥਿਰਤਾ ਨੂੰ ਯਕੀਨੀ ਬਣਾਉਣ ਲਈ, ਹੇਠ ਲਿਖੀਆਂ ਦਰ ਸੀਮਾਵਾਂ ਲਾਗੂ ਹੁੰਦੀਆਂ ਹਨ:
| ਪਲਾਨ | ਬੇਨਤੀਆਂ/ਮਿੰਟ | ਸਮਾਨੰਤਰ ਕੰਮ | ਰੋਜ਼ਾਨਾ ਸੀਮਾ |
|---|---|---|---|
| ਮੁਫ਼ਤ | 10 | 1 | 100 |
| Starter | 30 | 3 | 1,000 |
| Pro | 60 | 10 | 10,000 |
| Enterprise | ਕਸਟਮ | ਕਸਟਮ | ਅਸੀਮਤ |
X-RateLimit-Limit: Maximum requests per windowX-RateLimit-Remaining: Requests remainingX-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. ਅਸਿੰਕ੍ਰੋਨਸ ਪ੍ਰੋਸੈਸਿੰਗ ਨੂੰ ਸੰਭਾਲੋ
ਜਨਰੇਸ਼ਨ ਅਸਿੰਕ੍ਰੋਨਸ ਹੈ। ਸਹੀ ਪੋਲਿੰਗ ਜਾਂ webhooks ਲਾਗੂ ਕਰੋ:
// 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 ਦੀ ਵਰਤੋਂ ਕਰਨ ਵਾਲੇ ਹਜ਼ਾਰਾਂ ਡਿਵੈਲਪਰਾਂ ਵਿੱਚ ਸ਼ਾਮਲ ਹੋਵੋ