> ## 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.

# Recuperare una prediction di Replicate

> Interroga GET /replicate/v1/predictions/{id} per recuperare i dettagli di una prediction di Replicate e l'avanzamento in tempo reale per ID attività nei flussi di lavoro di generazione di immagini.

Usa questo endpoint dopo avere già un id di prediction di Replicate. Riporta lo stato corrente dell'attività e restituisce gli URL di output quando la prediction è completata.

## Controlla prima questi campi

* `status` per vedere se la prediction è ancora in esecuzione o è già terminata
* `output` per gli URL delle risorse generate
* `error` per gli errori lato provider
* `metrics` quando ti servono dettagli sui tempi di esecuzione o sul numero di immagini

## Modello di polling

<Steps>
  <Step title="Create the prediction first">
    Inizia con [Create a Replicate prediction](./create-predictions-general).
  </Step>

  <Step title="Poll by prediction id">
    Continua a interrogare finché `status` non diventa terminale e `output` non viene popolato oppure non viene restituito un errore del provider.
  </Step>

  <Step title="Persist finished assets">
    Tratta gli URL delle risorse restituiti come URL di consegna e spostali nel tuo storage se ti serve una conservazione a lungo termine.
  </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.

````