قفز إلى المحتوى

المطور API

النسخة 1 تستخدم نفس النماذج والأصول واسترداد المهام والمحاسبة الائتمانية مثل Studio.

إدارة API مفتاح

إرسال إذن: يحمل YOUR_API_KEY. لا يتم قبول ملفات تعريف الارتباط على موقع الويب كما API يتم التحقق من العضوية المدفوعة النشطة والترخيص الرئيسي المطلوب على كل طلب.

اقرأ النماذج، قم بتحميل مرجع إذا لزم الأمر، اطلب اقتراح، اعترف صراحة بهذا الاقتراح، ثم قم بتقديمه باستخدام مفتاح الخصوبة المستقر.

فقط تسليم الجيل يستهلك الائتمانات الحسابية. لا تستهلك الائتمانات الائتمانات الائتمانات الائتمانات الائتمانات الائتمانات الائتمانات الائتمانات الائتمانات الائتمانات الائتمانات الائتمانات الائتمانات الائتمانات الائتمانات الائتمانات الائتمانات الائتمانات الائتمانات الائتمانات الائتمانات الائتمانات الائتمانات.

كل مفتاح يسمح 60 طلبات معتمدة في الدقيقة.أ 429 رد شامل Retry-After. keys expires داخل 1–365 يمكن إلغاءها على الفور ويمكن إلغائها على الفور.

HTTPURLإذنات
GET/api/v1/modelsmodels:read
GET/api/v1/assetsassets:read
GET/api/v1/assets/{id}/downloadassets:read
POST/api/v1/uploadsassets:write
PUT/api/v1/uploads/{id}assets:write
POST/api/v1/uploads/{id}/completeassets:write
POST/api/v1/quotesgenerations:write
POST/api/v1/generationsgenerations:write
GET/api/v1/generations/{kind}/{id}generations:read
GET/api/v1/generations/{kind}/{id}/outputs/{index}generations:read

يستخدم الإشارات تحميل ثلاث خطوات: إعلان حجم MIME و byte، PUT byte، ثم الانتهاء. JPEG, PNG و WebP إلى الأعلى 10 يستخدم معرف الأصول المستردة؛ لا يتم قبول عناوين URL المرجعية الخارجية وأصول المستخدمين الآخرين.

// Node.js 22+; keep API_KEY on your server.
const base = process.env.API_BASE_URL;
const headers = {
  Authorization: `Bearer ${process.env.API_KEY}`,
  'Content-Type': 'application/json',
};
const modelsResponse = await fetch(base + '/api/v1/models', { headers });
if (!modelsResponse.ok) throw new Error('Read models failed');
const models = await modelsResponse.json();

const draft = {
  "kind": "image",
  "modelPreset": "gpt-image-2",
  "mode": "text-to-image",
  "prompt": "A yellow ceramic mug on a pale blue background",
  "aspectRatio": "1:1",
  "resolution": "1k",
  "outputCount": 1
};
const quoteResponse = await fetch(base + '/api/v1/quotes', {
  method: 'POST', headers, body: JSON.stringify({ draft }),
});
if (!quoteResponse.ok) throw new Error('Quote failed');
const quote = await quoteResponse.json();

// Review quote.quote before submitting. Persist this operation ID first.
const operationId = process.env.OPERATION_ID;
if (!operationId) throw new Error('A stable operation ID is required');
const submitted = await fetch(base + '/api/v1/generations', {
  method: 'POST',
  headers: { ...headers, 'Idempotency-Key': operationId },
  body: JSON.stringify({
    draft: quote.normalizedDraft,
    quoteAcknowledgement: quote.quote,
  }),
});
if (!submitted.ok) throw new Error('Check response before retrying');
const { task } = await submitted.json();
const taskResponse = await fetch(
  base + '/api/v1/generations/' + task.kind + '/' + task.id, { headers },
);
if (!taskResponse.ok) throw new Error('Read task failed');
const detail = await taskResponse.json();
// Poll at two-second intervals until terminal. Download detail.outputs[].downloadUrl
// with the same Authorization header. Never change the ID to retry an unknown outcome.

401المفتاح غير صحيح أو مدته أو تم إلغاءه. 403- عدم الحصول على إذن أو عضوية مدفوعة الأجر. 409: نزاع في القدرة أو تغيير الخصم ؛ طلب وتأكيد الخصم الجديد. 422إدخال غير صحيح. 429الحد الأدنى للعدد. 503: غير متوفر مؤقتًا. اقرأ رمز الخطأ في الاستجابة؛ لا تتراجع أبدًا عن تقديم مدفوع مع مفتاح جديد تلقائيًا.