Getting started overview
Integrating CheetahO for image optimization typically follows a structured process, moving from account setup to making a functional API call. This guide focuses on the steps required to get the CheetahO API operational for developers and technical users looking to improve website performance through automated image compression.
The core steps involve:
- Account Creation: Registering for a CheetahO account to gain access to the platform.
- API Key Retrieval: Locating and securing the unique API key necessary for authenticating requests.
- First API Request: Constructing and executing an initial API call to optimize an image.
- Verification: Confirming that the optimization was successful and understanding the API response.
While CheetahO offers various plugins for Content Management Systems (CMS) like WordPress and Magento, this guide prioritizes the direct API integration path, which provides the most granular control and is foundational for custom applications. For specific CMS integrations, refer to the official CheetahO documentation.
Quick reference table
| Step | What to do | Where |
|---|---|---|
| 1. Create Account | Sign up for a new CheetahO account. | CheetahO homepage (look for 'Sign Up' or 'Get Started') |
| 2. Get API Key | Locate your unique API key in your account dashboard. | CheetahO Dashboard > API Settings or Account Settings |
| 3. Prepare Request | Choose an image (URL or file) and construct the API call. | Your development environment |
| 4. Make Request | Execute the API call using your chosen method (cURL, programming language). | Terminal or application code |
| 5. Verify Output | Check the API response for success and retrieve the optimized image. | API response body |
Create an account and get keys
Before making any API calls, you need to establish an account with CheetahO and retrieve your authentication credentials.
Account registration
Navigate to the CheetahO website and initiate the sign-up process. Most services require an email address and password for initial registration. CheetahO offers a free tier that includes 100 free optimizations, which is sufficient for initial testing and development before committing to a paid plan.
During registration, you may be asked for basic information such as your name and organization. Complete the required fields and confirm your email address if prompted.
Locating your API key
Once your account is active and you are logged into the CheetahO dashboard, locate the section dedicated to API settings or account credentials. The exact path may vary, but common locations include:
- "API Settings"
- "My Account"
- "Developer Settings"
Your API key is a unique string of characters that authenticates your requests to the CheetahO API. It acts as a token, verifying your identity and authorization for image optimization services. Treat your API key as sensitive information; do not hardcode it directly into public-facing client-side code or commit it to public version control repositories. Best practices for API key management often involve using environment variables or secure configuration files, as outlined in general API security guidelines from Google Developers.
Copy your API key from the dashboard. This key will be included in the headers or parameters of your API requests.
Your first request
With your account set up and API key in hand, you can now make your first image optimization request to the CheetahO API. The CheetahO API is a RESTful API, meaning it uses standard HTTP methods (like POST) to interact with resources.
API endpoint
The primary endpoint for image optimization is typically a URL provided in the CheetahO API documentation. An example might be https://api.cheetaho.com/optimize, but always verify the current endpoint from the official sources.
Request structure
A basic optimization request will generally involve a POST request to the optimization endpoint, with your API key included for authentication and the image data (or URL) in the request body.
Example using cURL for URL optimization
This example demonstrates optimizing an image by providing its URL. Replace YOUR_API_KEY with your actual API key and YOUR_IMAGE_URL with the URL of an image you wish to optimize.
curl -X POST \
'https://api.cheetaho.com/optimize' \
-H 'Content-Type: application/json' \
-H 'X-Cheetaho-API-Key: YOUR_API_KEY' \
-d '{ "image_url": "YOUR_IMAGE_URL", "quality": 80 }'
In this cURL command:
-X POSTspecifies the HTTP method.-H 'Content-Type: application/json'indicates that the request body is in JSON format.-H 'X-Cheetaho-API-Key: YOUR_API_KEY'passes your API key in a custom header. The exact header name (e.g.,Authorization,X-Api-Key) should be confirmed in the CheetahO API reference.-d '{ "image_url": "YOUR_IMAGE_URL", "quality": 80 }'sends the JSON payload.image_urlis the publicly accessible URL of the image to optimize, andqualityspecifies the desired compression level (e.g., 80% quality for a JPEG).
Example using Python requests library
For programmatic integration, libraries like Python's requests simplify the process.
import requests
import json
API_KEY = 'YOUR_API_KEY'
IMAGE_URL = 'YOUR_IMAGE_URL' # e.g., 'https://example.com/images/original.jpg'
CHEETAHO_API_ENDPOINT = 'https://api.cheetaho.com/optimize'
headers = {
'Content-Type': 'application/json',
'X-Cheetaho-API-Key': API_KEY # Confirm header name from docs
}
payload = {
'image_url': IMAGE_URL,
'quality': 80 # Target quality for optimization
}
try:
response = requests.post(CHEETAHO_API_ENDPOINT, headers=headers, data=json.dumps(payload))
response.raise_for_status() # Raise an exception for HTTP errors
optimized_data = response.json()
print("Optimization successful!")
print("Optimized image URL:", optimized_data.get('optimized_image_url'))
print("Original size:", optimized_data.get('original_size'))
print("Optimized size:", optimized_data.get('optimized_size'))
print("Savings:", optimized_data.get('savings'))
except requests.exceptions.HTTPError as http_err:
print(f"HTTP error occurred: {http_err}")
print("Response body:", response.text)
except requests.exceptions.ConnectionError as conn_err:
print(f"Connection error occurred: {conn_err}")
except requests.exceptions.Timeout as timeout_err:
print(f"Timeout error occurred: {timeout_err}")
except requests.exceptions.RequestException as req_err:
print(f"An error occurred: {req_err}")
Understanding the API response
A successful API call will typically return a JSON object containing details about the optimized image. Key fields often include:
optimized_image_url: A URL where the optimized image can be accessed.original_size: The size of the image before optimization (in bytes).optimized_size: The size of the image after optimization (in bytes).savings: The percentage or byte amount of size reduction.status: An indicator of success or failure.
Review the response to confirm that the image was processed as expected and to retrieve the URL for the optimized asset. This URL can then be used to serve the image on your website or application.
Common next steps
Once you've successfully made your first API call, you can expand your integration:
- Dynamic Optimization Parameters: Experiment with different quality settings, resizing options, and format conversions (e.g., converting to WebP) as supported by the CheetahO API documentation.
- Batch Processing: Implement logic to send multiple images for optimization, either sequentially or in parallel, depending on API rate limits and best practices.
- Error Handling: Develop robust error handling routines to gracefully manage API failures, network issues, or invalid image inputs.
- Storage Integration: Integrate the optimized image URLs with your content delivery network (CDN) or cloud storage solution to ensure fast global delivery.
- CMS Plugin Installation: If using a CMS, consider installing the dedicated CheetahO plugin for easier integration without direct API coding.
- Monitoring and Analytics: Set up monitoring for API usage, performance, and image savings to track the impact of optimization.
Troubleshooting the first call
Encountering issues during the initial API call is common. Here's a checklist for common problems:
- Invalid API Key: Double-check that your API key is correct and has not expired. Ensure it is placed in the correct header or parameter as specified by the CheetahO API documentation.
- Incorrect Endpoint: Verify that the API endpoint URL is accurate. A typo can lead to 404 Not Found errors.
- JSON Formatting Errors: Ensure your request body is valid JSON. Missing commas, unquoted keys, or incorrect data types can cause parsing errors (e.g., 400 Bad Request). Online JSON validators can assist with this.
- Image URL Accessibility: If optimizing by URL, confirm that the
image_urlprovided is publicly accessible and not behind a firewall or authentication. The CheetahO servers must be able to fetch the image. - Rate Limits: For free or trial accounts, check if you've exceeded the allocated number of optimizations. The CheetahO pricing page details limits.
- HTTP Method: Ensure you are using the correct HTTP method (e.g., POST for optimization requests).
- Network Issues: Temporarily disable any VPNs or firewalls that might be interfering with your outgoing requests.
- Check Status Codes: HTTP status codes provide immediate feedback:
200 OK: Success.400 Bad Request: Issue with your request (e.g., invalid JSON, missing parameters).401 Unauthorized: API key is missing or invalid.403 Forbidden: Insufficient permissions or rate limit exceeded.5xx Server Error: An issue on the CheetahO server side; typically requires waiting or contacting support.- Consult Documentation: The official CheetahO API documentation is the definitive source for troubleshooting specific error codes and request requirements.
If issues persist, gather the request details (headers, body, response) and contact CheetahO support for assistance.