Skip to main content

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

Never expose your API key in client-side code, public repositories, or logs.
Best Practices:
  1. Store API keys in environment variables:
  2. Use a backend proxy to make API calls:
  3. Rotate keys regularly from the API Keys page
  4. 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 the webhook_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

Good prompts are specific, descriptive, and clear.
Examples: Bad: “a cat” Good: “A fluffy orange tabby cat sitting on a windowsill, soft natural lighting, photorealistic, high detail” Prompt Tips:
  1. Be specific: Include details about style, lighting, composition
  2. Use descriptive adjectives: “vibrant”, “dramatic”, “soft”, “detailed”
  3. Specify quality: “high quality”, “8k”, “professional”
  4. 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

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:
Check the Pricing page for detailed rates of each model.

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: API Keys Management Interface
  • 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
We recommend creating different API keys for different projects or environments (development, testing, production) for better management and tracking.

Credit Purchase Plans

Choose a suitable package on the Pricing page:
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