API Stable Diffusion
Model cod agored safonol y diwydiant gydag addasiadau helaeth
✓ Cod agored
✓ Addasadwy
✓ ControlNet
✓ Cefnogaeth LoRA
Dilysu
I gael mynediad i Stable Diffusion drwy API Doitong, defnyddiwch eich allwedd API Doitong. Cynhwyswch hi ym mhennynnau'r mwtaniad GraphQL neu'r REST API.
// GraphQL Header
{
"Authorization": "Bearer YOUR_API_KEY"
}
// REST Header
"X-API-Key": "YOUR_API_KEY"
Cychwyn Cyflym
Dechreuwch ddefnyddio Stable Diffusion API mewn ychydig funudau yn unig. Dilynwch y camau syml hyn i gynhyrchu eich text to image cyntaf.
Cam 1: Cael eich Allwedd API
Cofrestrwch am gyfrif Doitong ac ewch i'ch dangosfwrdd i gynhyrchu allwedd API.
Cam 2: Gwneud eich Cais Cyntaf
Defnyddiwch un o'r enghreifftiau cod isod i wneud eich galwad API gyntaf.
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"
}
}
}
Prisio
Mae Stable Diffusion API yn defnyddio model prisio sy'n seiliedig ar gredydau. Defnyddir credydau yn ôl cymhlethdod a hyd y cynnwys a gynhyrchir.
| Nodwedd | Credydau | Disgrifiad |
|---|---|---|
| Cydraniad Safonol | 10-20 Credydau | 512x512 i 1024x1024 picsel |
| Cydraniad Uchel | 30-50 Credydau | 2048x2048 picsel ac uwch |
Pwyntiau Terfyn API
Mae Stable Diffusion API ar gael drwy ein pwynt terfyn GraphQL unedig.
Pwynt Terfyn GraphQL
POST https://api.doitong.com/graphql
Pwynt Terfyn REST
POST https://api.doitong.com/v1/text_to_image
Paramedrau
Paramedrau sydd ar gael ar gyfer ceisiadau Stable Diffusion API:
| Paramedr | Math | Gofynnol | Disgrifiad |
|---|---|---|---|
service |
Llinyn | Yes | Dynodwr gwasanaeth: "stable-diffusion" |
prompt |
Llinyn | Yes | Disgrifiad testun o beth i'w gynhyrchu |
width |
Cyfanrif | No | Lled y ddelwedd mewn picseli (rhagosodiad: 1024) |
height |
Cyfanrif | No | Uchder y ddelwedd mewn picseli (rhagosodiad: 1024) |
version |
Llinyn | No | Model version: "sd-xl", "sd-2.1" |
webhookUrl |
Llinyn | No | URL i dderbyn hysbysiadau cwblhau |
Fformat yr Ymateb
Mae holl ymatebion yr API yn dilyn fformat cyson:
Ymateb Llwyddiannus
{
"data": {
"generateimage": {
"id": "abc123xyz",
"status": "processing",
"url": null,
"webhookUrl": "https://your-webhook.com/callback",
"createdAt": "2024-01-01T00:00:00Z"
}
}
}
Ymateb Wedi'i Gwblhau
{
"data": {
"generateimage": {
"id": "abc123xyz",
"status": "completed",
"url": "https://cdn.doitong.com/outputs/abc123xyz.jpg",
"duration": null,
"createdAt": "2024-01-01T00:00:00Z"
}
}
}
Trin Gwallau
Mae'r API yn defnyddio codau statws HTTP safonol ac yn dychwelyd negeseuon gwall manwl.
Codau Gwall Cyffredin
| Cod Statws | Math o Wall | Disgrifiad |
|---|---|---|
| 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 |
Fformat Ymateb Gwall
{
"errors": [
{
"message": "Insufficient credits for this operation",
"extensions": {
"code": "INSUFFICIENT_CREDITS",
"creditsRequired": 100,
"creditsAvailable": 50
}
}
]
}
Webhooks
Derbyniwch hysbysiadau amser-real pan fydd eich text to image wedi'i gynhyrchu.
Ffurfweddu Webhooks
Include a <code>webhookUrl</code> parameter in your request to receive a POST notification when processing is complete.
Llwyth Cyflog 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
}
}
Diogelwch Webhook
Mae pob cais webhook yn cynnwys pennyn llofnod ar gyfer dilysu:
X-Doitong-Signature: sha256=abc123...
Terfynau Cyfradd
Er mwyn sicrhau defnydd teg a sefydlogrwydd y system, mae'r terfynau cyfradd canlynol yn berthnasol:
| Cynllun | Ceisiadau/Munud | Tasgau Cydredol | Terfyn Dyddiol |
|---|---|---|---|
| Am Ddim | 10 | 1 | 100 |
| Dechreuwr | 30 | 3 | 1,000 |
| Pro | 60 | 10 | 10,000 |
| Menter | Personol | Personol | Diderfyn |
X-RateLimit-Limit: Maximum requests per windowX-RateLimit-Remaining: Requests remainingX-RateLimit-Reset: Window reset timestamp
Arferion Gorau
1. Optimeiddio eich Anogwyr
Ysgrifennwch anogwyr clir a disgrifiadol i gael y canlyniadau gorau:
- Be specific about visual elements, style, and mood
- Include details about lighting, camera angles, and composition
- Avoid contradictory or impossible requests
2. Trin Prosesu Anghydamserol
Mae'r broses gynhyrchu yn anghydamserol. Gweithredwch brosesau 'polling' neu webhooks priodol:
// 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. Adfer o Wallau
Gweithredwch resymeg ailgeisio gydag egwyl esbonyddol (exponential backoff):
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. Monitro Defnydd Credydau
Traciwch eich defnydd o gredydau er mwyn osgoi toriadau yn y gwasanaeth:
- Check credit balance before large batch operations
- Set up alerts for low credit thresholds
- Implement credit-aware request queuing
Yn barod i ddechrau?
Ymunwch â miloedd o ddatblygwyr sy'n defnyddio Stable Diffusion API i greu cynnwys anhygoel