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

# Get a Replicate prediction

> Query GET /replicate/v1/predictions/{id} to fetch Replicate prediction details and real-time progress by task ID for image generation workflows.

Use this endpoint after you already have a Replicate prediction id. It reports the current task state and returns output URLs when the prediction completes.

## Check these fields first

* `status` to see whether the prediction is still running or already finished
* `output` for generated asset URLs
* `error` for provider-side failures
* `metrics` when you need execution timing or image-count details

## Polling pattern

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

  <Step title="Poll by prediction id">
    Keep querying until `status` becomes terminal and `output` is either populated or a provider error is returned.
  </Step>

  <Step title="Persist finished assets">
    Treat returned asset URLs as delivery URLs and move them into your own storage if you need long retention.
  </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.

````