> For the complete documentation index, see [llms.txt](https://docs.colossyan.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.colossyan.com/video-generation/video-generation/receiving-a-generated-video.md).

# Receiving a generated video

{% hint style="info" %}
There are three ways to get a video, that was generated via our APIs.

1. You can get notified via our callback once a video is ready (recommended in production)
2. You can poll it using other API endpoints
3. You can download the video from your Colossyan Account after navigating to the workspace where the API key was created.
   {% endhint %}

### Callback <a href="#callback" id="callback"></a>

Upon posting a new video generation job, you have the opportunity to add a `callback` and some `callbackPayload` to the job. When the job is successful our service will issue a **POST** request to the url you provided in the `callback` field.

In the body of this post message, we add the following fields:

| Key                                                                                                      | Description                                                              |
| -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
| `url`                                                                                                    | Contains the public url of the generated video file.                     |
| `videoUrl` and `shareUrl`                                                                                | Contains a unique url pointing at Colossyans video sharing platform.     |
| `status`                                                                                                 | The status of the video generation. Can either be `finished` or `failed` |
| ...and everything that was provided at the job's generation as `callbackPayload` and `dynamicVariables`. |                                                                          |

### Polling <a href="#polling" id="polling"></a>

Due to the asynchronous nature of video-generations, first you need to query the video-generation-job itself, to see the status of it. To do this, use the API below.&#x20;

{% openapi src="/files/Ii7chHq2XhIO7zrcyhgg" path="/video-generation-jobs/{videoId}" method="get" %}
[index.yaml](https://55465428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2Ywi5dAVPQ3D5ZEo1sKj%2Fuploads%2FfYZ7eiatXGSDDkB7Ma31%2Findex.yaml?alt=media\&token=e240d51f-3fad-4655-b973-8123721cdd7a)
{% endopenapi %}

Continue to poll the status of the job, until it returns either `finished` or `failed`. In case it successfully finished generating use the API below to get the generated video.

* You can get the `videoId` both when queueing the job itself, or when fetching it's status.

{% openapi src="/files/7FxbXzHVwwGoAxGbyxVs" path="/generated-videos/{videoId}" method="get" %}
[index.yaml](https://55465428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2Ywi5dAVPQ3D5ZEo1sKj%2Fuploads%2FMj174DbCoMdmffVKYlqT%2Findex.yaml?alt=media\&token=9d1107fb-665b-4c1f-b3bd-56604bc92348)
{% endopenapi %}

An example of a script to poll a job can be found below:

```javascript
const token = "<your-token-here>";
const jobId = "<your-job-id-here>";
const videoId = "<your-video-id-here>";
const jobUrl = `https://app.colossyan.com/api/v1/video-generation-jobs/${jobId}`;
const videoUrl = `https://app.colossyan.com/api/v1/generated-videos/${videoId}`;

async function pollStatus() {
  const jobResponse = await fetch(jobUrl, {
    method: "GET",
    headers: {
      Authorization: `Bearer ${token}`,
      "Content-Type": "application/json",
    },
  });
  const result = await jobResponse.json();
  const status = result.status;

  if (status !== "finished" && status !== "failed") {
    console.log(
      `Video status: ${status}, progress: ${result.progress}/${result.maximumProgress}`
    );
    setTimeout(pollStatus, 5000); // Retry every 5 seconds
  } else {
    const videoResponse = await fetch(videoUrl, {
      method: "GET",
      headers: {
        Authorization: `Bearer ${token}`,
        "Content-Type": "application/json",
      },
    });

    const result = await videoResponse.json();
    console.log(result);
  }
}

pollStatus();
```

### Getting the video from the Colossyan App

1. Open [Colossyan](https://app.colossyan.com/)
2. Navigate to workspace in which the API key was used to generate the video
3. [Open the generated videos page](https://app.colossyan.com/my-library?filter=video).&#x20;
   1. The video should be listed there&#x20;
   2. You should also see it if it's currently being generated. In this case, it'll show the status of the job.&#x20;


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.colossyan.com/video-generation/video-generation/receiving-a-generated-video.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `build a script that syncs our docs to a CMS` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
