Developer Quickstart
This guide walks you through the recommended “upload → wait for processing → play” flow using the AntCDN API.
Key Concepts
- Asset ID (video ID): Used for API operations (details, delete, etc).
- Edge Key: The ID you embed in players. You can rotate/revoke Edge Keys without re-uploading the video.
- Playback: Use our iframe player (
player.antcdn.net) or stream HLS playlists from the worker (worker.antcdn.net).
Get Your API Key
In the dashboard, go to Settings → API Keys and create an API key.
Caution
Save your API key somewhere safe, you won’t be able to see it again.
Get a Video to Upload
Any video will do. Need a sample video? Try this one.
Upload Your Video (Recommended)
You’ll request a pre-signed upload URL, upload the bytes directly to storage, and AntCDN will start processing automatically once the upload completes.
View:
const APIKEY = "YOUR_API_KEY"; // Created in the AntCDN dashboard
interface UploadURLRequestOptions { fileName: string; videoQuality: "standard" | "high" | "ultra"; allowPublicAccess: boolean; videoName?: string; maxEdgeLength?: 480 | 720 | 1080 | 1440 | 2160; maxFrameRate?: number; encodingMode?: "fast" | "slow"; audioCodec?: "aac" | "mp3" | "ac3" | "eac3";}
async function uploadVideo(file: File, options: UploadURLRequestOptions): Promise<string> { // Step 1: Request a pre-signed URL for direct upload const res = await fetch( `https://api.antcdn.net/v1/videos/upload-url`, { method: "POST", headers: { "X-Api-Key": APIKEY, "Content-Type": "application/json" }, body: JSON.stringify(options) } );
if (!res.ok) throw new Error(`upload-url failed: ${res.status}`); const { body } = (await res.json()) as { body: { assetId: string; signedURL: string } };
// Step 2: Upload bytes directly to object storage const putRes = await fetch(body.signedURL, { method: "PUT", // Many storage providers infer type; it's still a good idea to send it. headers: file.type ? { "Content-Type": file.type } : undefined, body: file });
if (!putRes.ok) throw new Error(`upload PUT failed: ${putRes.status}`);
// Processing starts automatically after upload completes. return body.assetId;}
// Minimal usage example (browser)const input = document.querySelector<HTMLInputElement>("#video")!;const file = input.files?.[0];if (!file) throw new Error("No file selected");
const assetId = await uploadVideo(file, { fileName: file.name, videoQuality: "high", allowPublicAccess: true});import requests
APIKEY = "YOUR_API_KEY" # Created in the AntCDN dashboard
def upload_video(file_path: str, file_name: str) -> str: # Step 1: Request a pre-signed URL for direct upload upload_response = requests.post( 'https://api.antcdn.net/v1/videos/upload-url', headers={ 'X-Api-Key': APIKEY, 'Content-Type': 'application/json' }, json={ 'fileName': file_name, 'videoQuality': 'high', 'allowPublicAccess': True } )
upload_response.raise_for_status() body = upload_response.json()['body']
# Step 2: Upload bytes directly to object storage with open(file_path, 'rb') as f: put_res = requests.put(body['signedURL'], data=f) put_res.raise_for_status()
# Processing starts automatically after upload completes. return body['assetId']package main
import ( "bytes" "encoding/json" "fmt" "io" "net/http" "os")
const APIKEY = "YOUR_API_KEY" // Created in the AntCDN dashboard
type UploadURLRequest struct { FileName string `json:"fileName"` VideoQuality string `json:"videoQuality"` AllowPublicAccess bool `json:"allowPublicAccess"`}
type UploadURLResponse struct { Body struct { SignedURL string `json:"signedURL"` AssetId string `json:"assetId"` } `json:"body"`}
func uploadVideo(filePath, fileName string) (string, error) { // Step 1: Request a pre-signed URL for direct upload reqBody, _ := json.Marshal(UploadURLRequest{ FileName: fileName, VideoQuality: "high", AllowPublicAccess: true, })
req, _ := http.NewRequest("POST", "https://api.antcdn.net/v1/videos/upload-url", bytes.NewBuffer(reqBody)) req.Header.Set("X-Api-Key", APIKEY) req.Header.Set("Content-Type", "application/json")
client := &http.Client{} resp, err := client.Do(req) if err != nil { return "", err } defer resp.Body.Close()
var uploadResp UploadURLResponse if err := json.NewDecoder(resp.Body).Decode(&uploadResp); err != nil { return "", err }
// Step 2: Upload bytes directly to object storage file, err := os.Open(filePath) if err != nil { return "", err } defer file.Close()
putReq, _ := http.NewRequest("PUT", uploadResp.Body.SignedURL, file) putResp, err := client.Do(putReq) if err != nil { return "", err } defer putResp.Body.Close() io.Copy(io.Discard, putResp.Body) if putResp.StatusCode < 200 || putResp.StatusCode >= 300 { return "", fmt.Errorf("upload PUT failed: %s", putResp.Status) }
// Processing starts automatically after upload completes. return uploadResp.Body.AssetId, nil}const APIKEY = "YOUR_API_KEY"; // Created in the AntCDN dashboard
interface UploadVideoOptions { // Common options fileName: string; allowPublicAccess: boolean; videoQuality?: "standard" | "high" | "ultra";
// Optional videoName?: string; maxEdgeLength?: 480 | 720 | 1080 | 1440 | 2160; maxFrameRate?: number; encodingMode?: "fast" | "slow"; audioCodec?: "aac" | "aac-he" | "aac-he-v2" | "mp3" | "ac3" | "eac3";}
async function uploadVideo(file: File, options: UploadVideoOptions): Promise<string> { // Step 1: Request a pre-signed URL for direct upload const uploadResponse = await fetch( `https://api.antcdn.net/v1/videos/upload-url`, { method: "POST", headers: { "X-Api-Key": APIKEY, "Content-Type": "application/json" }, body: JSON.stringify(options) } );
if (!uploadResponse.ok) throw new Error(`upload-url failed: ${uploadResponse.status}`); const { body } = (await uploadResponse.json()) as { body: { assetId: string; signedURL: string; bucketPath: string; expiresAt: number }; };
// Step 2: Upload bytes directly to object storage const putRes = await fetch(body.signedURL, { method: "PUT", headers: file.type ? { "Content-Type": file.type } : undefined, body: file });
if (!putRes.ok) throw new Error(`upload PUT failed: ${putRes.status}`);
// Processing starts automatically after upload completes. return body.assetId;}
// Example usage with all optionsconst file = new File([/* bytes */], "video.mp4", { type: "video/mp4" });const assetId = await uploadVideo(file, { fileName: file.name, allowPublicAccess: true, videoQuality: "ultra", videoName: "My Firat Video", maxEdgeLength: 1080, maxFrameRate: 60, encodingMode: "slow", audioCodec: "aac"});import requestsfrom typing import Optional, Literal
APIKEY = "YOUR_API_KEY" # Created in the AntCDN dashboard
def upload_video( file_path: str, file_name: str, allow_public_access: bool, video_quality: Literal["standard", "high", "ultra"] = "standard", # Optional parameters video_name: Optional[str] = None, max_edge_length: Optional[int] = None, max_frame_rate: Optional[int] = None, encoding_mode: Optional[Literal["fast", "slow"]] = None, audio_codec: Optional[Literal["aac", "aac-he", "aac-he-v2", "mp3", "ac3", "eac3"]] = None) -> str: # Step 1: Build request body with all options request_body = { 'fileName': file_name, 'allowPublicAccess': allow_public_access, 'videoQuality': video_quality, }
# Add optional parameters if provided if video_name: request_body['videoName'] = video_name if max_edge_length: request_body['maxEdgeLength'] = max_edge_length if max_frame_rate: request_body['maxFrameRate'] = max_frame_rate if encoding_mode: request_body['encodingMode'] = encoding_mode if audio_codec: request_body['audioCodec'] = audio_codec
# Step 2: Request a pre-signed URL for direct upload upload_response = requests.post( 'https://api.antcdn.net/v1/videos/upload-url', headers={ 'X-Api-Key': APIKEY, 'Content-Type': 'application/json' }, json=request_body )
upload_response.raise_for_status() body = upload_response.json()['body']
# Step 3: Upload bytes directly to object storage with open(file_path, 'rb') as f: put_res = requests.put(body['signedURL'], data=f) put_res.raise_for_status()
# Processing starts automatically after upload completes. return body['assetId']
# Example usage with all optionsvideo_id = upload_video( file_path="/path/to/video.mp4", file_name="video.mp4", allow_public_access=False, video_quality="ultra", video_name="Product Demo 2024", max_edge_length=1080, max_frame_rate=60, encoding_mode="slow", audio_codec="aac")package main
import ( "bytes" "encoding/json" "fmt" "io" "net/http" "os")
const APIKEY = "YOUR_API_KEY" // Created in the AntCDN dashboard
type UploadURLRequest struct { FileName string `json:"fileName"` AllowPublicAccess bool `json:"allowPublicAccess"` VideoQuality string `json:"videoQuality,omitempty"`
// Optional VideoName *string `json:"videoName,omitempty"` MaxEdgeLength *int `json:"maxEdgeLength,omitempty"` MaxFrameRate *int `json:"maxFrameRate,omitempty"` EncodingMode *string `json:"encodingMode,omitempty"` AudioCodec *string `json:"audioCodec,omitempty"`}
type UploadURLResponse struct { Body struct { SignedURL string `json:"signedURL"` AssetId string `json:"assetId"` } `json:"body"`}
func uploadVideo(filePath string, req UploadURLRequest) (string, error) { // Step 1: Request a pre-signed URL for direct upload reqBody, _ := json.Marshal(req)
httpReq, _ := http.NewRequest("POST", "https://api.antcdn.net/v1/videos/upload-url", bytes.NewBuffer(reqBody)) httpReq.Header.Set("X-Api-Key", APIKEY) httpReq.Header.Set("Content-Type", "application/json")
client := &http.Client{} resp, err := client.Do(httpReq) if err != nil { return "", err } defer resp.Body.Close()
var uploadResp UploadURLResponse json.NewDecoder(resp.Body).Decode(&uploadResp)
// Step 2: Upload bytes directly to object storage file, _ := os.Open(filePath) defer file.Close()
putReq, _ := http.NewRequest("PUT", uploadResp.Body.SignedURL, file) putResp, err := client.Do(putReq) if err != nil { return "", err } defer putResp.Body.Close() io.Copy(io.Discard, putResp.Body) if putResp.StatusCode < 200 || putResp.StatusCode >= 300 { return "", fmt.Errorf("upload PUT failed: %s", putResp.Status) }
// Processing starts automatically after upload completes. return uploadResp.Body.AssetId, nil}
// Example usage with all optionsfunc main() { videoName := "Product Demo 2024" maxEdge := 1080 frameRate := 60 encoding := "slow" codec := "aac"
assetId, _ := uploadVideo("/path/to/video.mp4", UploadURLRequest{ FileName: "video.mp4", AllowPublicAccess: false, VideoQuality: "ultra", VideoName: &videoName, MaxEdgeLength: &maxEdge, MaxFrameRate: &frameRate, EncodingMode: &encoding, AudioCodec: &codec, })
fmt.Println("Video ID:", assetId)}See Your Video in the Dashboard
Navigate to app.antcdn.net to see your video.
Play Your Video
Once processing finishes, create (or use) an Edge Key and embed it.
<!-- Embed the AntCDN player using an Edge Key --><iframe src="https://player.antcdn.net/v1/{edgeKey}/master.m3u8?autoplay=true&muted=true" frameborder="0" allowfullscreen></iframe>If you want to stream HLS directly (without the iframe player), see the Video Playback and Video Player sections.