Getting started overview

To begin using Bunny.net's services, such as BunnyCDN, Bunny Stream, or Bunny Storage, the initial steps involve account creation, generation of API keys, and then making a first authenticated request. This process establishes the necessary credentials for programmatic interaction with Bunny.net's infrastructure, enabling developers to manage and deliver content efficiently.

The workflow typically follows these stages:

  1. Account Creation: Register for a Bunny.net account.
  2. API Key Generation: Obtain an API key from the Bunny.net control panel.
  3. Service Configuration: Set up a pull zone for CDN, a storage zone, or a video library, depending on the desired service.
  4. First API Request: Execute a basic API call using the generated key to verify authentication and connectivity.

This guide focuses on these core steps to get a functional interaction established quickly.

Quick Reference Table

Step What to do Where
1. Sign Up Create a new Bunny.net account. Bunny.net homepage
2. Get API Key Locate and copy your API key from the account settings. Bunny.net Control Panel > Account Settings > API
3. Configure Service (e.g., CDN) Create a Pull Zone and link it to your origin server. Bunny.net Control Panel > CDN > Pull Zones > Add Pull Zone
4. Make First Request Use curl or an SDK to fetch content via the CDN or interact with storage. Command line or preferred development environment

Create an account and get keys

To access Bunny.net's services, users must first register for an account. Navigate to the Bunny.net website and follow the sign-up process. Bunny.net operates on a pay-as-you-go model, with a minimum charge of $1 per month once services are utilized, rather than a dedicated free tier.

After account creation and login, the next critical step is to obtain your API key. This key is used for authenticating all programmatic interactions with Bunny.net's API. The process for retrieving the API key is as follows:

  1. Log in to the Bunny.net Control Panel.
  2. Navigate to Account Settings.
  3. Select the API tab.
  4. Your API Key will be displayed. Copy this key securely. This key grants full access to your account's resources, so it should be treated with the same confidentiality as a password.

Bunny.net provides a comprehensive API documentation that details the various endpoints and authentication methods, which primarily rely on this API key.

Your first request

Before making an API request, it is often necessary to configure a service within the Bunny.net control panel. For example, to use BunnyCDN, you would create a Pull Zone, which links your origin server to Bunny.net's global network. For Bunny Storage, you would create a Storage Zone. For Bunny Stream, a Video Library is required.

Once a service is configured, you can make your first API request. This example demonstrates a simple request to list pull zones using the Bunny.net API. Replace YOUR_API_KEY with the key obtained from your account settings.

Example: List Pull Zones (Node.js)


const axios = require('axios');

const API_KEY = 'YOUR_API_KEY'; // Replace with your actual API key
const BASE_URL = 'https://api.bunny.net';

async function listPullZones() {
  try {
    const response = await axios.get(`${BASE_URL}/pullzone`, {
      headers: {
        'AccessKey': API_KEY,
        'Accept': 'application/json'
      }
    });
    console.log('Successfully listed pull zones:');
    console.log(response.data);
  } catch (error) {
    console.error('Error listing pull zones:', error.response ? error.response.data : error.message);
  }
}

listPullZones();

This Node.js example uses the axios library to make an HTTP GET request to the /pullzone endpoint. The API key is passed in the AccessKey header, as specified in the Bunny.net API reference. Ensure you have axios installed (npm install axios) before running this script.

Example: List Storage Zones (Python)


import requests

API_KEY = 'YOUR_API_KEY'  # Replace with your actual API key
BASE_URL = 'https://api.bunny.net'

def list_storage_zones():
    headers = {
        'AccessKey': API_KEY,
        'Accept': 'application/json'
    }
    try:
        response = requests.get(f"{BASE_URL}/storagezone", headers=headers)
        response.raise_for_status()  # Raise an HTTPError for bad responses (4xx or 5xx)
        print("Successfully listed storage zones:")
        print(response.json())
    except requests.exceptions.HTTPError as http_err:
        print(f"HTTP error occurred: {http_err} - {response.text}")
    except Exception as err:
        print(f"An error occurred: {err}")

if __name__ == "__main__":
    list_storage_zones()

This Python example uses the requests library to perform a GET request to the /storagezone endpoint, authenticating with the AccessKey header. Install requests using pip install requests.

Common next steps

After successfully making your first API call, several common next steps can further integrate Bunny.net into your application or workflow:

  • Configure CDN Pull Zones: If you're using BunnyCDN, set up one or more Pull Zones. This involves specifying your origin server and configuring caching rules, security features like hotlink protection, and custom hostnames.
  • Upload to Bunny Storage: For asset hosting, explore Bunny Storage. You can use the API to upload, download, and manage files within your storage zones.
  • Implement Bunny Stream: For video content, utilize Bunny Stream to upload, encode, and deliver videos. This includes creating video libraries and retrieving stream URLs.
  • Explore Bunny Optimizer: Integrate Bunny Optimizer for image optimization and web asset manipulation. This service can automatically resize, compress, and convert images on the fly.
  • Review API Reference: Consult the Bunny.net API documentation for specific endpoints related to your use case. The documentation provides detailed parameters and responses for each service.
  • Set up DNS: For custom domains, configure your DNS records (e.g., CNAME) to point to Bunny.net's CDN endpoints. This is a standard practice for content delivery networks, as outlined in general DNS CNAME record documentation.
  • Monitor Usage and Billing: Regularly check your usage statistics and billing in the control panel to understand costs associated with data transfer and storage, as per the Bunny.net pricing structure.

Troubleshooting the first call

When encountering issues with your initial API requests to Bunny.net, consider the following common troubleshooting steps:

  • Incorrect API Key: Double-check that the AccessKey header contains the exact API key copied from your Bunny.net account settings. Even minor typos or leading/trailing spaces can cause authentication failures. The API key is case-sensitive.
  • Missing or Incorrect Header: Ensure that the AccessKey header is present in your request and correctly formatted. Also, verify that the Accept: application/json header is included, as Bunny.net's API typically responds with JSON.
  • Network Connectivity Issues: Verify that your development environment has stable internet access and can reach https://api.bunny.net. Firewall rules or proxy settings might block outbound connections.
  • API Endpoint Errors: Confirm that the URL for your API request is correct. Refer to the Bunny.net API reference for the precise endpoints for each operation (e.g., /pullzone, /storagezone).
  • Service Not Configured: For services like CDN or storage, ensure you have created the necessary zones (e.g., Pull Zone, Storage Zone, Video Library) in the Bunny.net control panel before attempting to interact with them via the API. An API call to list pull zones will return an empty array if no zones exist.
  • HTTP Status Codes: Pay attention to the HTTP status code returned in the API response.
    • 401 Unauthorized: Typically indicates an issue with the API key or authentication header.
    • 403 Forbidden: May imply insufficient permissions or a problem with the API key.
    • 404 Not Found: Often means the endpoint URL is incorrect or the resource does not exist.
    • 5xx Server Error: Indicates an issue on Bunny.net's side. If this persists, check the Bunny.net status page.
  • SDK Specific Issues: If using one of Bunny.net's SDKs (PHP, Node.js, Python, Go, Ruby, C#), ensure it is correctly installed and configured. Check the SDK's documentation for any specific initialization requirements or error handling.
  • Review Error Messages: Bunny.net's API typically returns descriptive error messages in JSON format. Parse these messages to gain insight into the problem.