# Asset (*asset*) ## Overview Operations related to asset/vod api ### Available Operations * [getAll](#getall) - Retrieve assets * [create](#create) - Upload an asset * [createViaUrl](#createviaurl) - Upload asset via URL * [get](#get) - Retrieves an asset * [update](#update) - Patch an asset * [delete](#delete) - Delete an asset ## getAll Retrieve assets ### Example Usage ```typescript import { Livepeer } from "livepeer"; const livepeer = new Livepeer({ apiKey: "", }); async function run() { const result = await livepeer.asset.getAll(); // Handle the result console.log(result); } run(); ``` ### Standalone function The standalone function version of this method: ```typescript import { LivepeerCore } from "livepeer/core.js"; import { assetGetAll } from "livepeer/funcs/assetGetAll.js"; // Use `LivepeerCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const livepeer = new LivepeerCore({ apiKey: "", }); async function run() { const res = await assetGetAll(livepeer); if (!res.ok) { throw res.error; } const { value: result } = res; // Handle the result console.log(result); } run(); ``` ### Parameters | Parameter | Type | Required | Description | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. | | `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. | | `options.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. | ### Response **Promise\<[operations.GetAssetsResponse](../../models/operations/getassetsresponse.md)\>** ### Errors | Error Type | Status Code | Content Type | | --------------- | --------------- | --------------- | | errors.SDKError | 4XX, 5XX | \*/\* | ## create To upload an asset, your first need to request for a direct upload URL and only then actually upload the contents of the asset. \ \ Once you created a upload link, you have 2 options, resumable or direct upload. For a more reliable experience, you should use resumable uploads which will work better for users with unreliable or slow network connections. If you want a simpler implementation though, you should just use a direct upload. ## Direct Upload For a direct upload, make a PUT request to the URL received in the url field of the response above, with the raw video file as the request body. response above: ## Resumable Upload Livepeer supports resumable uploads via Tus. This section provides a simple example of how to use tus-js-client to upload a video file. \ \ From the previous section, we generated a URL to upload a video file to Livepeer on POST /api/asset/request-upload. You should use the tusEndpoint field of the response to upload the video file and track the progress: ``` # This assumes there is an `input` element of `type="file"` with id `fileInput` in the HTML const input = document.getElementById('fileInput'); const file = input.files[0]; const upload = new tus.Upload(file, { endpoint: tusEndpoint, // URL from `tusEndpoint` field in the `/request-upload` response metadata: { filename, filetype: 'video/mp4', }, uploadSize: file.size, onError(err) { console.error('Error uploading file:', err); }, onProgress(bytesUploaded, bytesTotal) { const percentage = ((bytesUploaded / bytesTotal) * 100).toFixed(2); console.log('Uploaded ' + percentage + '%'); }, onSuccess() { console.log('Upload finished:', upload.url); }, }); const previousUploads = await upload.findPreviousUploads(); if (previousUploads.length > 0) { upload.resumeFromPreviousUpload(previousUploads[0]); } upload.start(); ``` > Note: If you are using tus from node.js, you need to add a custom URL storage to enable resuming from previous uploads. On the browser, this is enabled by default using local storage. In node.js, add urlStorage: new tus.FileUrlStorage("path/to/tmp/file"), to the UploadFile object definition above. ### Example Usage ```typescript import { Livepeer } from "livepeer"; import { TranscodeProfileEncoder, TranscodeProfileProfile, Type } from "livepeer/models/components"; const livepeer = new Livepeer({ apiKey: "", }); async function run() { const result = await livepeer.asset.create({ name: "filename.mp4", staticMp4: true, playbackPolicy: { type: Type.Webhook, webhookId: "1bde4o2i6xycudoy", webhookContext: { "streamerId": "my-custom-id", }, refreshInterval: 600, }, profiles: [ { width: 1280, name: "720p", height: 720, bitrate: 3000000, quality: 23, fps: 30, fpsDen: 1, gop: "2", profile: TranscodeProfileProfile.H264Baseline, encoder: TranscodeProfileEncoder.H264, }, ], }); // Handle the result console.log(result); } run(); ``` ### Standalone function The standalone function version of this method: ```typescript import { LivepeerCore } from "livepeer/core.js"; import { assetCreate } from "livepeer/funcs/assetCreate.js"; import { TranscodeProfileEncoder, TranscodeProfileProfile, Type } from "livepeer/models/components"; // Use `LivepeerCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const livepeer = new LivepeerCore({ apiKey: "", }); async function run() { const res = await assetCreate(livepeer, { name: "filename.mp4", staticMp4: true, playbackPolicy: { type: Type.Webhook, webhookId: "1bde4o2i6xycudoy", webhookContext: { "streamerId": "my-custom-id", }, refreshInterval: 600, }, profiles: [ { width: 1280, name: "720p", height: 720, bitrate: 3000000, quality: 23, fps: 30, fpsDen: 1, gop: "2", profile: TranscodeProfileProfile.H264Baseline, encoder: TranscodeProfileEncoder.H264, }, ], }); if (!res.ok) { throw res.error; } const { value: result } = res; // Handle the result console.log(result); } run(); ``` ### Parameters | Parameter | Type | Required | Description | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `request` | [components.NewAssetPayload](../../models/components/newassetpayload.md) | :heavy_check_mark: | The request object to use for the request. | | `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. | | `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. | | `options.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. | ### Response **Promise\<[operations.RequestUploadResponse](../../models/operations/requestuploadresponse.md)\>** ### Errors | Error Type | Status Code | Content Type | | --------------- | --------------- | --------------- | | errors.SDKError | 4XX, 5XX | \*/\* | ## createViaUrl Upload asset via URL ### Example Usage ```typescript import { Livepeer } from "livepeer"; import { TranscodeProfileEncoder, TranscodeProfileProfile, Type } from "livepeer/models/components"; const livepeer = new Livepeer({ apiKey: "", }); async function run() { const result = await livepeer.asset.createViaUrl({ name: "filename.mp4", staticMp4: true, playbackPolicy: { type: Type.Webhook, webhookId: "1bde4o2i6xycudoy", webhookContext: { "streamerId": "my-custom-id", }, refreshInterval: 600, }, url: "https://s3.amazonaws.com/my-bucket/path/filename.mp4", profiles: [ { width: 1280, name: "720p", height: 720, bitrate: 3000000, quality: 23, fps: 30, fpsDen: 1, gop: "2", profile: TranscodeProfileProfile.H264Baseline, encoder: TranscodeProfileEncoder.H264, }, ], }); // Handle the result console.log(result); } run(); ``` ### Standalone function The standalone function version of this method: ```typescript import { LivepeerCore } from "livepeer/core.js"; import { assetCreateViaUrl } from "livepeer/funcs/assetCreateViaUrl.js"; import { TranscodeProfileEncoder, TranscodeProfileProfile, Type } from "livepeer/models/components"; // Use `LivepeerCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const livepeer = new LivepeerCore({ apiKey: "", }); async function run() { const res = await assetCreateViaUrl(livepeer, { name: "filename.mp4", staticMp4: true, playbackPolicy: { type: Type.Webhook, webhookId: "1bde4o2i6xycudoy", webhookContext: { "streamerId": "my-custom-id", }, refreshInterval: 600, }, url: "https://s3.amazonaws.com/my-bucket/path/filename.mp4", profiles: [ { width: 1280, name: "720p", height: 720, bitrate: 3000000, quality: 23, fps: 30, fpsDen: 1, gop: "2", profile: TranscodeProfileProfile.H264Baseline, encoder: TranscodeProfileEncoder.H264, }, ], }); if (!res.ok) { throw res.error; } const { value: result } = res; // Handle the result console.log(result); } run(); ``` ### Parameters | Parameter | Type | Required | Description | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `request` | [components.NewAssetFromUrlPayload](../../models/components/newassetfromurlpayload.md) | :heavy_check_mark: | The request object to use for the request. | | `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. | | `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. | | `options.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. | ### Response **Promise\<[operations.UploadAssetResponse](../../models/operations/uploadassetresponse.md)\>** ### Errors | Error Type | Status Code | Content Type | | --------------- | --------------- | --------------- | | errors.SDKError | 4XX, 5XX | \*/\* | ## get Retrieves an asset ### Example Usage ```typescript import { Livepeer } from "livepeer"; const livepeer = new Livepeer({ apiKey: "", }); async function run() { const result = await livepeer.asset.get(""); // Handle the result console.log(result); } run(); ``` ### Standalone function The standalone function version of this method: ```typescript import { LivepeerCore } from "livepeer/core.js"; import { assetGet } from "livepeer/funcs/assetGet.js"; // Use `LivepeerCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const livepeer = new LivepeerCore({ apiKey: "", }); async function run() { const res = await assetGet(livepeer, ""); if (!res.ok) { throw res.error; } const { value: result } = res; // Handle the result console.log(result); } run(); ``` ### Parameters | Parameter | Type | Required | Description | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `assetId` | *string* | :heavy_check_mark: | ID of the asset | | `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. | | `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. | | `options.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. | ### Response **Promise\<[operations.GetAssetResponse](../../models/operations/getassetresponse.md)\>** ### Errors | Error Type | Status Code | Content Type | | --------------- | --------------- | --------------- | | errors.SDKError | 4XX, 5XX | \*/\* | ## update Patch an asset ### Example Usage ```typescript import { Livepeer } from "livepeer"; import { Type } from "livepeer/models/components"; const livepeer = new Livepeer({ apiKey: "", }); async function run() { const result = await livepeer.asset.update({ name: "filename.mp4", playbackPolicy: { type: Type.Webhook, webhookId: "1bde4o2i6xycudoy", webhookContext: { "streamerId": "my-custom-id", }, refreshInterval: 600, }, }, ""); // Handle the result console.log(result); } run(); ``` ### Standalone function The standalone function version of this method: ```typescript import { LivepeerCore } from "livepeer/core.js"; import { assetUpdate } from "livepeer/funcs/assetUpdate.js"; import { Type } from "livepeer/models/components"; // Use `LivepeerCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const livepeer = new LivepeerCore({ apiKey: "", }); async function run() { const res = await assetUpdate(livepeer, { name: "filename.mp4", playbackPolicy: { type: Type.Webhook, webhookId: "1bde4o2i6xycudoy", webhookContext: { "streamerId": "my-custom-id", }, refreshInterval: 600, }, }, ""); if (!res.ok) { throw res.error; } const { value: result } = res; // Handle the result console.log(result); } run(); ``` ### Parameters | Parameter | Type | Required | Description | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `assetId` | *string* | :heavy_check_mark: | ID of the asset | | `assetPatchPayload` | [components.AssetPatchPayload](../../models/components/assetpatchpayload.md) | :heavy_check_mark: | N/A | | `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. | | `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. | | `options.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. | ### Response **Promise\<[operations.UpdateAssetResponse](../../models/operations/updateassetresponse.md)\>** ### Errors | Error Type | Status Code | Content Type | | --------------- | --------------- | --------------- | | errors.SDKError | 4XX, 5XX | \*/\* | ## delete Delete an asset ### Example Usage ```typescript import { Livepeer } from "livepeer"; const livepeer = new Livepeer({ apiKey: "", }); async function run() { const result = await livepeer.asset.delete(""); // Handle the result console.log(result); } run(); ``` ### Standalone function The standalone function version of this method: ```typescript import { LivepeerCore } from "livepeer/core.js"; import { assetDelete } from "livepeer/funcs/assetDelete.js"; // Use `LivepeerCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const livepeer = new LivepeerCore({ apiKey: "", }); async function run() { const res = await assetDelete(livepeer, ""); if (!res.ok) { throw res.error; } const { value: result } = res; // Handle the result console.log(result); } run(); ``` ### Parameters | Parameter | Type | Required | Description | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `assetId` | *string* | :heavy_check_mark: | ID of the asset | | `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. | | `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. | | `options.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. | ### Response **Promise\<[operations.DeleteAssetResponse](../../models/operations/deleteassetresponse.md)\>** ### Errors | Error Type | Status Code | Content Type | | --------------- | --------------- | --------------- | | errors.SDKError | 4XX, 5XX | \*/\* |