> ## Documentation Index
> Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# الحصول على توقع Replicate

> استخدم استعلام GET /replicate/v1/predictions/{id} لجلب تفاصيل توقع Replicate والتقدم الفعلي في الوقت الحقيقي حسب معرّف المهمة ضمن مسارات عمل توليد الصور.

استخدم نقطة النهاية هذه بعد أن يكون لديك بالفعل معرّف توقع Replicate. فهي تعرض الحالة الحالية للمهمة وتُرجع عناوين URL للمخرجات عند اكتمال التوقع.

## تحقق من هذه الحقول أولاً

* `status` لمعرفة ما إذا كان التوقع لا يزال قيد التشغيل أو قد انتهى بالفعل
* `output` لعناوين URL الخاصة بالأصول المُولدة
* `error` لحالات الفشل من جهة المزوّد
* `metrics` عندما تحتاج إلى تفاصيل توقيت التنفيذ أو عدد الصور

## نمط الاستطلاع

<Steps>
  <Step title="أنشئ التوقع أولاً">
    ابدأ من [إنشاء توقع Replicate](./create-predictions-general).
  </Step>

  <Step title="استطلع باستخدام معرّف التوقع">
    استمر في الاستعلام حتى تصبح قيمة `status` نهائية وتكون `output` قد امتلأت أو يتم إرجاع خطأ من المزوّد.
  </Step>

  <Step title="احفظ الأصول المكتملة">
    تعامل مع عناوين URL الخاصة بالأصول المُعادة على أنها عناوين تسليم، وانقلها إلى التخزين الخاص بك إذا كنت بحاجة إلى احتفاظ طويل الأمد.
  </Step>
</Steps>


## OpenAPI

````yaml api/openapi/image/replicate/get-replicate-query.openapi.json GET /replicate/v1/predictions/{id}
openapi: 3.1.0
info:
  title: Replicate Query API
  version: 1.0.0
  description: >-
    Query a Replicate prediction created through CometAPI and read the final
    output URLs when the prediction completes.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /replicate/v1/predictions/{id}:
    get:
      summary: Query a Replicate prediction
      description: >-
        Use the prediction id returned by the create endpoint. Keep polling
        until `output` is populated or `error` is not null.
      operationId: replicate_query
      parameters:
        - name: id
          in: path
          required: true
          description: Prediction id returned by the create endpoint.
          schema:
            type: string
      responses:
        '200':
          description: Current prediction state.
          content:
            application/json:
              schema:
                type: object
                required:
                  - id
                  - input
                  - model
                  - output
                  - status
                  - created_at
                  - data_removed
                properties:
                  id:
                    type: string
                  logs:
                    type: string
                  urls:
                    type: object
                    properties:
                      get:
                        type: string
                      cancel:
                        type: string
                      stream:
                        type: string
                  error:
                    type:
                      - string
                      - 'null'
                  input:
                    type: object
                  model:
                    type: string
                  output:
                    type:
                      - array
                      - 'null'
                    items:
                      type: string
                  status:
                    type: string
                  metrics:
                    type: object
                    properties:
                      image_count:
                        type: integer
                      predict_time:
                        type: number
                  version:
                    type: string
                  created_at:
                    type: string
                  started_at:
                    type:
                      - string
                      - 'null'
                  completed_at:
                    type:
                      - string
                      - 'null'
                  data_removed:
                    type: boolean
              example:
                id: <prediction_id>
                model: black-forest-labs/flux-schnell
                status: succeeded
                output:
                  - https://replicate.delivery/xezq/.../out-0.webp
                error: null
      x-codeSamples:
        - lang: Shell
          label: Default
          source: >
            PREDICTION_ID="<prediction_id>"


            curl
            "https://api.cometapi.com/replicate/v1/predictions/$PREDICTION_ID" \
              -H "Authorization: Bearer $COMETAPI_KEY"
        - lang: Python
          label: Default
          source: |
            import os
            import time
            import requests

            prediction_id = "<prediction_id>"
            headers = {"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]}

            while True:
                prediction = requests.get(
                    f"https://api.cometapi.com/replicate/v1/predictions/{prediction_id}",
                    headers=headers,
                ).json()
                print(prediction["status"])
                if prediction["status"] in ("succeeded", "failed", "canceled"):
                    break
                time.sleep(3)

            if prediction["status"] == "succeeded":
                print(prediction["output"])
        - lang: JavaScript
          label: Default
          source: >
            const predictionId = "<prediction_id>";

            const headers = { Authorization: `Bearer
            ${process.env.COMETAPI_KEY}` };


            let prediction;

            while (true) {
                prediction = await (await fetch(
                    `https://api.cometapi.com/replicate/v1/predictions/${predictionId}`, { headers }
                )).json();
                console.log(prediction.status);
                if (["succeeded", "failed", "canceled"].includes(prediction.status)) break;
                await new Promise((resolve) => setTimeout(resolve, 3000));
            }


            if (prediction.status === "succeeded")
            console.log(prediction.output);
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````