Getting started overview

Integrating STAPI into your application involves a series of steps designed to get you from account creation to your first successful video operation. This guide covers the essential requirements and actions to begin using STAPI's video and streaming capabilities. The typical journey starts with setting up your STAPI account, securing your API credentials, and then executing a basic API call to confirm your setup. This foundational process enables you to then build more complex video workflows, such as live streaming, video-on-demand (VOD) services, or video analytics, all supported by STAPI's infrastructure.

STAPI provides client SDKs for several programming languages, including JavaScript, Python, Node.js, Ruby, Go, and PHP. These SDKs are designed to simplify interaction with the STAPI API by abstracting HTTP request details and providing language-specific methods for common operations like video upload, encoding, and playback. For direct HTTP interactions without an SDK, developers can refer to the STAPI API reference documentation.

Quick Reference: STAPI Getting Started Steps

Step What to Do Where
1. Create Account Register for a STAPI account. STAPI Signup Page
2. Get API Keys Generate and securely store your API Key and Secret. STAPI Dashboard > API Settings
3. Install SDK (Optional) Install the STAPI SDK for your preferred language. STAPI SDK Documentation
4. Configure SDK/Client Initialize the SDK or set up HTTP client with your API keys. Your application code
5. Make First Request Upload a test video or list existing videos. Your application code / STAPI Upload Video API
6. Verify Success Confirm the video operation completed successfully. STAPI Dashboard > Videos / Application Logs

Create an account and get keys

Before making any API calls, you need to create a STAPI account and obtain your API credentials. These credentials authenticate your requests and link them to your account for billing and access control.

  1. Sign up for a STAPI account: Navigate to the STAPI signup page. You can start with the Developer Plan, which offers a free tier including 5 GB of video storage and 10 GB of bandwidth, suitable for testing and development.
  2. Access your Dashboard: After successful registration and login, you will be directed to your STAPI dashboard.
  3. Locate API Keys: In the dashboard, typically under a section like "API Settings" or "Credentials," you will find your unique API Key and API Secret. The API Key identifies your account, and the API Secret is used to sign your requests, ensuring their authenticity.

Security Best Practices:

  • Treat your API Secret like a password. Do not hardcode it directly into client-side code, commit it to version control, or expose it publicly.
  • Use environment variables for server-side applications or secure secret management services to store your API keys. For more information on securing API keys, consult resources like Google Cloud's API key security documentation.
  • Rotate your API keys periodically, especially if you suspect they might have been compromised.

Your first request

To confirm your STAPI setup, let's make a simple request to upload a video. This example will use the Node.js SDK, one of the primary languages supported by STAPI. Equivalent examples are available for other STAPI SDKs.

Prerequisites:

  • Node.js installed on your system.
  • Your STAPI API Key and API Secret.
  • A small video file (e.g., my-test-video.mp4) for upload.

Step 1: Install the Node.js SDK

npm install stapi-node-sdk

Step 2: Create your application file (e.g., uploadVideo.js)

const STAPI = require('stapi-node-sdk');
const path = require('path');
const fs = require('fs');

// Replace with your actual API Key and Secret
const API_KEY = process.env.STAPI_API_KEY || 'YOUR_STAPI_API_KEY';
const API_SECRET = process.env.STAPI_API_SECRET || 'YOUR_STAPI_API_SECRET';

const stapi = new STAPI({ apiKey: API_KEY, apiSecret: API_SECRET });

async function uploadTestVideo() {
  try {
    const videoPath = path.join(__dirname, 'my-test-video.mp4'); // Ensure this file exists
    if (!fs.existsSync(videoPath)) {
      console.error('Error: my-test-video.mp4 not found. Please create or specify correct path.');
      process.exit(1);
    }

    console.log('Attempting to upload video...');
    const uploadResult = await stapi.videos.upload({
      file: fs.createReadStream(videoPath),
      title: 'My First STAPI Video',
      description: 'A test video uploaded via the Node.js SDK',
      tags: ['test', 'getting-started']
    });

    console.log('Video uploaded successfully!');
    console.log('Video ID:', uploadResult.id);
    console.log('Playback URL:', uploadResult.playback_url);
    console.log('Details:', uploadResult);

  } catch (error) {
    console.error('Error uploading video:', error.message);
    if (error.response && error.response.data) {
      console.error('API Error Details:', error.response.data);
    }
    process.exit(1);
  }
}

