### Create an Index using Go Source: https://docs.twelvelabs.io/api-reference/indexes/list This Go example shows how to make an HTTP GET request to create an index. It includes reading the response body and printing it. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.twelvelabs.io/v1.3/indexes?index_name=myIndex&model_options=visual%2Caudio&model_family=marengo&created_at=2024-08-16T16%3A53%3A59Z&updated_at=2024-08-16T16%3A55%3A59Z" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("x-api-key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Fetch Assets using Go Source: https://docs.twelvelabs.io/api-reference/upload-content/direct-uploads/list This Go example demonstrates making an HTTP GET request to fetch assets. Replace `` with your actual API key. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.twelvelabs.io/v1.3/assets?asset_ids=%5B%226298d673f1090f1100476d4c%22%2C%226298d673f1090f1100476d4d%22%5D&asset_types=%5B%22image%22%2C%22video%22%5D" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("x-api-key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Node.js Example for Listing Videos Source: https://docs.twelvelabs.io/sdk-reference/node-js/manage-videos This Node.js example demonstrates how to use the `list` method to fetch videos from an index. It iterates through the paginated results and logs various video properties. Ensure you have the `twelvelabs-js` library installed and replace `` with your actual index ID. ```javascript import { TwelveLabs } from "twelvelabs-js"; const videosPager = await client.indexes.videos.list(""); for await (const video of videosPager.data) { console.log(`ID: ${video.id}`); console.log(`Created at: ${video.createdAt}`); console.log(`Updated at: ${video.updatedAt || "N/A"}`); console.log(`Indexed at: ${video.indexedAt || "N/A"}`); if (video.systemMetadata) { console.log("System metadata:"); console.log(` Filename: ${video.systemMetadata.filename || "N/A"}`); console.log(` Duration: ${video.systemMetadata.duration || "N/A"}`); console.log(` FPS: ${video.systemMetadata.fps || "N/A"}`); console.log(` Width: ${video.systemMetadata.width || "N/A"}`); console.log(` Height: ${video.systemMetadata.height || "N/A"}`); console.log(` Size: ${video.systemMetadata.size || "N/A"}`); } console.log("---"); } ``` -------------------------------- ### Get Task Results in Go Source: https://docs.twelvelabs.io/api-reference/create-embeddings-v2/retrieve-embeddings Use Go's standard net/http package to construct and execute a GET request. This example reads and prints the response body. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.twelvelabs.io/v1.3/embed-v2/tasks/64f8d2c7e4a1b37f8a9c5d12" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("x-api-key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Query Videos in Go Source: https://docs.twelvelabs.io/api-reference/videos/list Use Go's net/http package to make a GET request. This example includes reading the response body. Replace '' with your actual API key. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.twelvelabs.io/v1.3/indexes/6298d673f1090f1100476d4c/videos?filename=01.mp4&duration=%7B%22gte%22%3A10%2C%22lte%22%3A10%7D&fps=%7B%22gte%22%3A25%2C%22lte%22%3A25%7D&width=%7B%22gte%22%3A1920%2C%22lte%22%3A1920%7D&height=%7B%22gte%22%3A1080%2C%22lte%22%3A1080%7D&size=%7B%22gte%22%3A1048576%2C%22lte%22%3A1048576%7D&created_at=2024-08-16T16%3A53%3A59Z&updated_at=2024-08-16T16%3A53%3A59Z" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("x-api-key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Create an Index using Swift Source: https://docs.twelvelabs.io/api-reference/indexes/list A Swift example using URLSession to make a GET request to create an index. It includes setting headers and handling the response asynchronously. ```swift import Foundation let headers = ["x-api-key": ""] let request = NSMutableURLRequest(url: NSURL(string: "https://api.twelvelabs.io/v1.3/indexes?index_name=myIndex&model_options=visual%2Caudio&model_family=marengo&created_at=2024-08-16T16%3A53%3A59Z&updated_at=2024-08-16T16%3A55%3A59Z")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Get Entity Collections with Go SDK Source: https://docs.twelvelabs.io/api-reference/entities/entity-collections/retrieve This Go example shows how to fetch entity collections using the net/http package. Replace '' with your API key. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.twelvelabs.io/v1.3/entity-collections/6298d673f1090f1100476d4c" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("x-api-key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Install Required Packages Source: https://docs.twelvelabs.io/api-reference/authentication Install the necessary HTTP client libraries for your environment. ```shell python -m pip install requests ``` ```shell npm install axios form-data ``` -------------------------------- ### Create an Index using Python SDK Source: https://docs.twelvelabs.io/api-reference/indexes/list Use the requests library to make a GET request to create an index. Ensure you have the requests library installed. ```python import requests url = "https://api.twelvelabs.io/v1.3/indexes" querystring = {"index_name":"myIndex","model_options":"visual,audio","model_family":"marengo","created_at":"2024-08-16T16:53:59Z","updated_at":"2024-08-16T16:55:59Z"} headers = {"x-api-key": ""} response = requests.get(url, headers=headers, params=querystring) print(response.json()) ``` -------------------------------- ### Initiate Multipart Upload with Python Source: https://docs.twelvelabs.io/api-reference/upload-content/multipart-uploads/create Use this Python snippet to start a multipart upload. Ensure you have the 'requests' library installed. Replace '' with your actual API key. ```python import requests url = "https://api.twelvelabs.io/v1.3/assets/multipart-uploads" payload = { "filename": "my-video.mp4", "type": "video", "total_size": 104857600 } headers = { "x-api-key": "", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` -------------------------------- ### Initiate Multipart Upload with PHP Source: https://docs.twelvelabs.io/api-reference/upload-content/multipart-uploads/create This PHP example uses the Guzzle HTTP client to initiate a multipart upload. Make sure you have Guzzle installed via Composer. Replace '' with your actual API key. ```php request('POST', 'https://api.twelvelabs.io/v1.3/assets/multipart-uploads', [ 'body' => '{ "filename": "my-video.mp4", "type": "video", "total_size": 104857600 }', 'headers' => [ 'Content-Type' => 'application/json', 'x-api-key' => '', ], ]); echo $response->getBody(); ?> ``` -------------------------------- ### Query Indexed Assets with Go SDK Source: https://docs.twelvelabs.io/api-reference/index-content/list This Go example demonstrates making an HTTP GET request to query indexed assets. It includes reading the response body. Replace '' with your actual API key. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.twelvelabs.io/v1.3/indexes/6298d673f1090f1100476d4c/indexed-assets?filename=01.mp4&duration=%7B%22gte%22%3A10%2C%22lte%22%3A10%7D&fps=%7B%22gte%22%3A25%2C%22lte%22%3A25%7D&width=%7B%22gte%22%3A1920%2C%22lte%22%3A1920%7D&height=%7B%22gte%22%3A1080%2C%22lte%22%3A1080%7D&size=%7B%22gte%22%3A1048576%2C%22lte%22%3A1048576%7D&created_at=2024-08-16T16%3A53%3A59Z&updated_at=2024-08-16T16%3A53%3A59Z" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("x-api-key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Install TwelveLabs SDK Source: https://docs.twelvelabs.io/docs/get-started/quickstart/analyze-videos Install the required SDK for your programming environment to begin interacting with the TwelveLabs API. ```shell pip install twelvelabs ``` ```shell yarn add twelvelabs-js # or npm install twelvelabs-js ``` -------------------------------- ### Query Indexed Assets with Ruby SDK Source: https://docs.twelvelabs.io/api-reference/index-content/list This Ruby example uses the Net::HTTP library to make a GET request. It handles SSL and sets the API key in the headers. Replace '' with your actual API key. ```ruby require 'uri' require 'net/http' url = URI("https://api.twelvelabs.io/v1.3/indexes/6298d673f1090f1100476d4c/indexed-assets?filename=01.mp4&duration=%7B%22gte%22%3A10%2C%22lte%22%3A10%7D&fps=%7B%22gte%22%3A25%2C%22lte%22%3A25%7D&width=%7B%22gte%22%3A1920%2C%22lte%22%3A1920%7D&height=%7B%22gte%22%3A1080%2C%22lte%22%3A1080%7D&size=%7B%22gte%22%3A1048576%2C%22lte%22%3A1048576%7D&created_at=2024-08-16T16%3A53%3A59Z&updated_at=2024-08-16T16%3A53%3A59Z") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["x-api-key"] = '' response = http.request(request) puts response.read_body ``` -------------------------------- ### Query Indexed Assets with PHP SDK Source: https://docs.twelvelabs.io/api-reference/index-content/list This PHP example uses the Guzzle HTTP client to make a GET request. Ensure you have Guzzle installed via Composer. Replace '' with your actual API key. ```php request('GET', 'https://api.twelvelabs.io/v1.3/indexes/6298d673f1090f1100476d4c/indexed-assets?filename=01.mp4&duration=%7B%22gte%22%3A10%2C%22lte%22%3A10%7D&fps=%7B%22gte%22%3A25%2C%22lte%22%3A25%7D&width=%7B%22gte%22%3A1920%2C%22lte%22%3A1920%7D&height=%7B%22gte%22%3A1080%2C%22lte%22%3A1080%7D&size=%7B%22gte%22%3A1048576%2C%22lte%22%3A1048576%7D&created_at=2024-08-16T16%3A53%3A59Z&updated_at=2024-08-16T16%3A53%3A59Z', [ 'headers' => [ 'x-api-key' => '', ], ]); echo $response->getBody(); ``` -------------------------------- ### Get Entity Collections with Swift SDK Source: https://docs.twelvelabs.io/api-reference/entities/entity-collections/retrieve Example of making a GET request for entity collections in Swift using URLSession. Replace '' with your API key. ```swift import Foundation let headers = ["x-api-key": ""] let request = NSMutableURLRequest(url: NSURL(string: "https://api.twelvelabs.io/v1.3/entity-collections/6298d673f1090f1100476d4c")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Initialize and Search with Twelve Labs SDK Source: https://docs.twelvelabs.io/docs/get-started/quickstart/search Demonstrates the full workflow of creating an index, uploading a video, monitoring status, and performing a search query. ```Python import time from twelvelabs import TwelveLabs # 1. Initialize the client client = TwelveLabs(api_key="") # 2. Create an index # An index is a container for organizing your video content index = client.indexes.create( index_name="", models=[{"model_name": "marengo3.0", "model_options": ["visual", "audio"]}] ) if not index.id: raise RuntimeError("Failed to create an index.") print(f"Created index: id={index.id}") # 3. Upload a video asset = client.assets.create( method="url", url="" # Use direct links to raw media files. Video hosting platforms and cloud storage sharing links are not supported. # Or use method="direct" and file=open("", "rb") to upload a file from the local file system ) print(f"Created asset: id={asset.id}") # 4. Check the status of the asset print("Waiting for asset to be ready...") while True: asset = client.assets.retrieve(asset.id) if asset.status == "ready": print("Asset is ready") break if asset.status == "failed": raise RuntimeError(f"Asset processing failed: id={asset.id}") time.sleep(5) # 5. Index your video indexed_asset = client.indexes.indexed_assets.create( index_id=index.id, asset_id=asset.id ) print(f"Created indexed asset: id={indexed_asset.id}") # 6. Monitor the indexing process print("Waiting for indexing to complete.") while True: indexed_asset = client.indexes.indexed_assets.retrieve( index.id, indexed_asset.id ) print(f" Status={indexed_asset.status}") if indexed_asset.status == "ready": print("Indexing complete!") break elif indexed_asset.status == "failed": raise RuntimeError("Indexing failed") time.sleep(5) # 7. Perform a search search_results = client.search.query( index_id=index.id, query_text="", search_options=["visual", "audio"] ) # 8. Process the search results print("\nSearch results:") print("Each result shows a video clip that matches your query:\n") for i, clip in enumerate(search_results): print(f"Result {i + 1}:") print(f" Video ID: {clip.video_id}") # Unique identifier of the video print(f" Rank: {clip.rank}") # Relevance ranking (1 = most relevant) print(f" Time: {clip.start}s - {clip.end}s") # When this moment occurs in the video print() ``` ```JavaScript import { TwelveLabs } from "twelvelabs-js"; // Uncomment the next line if uploading a local file // import fs from "fs"; // 1. Initialize the client const client = new TwelveLabs({ apiKey: "" }); // 2. Create an index // An index is a container for organizing your video content const index = await client.indexes.create({ indexName: "", models: [{ modelName: "marengo3.0", modelOptions: ["visual", "audio"] }] }); if (!index.id) { throw new Error("Failed to create an index."); } console.log(`Created index: id=${index.id}`); // 3. Upload a video const asset = await client.assets.create({ method: "url", url: "" // Use direct links to raw media files. Video hosting platforms and cloud storage sharing links are not supported // Or use method: "direct" and file: fs.createReadStream("") to upload a file from the local file system }); console.log(`Created asset: id=${asset.id}`); // 4. Check the status of the asset console.log("Waiting for asset to be ready..."); let readyAsset = await client.assets.retrieve(asset.id); while (readyAsset.status !== "ready" && readyAsset.status !== "failed") { await new Promise((resolve) => setTimeout(resolve, 5000)); readyAsset = await client.assets.retrieve(asset.id); } if (readyAsset.status === "failed") { throw new Error(`Asset processing failed: id=${asset.id}`); } console.log("Asset is ready"); // 5. Index your video let indexedAsset = await client.indexes.indexedAssets.create(index.id, { assetId: asset.id }); console.log(`Created indexed asset: id=${indexedAsset.id}`); // 6. Monitor the indexing process console.log("Waiting for indexing to complete."); while (true) { indexedAsset = await client.indexes.indexedAssets.retrieve( index.id, indexedAsset.id ); console.log(` Status=${indexedAsset.status}`); if (indexedAsset.status === "ready") { console.log("Indexing complete!"); break; } else if (indexedAsset.status === "failed") { throw new Error("Indexing failed"); } await new Promise(resolve => setTimeout(resolve, 5000)); } // 7. Perform a search request ``` -------------------------------- ### Initiate Multipart Upload with Go Source: https://docs.twelvelabs.io/api-reference/upload-content/multipart-uploads/create This Go program demonstrates how to initiate a multipart upload using the standard 'net/http' package. Remember to replace '' with your actual API key. ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.twelvelabs.io/v1.3/assets/multipart-uploads" payload := strings.NewReader("{\n \"filename\": \"my-video.mp4\",\n \"type\": \"video\",\n \"total_size\": 104857600\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("x-api-key", "") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Get Entity Collections with Java SDK Source: https://docs.twelvelabs.io/api-reference/entities/entity-collections/retrieve This Java example uses the Unirest library to make a GET request to retrieve entity collections. Replace '' with your API key. ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.get("https://api.twelvelabs.io/v1.3/entity-collections/6298d673f1090f1100476d4c") .header("x-api-key", "") .asString(); ``` -------------------------------- ### Initialize Python Client Source: https://docs.twelvelabs.io/docs/guides/create-embeddings/image Create a client instance to interact with the TwelveLabs Video Understanding Platform. Requires your API key. ```python from twelve_labs import TwelveLabs client = TwelveLabs("YOUR_API_KEY") ``` -------------------------------- ### Fetch Task Status (C#) Source: https://docs.twelvelabs.io/api-reference/create-embeddings-v2/retrieve-embeddings A C# example using the RestSharp library to get task status from the Twelve Labs API. This code sets up a REST client and executes a GET request. ```csharp using RestSharp; var client = new RestClient("https://api.twelvelabs.io/v1.3/embed-v2/tasks/64f8d2c7e4a1b37f8a9c5d12"); var request = new RestRequest(Method.GET); request.AddHeader("x-api-key", ""); IRestResponse response = client.Execute(request); ``` -------------------------------- ### Example Prompt for Police Report Source: https://docs.twelvelabs.io/docs/guides/analyze-videos/prompt-engineering This prompt provides an example of a police report to guide the model in generating a similar report based on surveillance footage. It includes necessary context and a structured format for the desired output. ```markdown Write a police report based on this video using the following example: Date: 11/01/2020 Location: San Francisco Police Department Witnesser’s full name: John Smith Reporter: Barbara Lim On 11/01/2020 around 5 PM, I saw a suspect walking in a retail store on Height Street… ``` -------------------------------- ### Retrieve Indexed Assets via API Source: https://docs.twelvelabs.io/api-reference/index-content/retrieve Examples for performing a GET request to the Twelve Labs indexed-assets endpoint with transcription parameters. ```python import requests url = "https://api.twelvelabs.io/v1.3/indexes/6298d673f1090f1100476d4c/indexed-assets/6298d673f1090f1100476d4c" querystring = {"transcription":"true"} headers = {"x-api-key": ""} response = requests.get(url, headers=headers, params=querystring) print(response.json()) ``` ```javascript const url = 'https://api.twelvelabs.io/v1.3/indexes/6298d673f1090f1100476d4c/indexed-assets/6298d673f1090f1100476d4c?transcription=true'; const options = {method: 'GET', headers: {'x-api-key': ''}}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.twelvelabs.io/v1.3/indexes/6298d673f1090f1100476d4c/indexed-assets/6298d673f1090f1100476d4c?transcription=true" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("x-api-key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://api.twelvelabs.io/v1.3/indexes/6298d673f1090f1100476d4c/indexed-assets/6298d673f1090f1100476d4c?transcription=true") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["x-api-key"] = '' response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.get("https://api.twelvelabs.io/v1.3/indexes/6298d673f1090f1100476d4c/indexed-assets/6298d673f1090f1100476d4c?transcription=true") .header("x-api-key", "") .asString(); ``` ```php request('GET', 'https://api.twelvelabs.io/v1.3/indexes/6298d673f1090f1100476d4c/indexed-assets/6298d673f1090f1100476d4c?transcription=true', [ 'headers' => [ 'x-api-key' => '', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://api.twelvelabs.io/v1.3/indexes/6298d673f1090f1100476d4c/indexed-assets/6298d673f1090f1100476d4c?transcription=true"); var request = new RestRequest(Method.GET); request.AddHeader("x-api-key", ""); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = ["x-api-key": ""] let request = NSMutableURLRequest(url: NSURL(string: "https://api.twelvelabs.io/v1.3/indexes/6298d673f1090f1100476d4c/indexed-assets/6298d673f1090f1100476d4c?transcription=true")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Initialize client and upload video in Python Source: https://docs.twelvelabs.io/docs/guides/search Sets up the Twelve Labs client and initiates a video upload using a URL. ```python import time from twelvelabs import TwelveLabs # 1. Initialize the client client = TwelveLabs(api_key="") # 2. Create an index # An index is a container for organizing your video content index = client.indexes.create( index_name="", models=[{"model_name": "marengo3.0", "model_options": ["visual", "audio"]}] ) if not index.id: raise RuntimeError("Failed to create an index.") print(f"Created index: id={index.id}") # 3. Upload a video asset = client.assets.create( method="url", url="" # Use direct links to raw media files. Video hosting platforms and cloud storage sharing links are not supported ``` -------------------------------- ### Python Example: Create a Video Indexing Task Source: https://docs.twelvelabs.io/sdk-reference/python/upload-content/video-indexing-tasks Use this example to create a new video indexing task by providing a video URL. Ensure you have initialized the TwelveLabs client. ```python from twelvelabs import TwelveLabs task = client.tasks.create( index_id=index.id, video_url="") print(f"Created task: id={task.id}") ``` -------------------------------- ### Initialize the Node.js client Source: https://docs.twelvelabs.io/docs/guides/search Create a client instance to interact with the TwelveLabs Video Understanding Platform. Pass your API key to authenticate requests. ```javascript const { TwelveLabs } = require("@twelvelabs/twelvelabs-js"); const client = new TwelveLabs({ apiKey: "YOUR_API_KEY", }); ``` -------------------------------- ### Get Entity Collections with PHP SDK Source: https://docs.twelvelabs.io/api-reference/entities/entity-collections/retrieve Example of fetching entity collections using GuzzleHttp in PHP. Remember to replace '' with your API key. ```php request('GET', 'https://api.twelvelabs.io/v1.3/entity-collections/6298d673f1090f1100476d4c', [ 'headers' => [ 'x-api-key' => '', ], ]); echo $response->getBody(); ``` -------------------------------- ### List Entity Collections API Requests Source: https://docs.twelvelabs.io/api-reference/entities/entity-collections/list Examples for performing a GET request to retrieve entity collections with optional query parameters for filtering and sorting. ```python import requests url = "https://api.twelvelabs.io/v1.3/entity-collections" querystring = {"name":"My entity collection","sort_by":"created_at"} headers = {"x-api-key": ""} response = requests.get(url, headers=headers, params=querystring) print(response.json()) ``` ```javascript const url = 'https://api.twelvelabs.io/v1.3/entity-collections?name=My+entity+collection&sort_by=created_at'; const options = {method: 'GET', headers: {'x-api-key': ''}}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.twelvelabs.io/v1.3/entity-collections?name=My+entity+collection&sort_by=created_at" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("x-api-key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://api.twelvelabs.io/v1.3/entity-collections?name=My+entity+collection&sort_by=created_at") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["x-api-key"] = '' response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.get("https://api.twelvelabs.io/v1.3/entity-collections?name=My+entity+collection&sort_by=created_at") .header("x-api-key", "") .asString(); ``` ```php request('GET', 'https://api.twelvelabs.io/v1.3/entity-collections?name=My+entity+collection&sort_by=created_at', [ 'headers' => [ 'x-api-key' => '', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://api.twelvelabs.io/v1.3/entity-collections?name=My+entity+collection&sort_by=created_at"); var request = new RestRequest(Method.GET); request.AddHeader("x-api-key", ""); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = ["x-api-key": ""] let request = NSMutableURLRequest(url: NSURL(string: "https://api.twelvelabs.io/v1.3/entity-collections?name=My+entity+collection&sort_by=created_at")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Initialize Node.js Client Source: https://docs.twelvelabs.io/docs/guides/create-embeddings/image Create a client instance to interact with the TwelveLabs Video Understanding Platform. Requires your API key passed as an object property. ```javascript import TwelveLabs from "@twelvelabs/twelvelabs-js"; const client = new TwelveLabs({ apiKey: "YOUR_API_KEY", }); ``` -------------------------------- ### Python Example for Creating an Async Analysis Task Source: https://docs.twelvelabs.io/sdk-reference/python/analyze-videos/async-analysis This Python example demonstrates how to use the `create` method to initiate an asynchronous video analysis task. It requires a video URL and a prompt. Note that this method is rate-limited. ```python from twelvelabs import TwelveLabs from twelvelabs.types import VideoContext_Url task = client.analyze_async.tasks.create( video=VideoContext_Url( url="", ), prompt="", temperature=0.2, ) print(f"Task ID: {task.task_id}") print(f"Status: {task.status}") ``` -------------------------------- ### Analyze Tasks with C# (RestSharp) Source: https://docs.twelvelabs.io/api-reference/analyze-videos/list-async-analysis-tasks Example using the RestSharp library in C# to make a GET request. Add RestSharp as a NuGet package to your project. ```csharp using RestSharp; var client = new RestClient("https://api.twelvelabs.io/v1.3/analyze/tasks"); var request = new RestRequest(Method.GET); request.AddHeader("x-api-key", ""); IRestResponse response = client.Execute(request); ``` -------------------------------- ### Analyze Tasks with Java (Unirest) Source: https://docs.twelvelabs.io/api-reference/analyze-videos/list-async-analysis-tasks Example using the Unirest library for Java to send an HTTP GET request. Requires Unirest to be included as a dependency. ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.get("https://api.twelvelabs.io/v1.3/analyze/tasks") .header("x-api-key", "") .asString(); ``` -------------------------------- ### Fetch Assets using Swift Source: https://docs.twelvelabs.io/api-reference/upload-content/direct-uploads/list An example in Swift demonstrating how to fetch assets using `URLSession`. Ensure your API key is provided in the headers. ```swift import Foundation let headers = ["x-api-key": ""] let request = NSMutableURLRequest(url: NSURL(string: "https://api.twelvelabs.io/v1.3/assets?asset_ids=%5B%226298d673f1090f1100476d4c%22%2C%226298d673f1090f1100476d4d%22%5D&asset_types=%5B%22image%22%2C%22video%22%5D")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Create Analyze Task - Go Source: https://docs.twelvelabs.io/api-reference/analyze-videos/create-async-analysis-task A Go example for creating an asynchronous video analysis task. It demonstrates setting headers and making a POST request. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.twelvelabs.io/v1.3/analyze/tasks" req, _ := http.NewRequest("POST", url, nil) req.Header.Add("x-api-key", "") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Update Index using PHP (Guzzle) Source: https://docs.twelvelabs.io/api-reference/indexes/update This PHP example uses the Guzzle HTTP client to update an index. Ensure you have Guzzle installed via Composer. ```php request('PUT', 'https://api.twelvelabs.io/v1.3/indexes/6298d673f1090f1100476d4c', [ 'body' => '{ "index_name": "myIndex" }', 'headers' => [ 'Content-Type' => 'application/json', 'x-api-key' => '', ], ]); echo $response->getBody(); ?> ``` -------------------------------- ### Analyze Tasks with Go Source: https://docs.twelvelabs.io/api-reference/analyze-videos/list-async-analysis-tasks Demonstrates making an HTTP GET request using Go's standard net/http package. Remember to close the response body. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.twelvelabs.io/v1.3/analyze/tasks" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("x-api-key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Multi-input Embedding Request (Swift) Source: https://docs.twelvelabs.io/api-reference/create-embeddings-v2/create-embeddings Utilize Foundation and URLSession to send a multi-input embedding request. This example shows basic setup for making the POST request. ```swift import Foundation let headers = [ "x-api-key": "", "Content-Type": "application/json" ] let request = NSMutableURLRequest(url: NSURL(string: "https://api.twelvelabs.io/v1.3/embed-v2")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Initialize TwelveLabs SDK and Create Index Source: https://docs.twelvelabs.io/docs/resources/from-the-community/media-and-entertainment Initializes the client and creates a new index with Marengo and Pegasus engines enabled. ```python client = TwelveLabs(api_key = api_key) engines = [ { "name": "marengo2.7", "options": ["visual", "conversation", "text_in_video", "logo"] }, { "name": "pegasus1", "options": ["visual", "conversation"] } ] index = client.index.create( name = "tlabs2", engines=engines, addons=["thumbnail"] # Optional ) print(f"A new index has been created: id={index.id} name={index.name} engines={index.engines}") ``` -------------------------------- ### Update Entity Collection in Swift Source: https://docs.twelvelabs.io/api-reference/entities/entity-collections/update This Swift example shows how to update an entity collection using URLSession. It includes basic setup for headers and the request body. ```swift import Foundation let headers = [ "x-api-key": "", "Content-Type": "application/json" ] let parameters = [] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.twelvelabs.io/v1.3/entity-collections/6298d673f1090f1100476d4c")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "PATCH" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Embed media with local files (Go) Source: https://docs.twelvelabs.io/api-reference/create-embeddings-v1/text-image-audio-embeddings/create-text-image-audio-embeddings This Go example demonstrates constructing a multipart form data request to embed media. It uses `strings.NewReader` to prepare the payload. ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.twelvelabs.io/v1.3/embed" payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"model_name\"\r\n\r\nmarengo3.0\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"text\"\r\n\r\nMan with a dog crossing the street\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image_url\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image_file\"; filename=\"\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_url\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_file\"; filename=\"\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_start_offset_sec\"\r\n\r\n\r\n-----011000010111000001101001--\r\n") client := &http.Client{} req, err := http.NewRequest("POST", url, payload) if err != nil { panic(err) } req.Header.Add("x-api-key", "") req.Header.Add("Content-Type", "multipart/form-data; boundary=----011000010111000001101001") resp, err := client.Do(req) if err != nil { panic(err) } defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err != nil { panic(err) } fmt.Println(string(body)) } ``` -------------------------------- ### Retrieve a Video Indexing Task (PHP) Source: https://docs.twelvelabs.io/api-reference/upload-content/tasks/retrieve This PHP example uses GuzzleHttp to retrieve a video indexing task. Ensure you have the GuzzleHttp library installed via Composer. ```php request('GET', 'https://api.twelvelabs.io/v1.3/tasks/6298d673f1090f1100476d4c', [ 'headers' => [ 'x-api-key' => '', ], ]); echo $response->getBody(); ?> ``` -------------------------------- ### Initialize TwelveLabs Client Source: https://docs.twelvelabs.io/sdk-reference/node-js/the-twelve-labs-class The `TwelveLabs` class is the main entry point for the SDK. It initializes the client and provides access to all the resources. The constructor creates a new instance of the TwelveLabs class. ```APIDOC ## Initialize TwelveLabs Client ### Description The constructor creates a new instance of the TwelveLabs class, which is the main entry point for the SDK. ### Method Constructor ### Endpoint N/A (Class constructor) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript const client = new TwelveLabs({ apiKey: "" }); ``` ### Response #### Success Response (200) Implicitly returns the newly created instance. #### Response Example ```javascript // Instance of TwelveLabs class ```