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

# Get Prediction

> Retrieve the status and results of a model prediction.

## Endpoint

```
GET https://api.eachlabs.ai/v1/prediction/{id}
```

## Path Parameters

| Parameter | Type   | Required | Description                                                                         |
| --------- | ------ | -------- | ----------------------------------------------------------------------------------- |
| `id`      | string | Yes      | Prediction ID returned from [Create Prediction](/api/predictions/create-prediction) |

## Code Examples

<CodeGroup>
  ```bash cURL theme={"dark"}
  curl https://api.eachlabs.ai/v1/prediction/abc123-def456-ghi789 \
    -H "X-API-Key: YOUR_API_KEY"
  ```

  ```python Python theme={"dark"}
  import requests
  import time

  prediction_id = "abc123-def456-ghi789"

  while True:
      response = requests.get(
          f"https://api.eachlabs.ai/v1/prediction/{prediction_id}",
          headers={"X-API-Key": "YOUR_API_KEY"}
      )
      data = response.json()

      if data["status"] in ("success", "failed", "cancelled"):
          break

      print(f"Status: {data['status']}...")
      time.sleep(2)

  if data["status"] == "success":
      print(f"Output: {data['output']}")
  else:
      print(f"Failed: {data.get('logs')}")
  ```

  ```javascript JavaScript theme={"dark"}
  async function waitForPrediction(predictionId) {
    while (true) {
      const response = await fetch(
        `https://api.eachlabs.ai/v1/prediction/${predictionId}`,
        { headers: { "X-API-Key": "YOUR_API_KEY" } }
      );
      const data = await response.json();

      if (["success", "failed", "cancelled"].includes(data.status)) {
        return data;
      }

      console.log(`Status: ${data.status}...`);
      await new Promise((r) => setTimeout(r, 2000));
    }
  }

  const result = await waitForPrediction("abc123-def456-ghi789");
  console.log(`Output: ${result.output}`);
  ```
</CodeGroup>

## Response

```json theme={"dark"}
{
  "id": "abc123-def456-ghi789",
  "input": {
    "prompt": "A beautiful sunset over the ocean with vibrant colors",
    "aspect_ratio": "16:9"
  },
  "status": "success",
  "output": "https://storage.example.com/predictions/abc123/image.jpg",
  "logs": null,
  "metrics": {
    "predict_time": 12.5,
    "cost": 0.05
  },
  "urls": {
    "cancel": "https://api.eachlabs.ai/v1/prediction/abc123-def456-ghi789/cancel",
    "get": "https://api.eachlabs.ai/v1/prediction/abc123-def456-ghi789"
  }
}
```

### Response Fields

| Field                  | Type                      | Description                                                   |
| ---------------------- | ------------------------- | ------------------------------------------------------------- |
| `id`                   | string                    | Prediction ID                                                 |
| `input`                | object                    | Input parameters used                                         |
| `status`               | string                    | `starting`, `processing`, `success`, `failed`, or `cancelled` |
| `output`               | string \| array \| object | Prediction output (type depends on model)                     |
| `logs`                 | string \| null            | Execution logs                                                |
| `metrics.predict_time` | number                    | Processing time in seconds                                    |
| `metrics.cost`         | number                    | Cost in USD                                                   |
| `urls.cancel`          | string                    | URL to cancel the prediction                                  |
| `urls.get`             | string                    | URL to re-fetch this prediction                               |

### Prediction Status Values

| Status       | Description                       |
| ------------ | --------------------------------- |
| `starting`   | Prediction is initializing        |
| `processing` | Model is processing the input     |
| `success`    | Prediction completed successfully |
| `failed`     | Prediction failed                 |
| `cancelled`  | Prediction was cancelled          |

## Error Responses

| Status | Body                                 | Description           |
| ------ | ------------------------------------ | --------------------- |
| `404`  | `{"error": "Prediction not found"}`  | Invalid prediction ID |
| `500`  | `{"error": "Internal server error"}` | Server error          |