uploadTestVideo();

Step 3: Run the script

Ensure your my-test-video.mp4 file is in the same directory as uploadVideo.js, or update the videoPath variable. It's recommended to set your API keys as environment variables:

export STAPI_API_KEY="YOUR_STAPI_API_KEY"
export STAPI_API_SECRET="YOUR_STAPI_API_SECRET"
node uploadVideo.js

Upon successful execution, the script will output the video ID and its playback URL, confirming that your credentials are correct and your first API call was successful. You can also verify the upload by checking your STAPI dashboard under the "Videos" section.

Common next steps

After successfully making your first request, you can explore STAPI's broader capabilities to integrate advanced video features into your applications:

  • Video on Demand (VOD): Utilize STAPI's VOD features to store, encode, and deliver pre-recorded videos efficiently. This includes managing video metadata, generating thumbnails, and ensuring adaptive bitrate streaming for optimal playback across various devices and network conditions. Refer to the STAPI VOD documentation for detailed guides.
  • Live Streaming: Implement live video broadcasts with STAPI's live streaming API. This involves setting up streams, managing viewers, and handling real-time video ingestion and distribution. The STAPI live streaming section provides information on stream setup and event handling.
  • Video Encoding and Transcoding: Understand how STAPI automatically encodes and transcodes videos to various formats and resolutions, suitable for different devices and bandwidths. You can configure encoding profiles or rely on default settings to ensure broad compatibility.
  • Video Analytics: Integrate STAPI's analytics tools to gain insights into video performance, viewer engagement, and streaming quality. This data can help optimize your content strategy and user experience. Check the STAPI video analytics documentation for available metrics and integration options.
  • Webhooks: Set up webhooks to receive real-time notifications about video processing events (e.g., upload complete, encoding finished). Webhooks are crucial for building responsive applications that react to changes in video status without constant polling. Learn more about STAPI webhooks.
  • Security and Access Control: Explore STAPI's options for securing your video content, including token-based authentication for playback and content encryption. Implementing proper access control ensures only authorized users can view your videos.
  • Explore SDKs and Libraries: Deepen your understanding of the STAPI SDKs for your chosen language. Each SDK offers specific utility functions and simplifies common tasks, reducing the boilerplate code you need to write. The STAPI SDK overview lists all available libraries.

Troubleshooting the first call

Encountering issues during your first API call is common. Here are some steps to diagnose and resolve typical problems:

  • Invalid API Key/Secret:
    • Symptom: Authentication errors (e.g., HTTP 401 Unauthorized).
    • Solution: Double-check that you have copied your API Key and API Secret correctly from your STAPI dashboard. Ensure there are no leading or trailing spaces. Verify that you are using the correct keys for the environment (e.g., development vs. production, if applicable).
  • Network Issues:
    • Symptom: Connection timeouts or network unreachable errors.
    • Solution: Confirm your internet connection is stable. Check if any firewalls or proxies are blocking outgoing connections to STAPI's API endpoints. If you are in a corporate environment, you might need to configure proxy settings.
  • Incorrect File Path or Permissions:
    • Symptom: File not found errors when attempting to upload a video.
    • Solution: Verify that the path to your video file in the code is absolutely correct. Ensure the application running the script has read permissions for the video file.
  • Missing Dependencies (SDK):
    • Symptom: "Module not found" errors when running the SDK example.
    • Solution: Ensure you have installed the STAPI SDK and any other necessary dependencies using your package manager (e.g., npm install for Node.js, pip install for Python).
  • API Rate Limits:
    • Symptom: HTTP 429 Too Many Requests errors.
    • Solution: While unlikely for a first call, repeated rapid calls can trigger rate limits. Implement exponential backoff for retries in production environments. Consult the STAPI rate limit documentation.
  • Server-Side Errors (STAPI):
    • Symptom: HTTP 5xx errors.
    • Solution: These indicate an issue on STAPI's end. Check the STAPI status page for any ongoing incidents. If no incidents are reported, contact STAPI support with your request details and any error messages.
  • Verbose Logging:
    • Solution: Enable verbose logging in your HTTP client or SDK, if available, to get more detailed information about the request and response. This can often reveal subtle issues with headers, request body, or endpoint URLs.