Overview
This guide covers best practices, optimization techniques, and advanced features to help you get the most out of the WeryAI API.API Basics
Base URL
Request Format
All API requests should use:- Method: POST for generation endpoints, GET for query endpoints
- Content-Type:
application/json - Authorization:
Bearer YOUR_API_KEY
Response Format
All responses follow a consistent structure:Authentication
Securing Your API Key
Best Practices:-
Store API keys in environment variables:
-
Use a backend proxy to make API calls:
- Rotate keys regularly from the API Keys page
- If a key is compromised, immediately delete the old key and create a new one on the API Keys page
Webhook Integration
Setting Up Webhooks
Webhooks allow you to receive results asynchronously without polling. Add thewebhook_url parameter to your request:
Webhook Response
When the task completes, WeryAI sends a POST request to your webhook URL:Handling Webhook Requests
Here’s a simple example of webhook handling:Optimizing Generation Quality
Writing Better Prompts
Examples: ❌ Bad: “a cat” ✅ Good: “A fluffy orange tabby cat sitting on a windowsill, soft natural lighting, photorealistic, high detail” Prompt Tips:- Be specific: Include details about style, lighting, composition
- Use descriptive adjectives: “vibrant”, “dramatic”, “soft”, “detailed”
- Specify quality: “high quality”, “8k”, “professional”
- Add style keywords: “photorealistic”, “anime style”, “oil painting”
Using Negative Prompts
Negative prompts help exclude unwanted elements:Aspect Ratio Selection
Choose the right aspect ratio for your use case:- 1:1 - Profile pictures, thumbnails, social media posts
- 16:9 - Widescreen, YouTube thumbnails, presentations
- 9:16 - Vertical video, Instagram Stories, TikTok
- 4:3 - Traditional displays
- 21:9 - Ultra-wide, cinematic
Error Handling
Common Error Codes
| Status Code | Description | Solution |
|---|---|---|
| 1001 | Parameter error | Check request parameter format and required fields |
| 1002 | Unauthorized | Verify your API key is correct |
| 1003 | Not found | Check if task ID or batch ID is valid |
| 1004 | Insufficient credits | Go to Pricing page to purchase credits |
| 1005 | Content moderation failed | Modify prompt to avoid sensitive content |
Robust Error Handling
Implement comprehensive error handling:Task Status Polling
Polling Best Practices
When not using Webhooks, you need to poll for task status:We recommend a polling interval of 3-5 seconds. Too frequent polling wastes resources, while too long intervals affect user experience.
Credit Management
Monitor Credit Balance
Regularly check your account credit balance to avoid service interruptions:- Visit the Pricing page to view real-time balance
- Pay attention to balance-related information in API responses
- Set up balance alerts and recharge in time when credits are low
Optimize Credit Usage
Different models consume different amounts of credits. Choose the right model to optimize costs:Monitoring and Debugging
Using WeryAI Platform Features
WeryAI platform provides comprehensive monitoring and management features:API Key Management
Create, view, copy, and delete API keys
Call History
View all API request records and details
Credit Balance
View credit balance in real-time and purchase credits
Model Rates
Learn about credit consumption for different models
Call History Features
On the Call History page you can:- View complete records of all API requests
- Search for specific API calls by request ID
- View detailed information for each request (time, method, path, status code, duration)
- Analyze API call patterns and frequency
- Quickly locate and debug issues
Local Logging
In addition to platform features, implement logging in your application:Best Practices Summary
Security
- Store API keys in environment variables
- Call API through backend proxy
- Rotate keys regularly
- Delete compromised keys immediately
Reliability
- Implement comprehensive error handling
- Use Webhooks for async results
- Set reasonable polling intervals
- Keep detailed logs
Cost Optimization
- Monitor credit balance
- Choose appropriate models based on needs
- Check Pricing page for rates
- Enjoy discounts with bulk purchases
Quality Enhancement
- Write detailed and specific prompts
- Use negative prompts to exclude unwanted elements
- Choose appropriate aspect ratios
- Learn from successful examples
Platform Features Details
API Key Management
Visit the API Keys page to manage your keys:
- Create Keys: Click “Create New Key” button to generate new API keys
- View Keys: See all created keys (keys are partially hidden for security)
- Copy Keys: Click copy button to quickly copy keys for development
- Delete Keys: Remove unused keys to improve security
Credit Purchase Plans
Choose a suitable package on the Pricing page:| Amount | Credits | Unit Price |
|---|---|---|
| $50.00 | 1,000 | $0.05/credit |
| $200.00 | 4,000 | $0.05/credit |
| $500.00 | 12,500 | $0.04/credit |
| $1000.00 | 25,000 | $0.04/credit |
| $2000.00 | 50,000 | $0.04/credit |
| $3000.00 | 100,000 | $0.03/credit |
| $6000.00 | 200,000 | $0.03/credit |
Larger packages offer better unit prices. Choose the right package based on your usage to save costs.
Next Steps
API Reference
Explore all available API endpoints and parameters
API Keys
Create and manage your API keys
Call History
View and analyze API call records
Pricing
Purchase credits and view model rates
