Getting started overview
This guide provides a structured approach to initiating development with Hirak FaceAPI. It covers the fundamental steps required to go from account creation to successfully executing a first API call. Hirak FaceAPI offers functionalities for tasks such as user authentication, identity verification, and emotion analysis.
The process involves:
- Creating a Hirak account.
- Obtaining API keys (API Key and API Secret).
- Preparing an environment for API calls.
- Making a basic authenticated request.
Hirak provides comprehensive documentation and API reference to support developers through this process, including code examples in multiple languages like Python and cURL.
Quick reference table
| Step | What to do | Where |
|---|---|---|
| 1. Sign Up | Create a new Hirak account. | Hirak Homepage |
| 2. Get API Keys | Locate your API Key and API Secret in the developer dashboard. | Hirak Developer Dashboard |
| 3. Choose SDK/Method | Select a preferred SDK (Python, Node.js, etc.) or use cURL. | Hirak Documentation |
| 4. Make First Call | Send an authenticated request to a Hirak FaceAPI endpoint. | Your chosen development environment |
| 5. Review Response | Check the API response for success or error messages. | API client/console output |
Create an account and get keys
To access Hirak FaceAPI, developers must first register for an account. This process typically involves providing an email address and creating a password. Upon successful registration, users gain access to the Hirak developer dashboard.
Account Registration
- Navigate to the Hirak homepage.
- Click on the "Sign Up" or "Get Started" button.
- Follow the prompts to create your account, providing necessary details.
- Verify your email address if prompted, which is a common security measure for API platforms to ensure account authenticity (see OAuth 2.0 for Native Apps for general secure registration practices).
Obtaining API Keys
After creating and logging into your Hirak account, your API credentials will be available in the developer dashboard. These credentials typically consist of an API Key and an API Secret. These keys are crucial for authenticating your requests to the Hirak FaceAPI.
- Log in to your Hirak developer dashboard.
- Locate the "API Keys" or "Credentials" section.
- Copy your unique API Key and API Secret. It is recommended to store these securely and avoid hardcoding them directly into your application's source code. Environment variables or secure configuration management are preferred methods for handling sensitive credentials.
Hirak offers a free tier that includes 500 API calls per month, allowing developers to test and integrate the API without immediate cost.
Your first request
Making your first request involves selecting a method (cURL or an SDK), setting up authentication, and sending a basic API call. For this example, we will use the Face Recognition API to detect faces in an image.
Using cURL
cURL is a command-line tool and library for transferring data with URLs, making it suitable for quick tests and direct API interaction. Ensure you replace YOUR_API_KEY, YOUR_API_SECRET, and IMAGE_URL_OR_PATH with your actual credentials and image data.
curl -X POST "https://api.hirak.ai/v1/face/detect" \
-H "Content-Type: application/json" \
-H "X-API-KEY: YOUR_API_KEY" \
-H "X-API-SECRET: YOUR_API_SECRET" \
-d '{"image_url": "https://example.com/your-image.jpg", "return_attributes": "gender,age,emotion"}'
This cURL command sends a POST request to the /v1/face/detect endpoint, providing an image URL and requesting specific attributes like gender, age, and emotion. The API Key and Secret are passed in the X-API-KEY and X-API-SECRET headers for authentication.
Using Python SDK
Hirak provides official SDKs for several languages, including Python. First, install the SDK:
pip install hirak-faceapi
Then, use the following Python code to make a face detection request:
import os
from hirak_faceapi import HirakFaceAPI
api_key = os.environ.get("HIRAK_API_KEY")
api_secret = os.environ.get("HIRAK_API_SECRET")
if not api_key or not api_secret:
raise ValueError("HIRAK_API_KEY and HIRAK_API_SECRET environment variables must be set.")
client = HirakFaceAPI(api_key=api_key, api_secret=api_secret)
image_url = "https://example.com/your-image.jpg" # Replace with your image URL
try:
response = client.face.detect(
image_url=image_url,
return_attributes=["gender", "age", "emotion"]
)
print(response.json())
except Exception as e:
print(f"An error occurred: {e}")
This Python example demonstrates initializing the HirakFaceAPI client with API keys retrieved from environment variables for security. It then calls the face.detect method with an image URL and desired attributes. For more details on environment variable usage, refer to Mozilla Developer Network's guide on environment variables.
Common next steps
After successfully making your first API call, consider these next steps to further integrate Hirak FaceAPI into your application:
- Explore other endpoints: Review the API reference for other functionalities like Face Verification, Liveness Detection, or Emotion Recognition.
- Implement error handling: Integrate robust error handling into your code to manage API rate limits, invalid inputs, and other potential issues.
- Secure API keys: Transition from testing with hardcoded keys to using secure methods for storing and accessing credentials, such as environment variables, secret management services, or encrypted configuration files.
- Review SDKs: If not already using one, consider leveraging a Hirak SDK for your preferred language (Python, Node.js, Java, PHP, Ruby) to simplify API interaction and reduce boilerplate code.
- Monitor usage: Utilize the Hirak developer dashboard to monitor your API call usage and manage your subscription.
- Optimize image input: Understand the recommended image formats, sizes, and quality for optimal face detection and recognition results.
- Consider advanced features: Explore features like face tracking, facial landmark detection, or custom face sets for more complex use cases.
Troubleshooting the first call
Encountering issues during your first API call is common. Here are some troubleshooting tips:
- Check API Keys: Verify that your API Key and API Secret are correct and have not been truncated or mistyped. Ensure they are included in the correct headers (
X-API-KEY,X-API-SECRET) or parameters as specified in the Hirak documentation. - Review Request Body/Parameters: Confirm that the JSON payload or form data sent in your request matches the expected format for the specific endpoint. Pay attention to required fields and data types.
- Endpoint URL: Double-check that you are sending the request to the correct Hirak FaceAPI endpoint URL.
- Network Connectivity: Ensure your development environment has a stable internet connection and is not blocked by firewalls or proxy settings.
- Rate Limits: If you receive a
429 Too Many Requestserror, you may have exceeded your free tier or paid plan's rate limits. Check your usage in the Hirak dashboard. - Error Messages: Carefully read the error messages returned by the API. They often contain specific information that can help diagnose the problem. Common HTTP status codes and their meanings are outlined in the Hirak API reference. For general understanding of HTTP status codes, consult the W3C HTTP/1.1 Status Code Definitions.
- Image Accessibility: If using an image URL, ensure the URL is publicly accessible and the image format is supported by Hirak FaceAPI.
- SDK Specific Issues: If using an SDK, ensure it is the latest version and correctly initialized with your credentials. Refer to the SDK's specific documentation for common issues.
- Contact Support: If you've exhausted these options, Hirak's support channels can provide further assistance.