Skip to main content

API Documentation

Base URL

https://api-base.hitpaw.com

Authentication

All API requests require authentication.

Endpoints

Endpoint: POST /api/photo-enhancer

Description: Submit a photo enhancement task for image super-resolution processing.

Request Body:

{
"model_name": "generative_portrait",
"img_url": "https://i.ibb.co/TDLJLgVR/face-model-before.jpg",
"extension": ".jpg",
"exif": true,
"DPI": 300
}

Request Parameters:

ParameterTypeRequiredDescription
model_namestringYesThe model name to use for enhancement
img_urlstringYesURL of the image to be enhanced
extensionstringYesFile extension of the image (e.g., ".jpg", ".png")
exifbooleanNoWhether to preserve EXIF data (default: false)
DPIintegerNoTarget DPI for the output image

Response:

{
"code": 200,
"message": "OK",
"data": {
"job_id": "f5007c0b-e902-4070-8c75-f337d896168f",
"consume_coins": 75
}
}

Response Fields:

FieldTypeDescription
job_idstringUnique identifier for the enhancement job
consume_coinsintegerNumber of coins consumed for this task

Example Request (cURL):

curl -X POST https://api-base.hitpaw.com/api/photo-enhancer \
-H "Content-Type: application/json" \
-H "Apikey: YOUR_API_KEY" \
-d '{
"model_name": "enhanced_v1",
"img_url": "https://example.com/image.jpg",
"extension": ".jpg",
"exif": true,
"DPI": 300
}'

Example Request (Python):

import requests
import json

url = "https://api-base.hitpaw.com/api/photo-enhancer"

headers = {
"Content-Type": "application/json",
"Apikey": "YOUR_API_KEY"
}

payload = {
"model_name": "enhanced_v1",
"img_url": "https://example.com/image.jpg",
"extension": ".jpg",
"exif": True,
"DPI": 300
}

response = requests.post(url, headers=headers, data=json.dumps(payload))

if response.status_code == 200:
result = response.json()
print(f"Job ID: {result['job_id']}")
print(f"Consume Coins: {result['consume_coins']}")
else:
print(f"Error: {response.status_code}")
print(response.text)

Available Models

Use the following values for the model_name parameter in your request:

Display NameAPI model_name Value
Face Clear Model 2x/4xface_2x/face_4x
Face Natural Model 2x/4xface_v2_2x/face_v2_4x
General Enhance Model 2x/4xgeneral_2x/general_4x
High Fidelity Model 2x/4xhigh_fidelity_2x/high_fidelity_4x
Sharp Denoise Modelsharpen_denoise
Detail Denoise Modeldetail_denoise
Generative Portrait Modelgenerative_portrait
Generative Enhance Modelgenerative

Task Status

Endpoint: POST /api/task-status

Description: Query the status of a submitted enhancement job. Use this endpoint to poll for job completion.

Request Body:

{
"job_id": "string"
}

Request Parameters:

ParameterTypeRequiredDescription
job_idstringYesJob ID returned from photo-enhancer or video-enhancer endpoint

Response:

{
"code": 200,
"message": "OK",
"data": {
"job_id": "string",
"status": "string",
"res_url": "string",
"original_url": "string"
}
}

Response Fields:

FieldTypeDescription
job_idstringJob identifier
statusstringCurrent job status (see status values below)
res_urlstringURL of the processed/enhanced file (available when status is "COMPLETED")
original_urlstringURL of the original input file

Status Values:

StatusDescription
CONVERTINGJob is currently being processed
COMPLETEDJob has completed successfully, result is available
ERRORJob failed due to an error

Example Request (cURL):

curl -X POST https://api-base.hitpaw.com/api/task-status \
-H "Content-Type: application/json" \
-H "Apikey: YOUR_API_KEY" \
-d '{
"job_id": "abc123def456"
}'

Example Request (Python):

import requests
import json
import time

url = "https://api-base.hitpaw.com/api/task-status"

headers = {
"Content-Type": "application/json",
"Apikey": "YOUR_API_KEY"
}

payload = {
"job_id": "abc123def456"
}

# Poll for job completion
max_attempts = 60
attempt = 0

while attempt < max_attempts:
response = requests.post(url, headers=headers, data=json.dumps(payload))

if response.status_code == 200:
result = response.json()
status = result['status']

print(f"Attempt {attempt + 1}: Status = {status}")

if status == "COMPLETED":
print(f"Job completed successfully!")
print(f"Result URL: {result['res_url']}")
print(f"Original URL: {result['original_url']}")
break
elif status == "ERROR":
print(f"Job failed with error")
break
elif status == "CONVERTING":
print(f"Job is still processing, waiting 5 seconds...")
time.sleep(5)

attempt += 1
else:
print(f"Error: {response.status_code}")
print(response.text)
break

if attempt >= max_attempts:
print("Max polling attempts reached")

Error Codes

The API uses the following error codes:

General Errors

Error CodeHTTP StatusMessage
100400000400No access
100400001400Invalid URL
100400002400Bad Request
100401000401Token is expired
100403000403Invalid request parameters
100403001403Access denied
100403002403You don't have permission to access this resource
100429000429Too many requests, please try again later
100500000500Internal error
100500001500Database error
100500002500Cache error
100500003500Failed to create file
100500004500Signature verification failed
100500005500Configuration error
100500006500Unknown error
100500007500Operation timeout

API-Specific Errors

Error CodeHTTP StatusMessage
110400000400api_key is not valid
110400002400The task does not exist
110400003400The task failed, please try again
110400005400The model is not supported, please try again
110400007400The extension is not valid
110400008400The video URL is not valid
110400009400The input resolution is over limit
110400010400The target resolution is over limit
110400011400The video duration is over limit
110402000402The coins are not enough
110402001402The coins are not enough
110402004402The Demo try times exceeded

Error Response Format

{
"error_code": 110400000,
"message": "api_key is not valid"
}

Rate Limiting

  • The API implements rate limiting to ensure fair usage
  • Error code 100429000 will be returned if you exceed the rate limit
  • Please implement exponential backoff in your retry logic

Best Practices

  1. Polling for Job Status:

    • Poll the /api/task-status endpoint at reasonable intervals (recommended: every 5-10 seconds)
    • Implement exponential backoff for failed requests
    • Set a maximum number of polling attempts to avoid infinite loops
    • Check for status values: CONVERTING (continue polling), COMPLETED (success), ERROR (failed)
  2. Error Handling:

    • Always check the HTTP status code and error code in the response
    • Implement appropriate retry logic for transient errors (5xx errors)
    • Don't retry for client errors (4xx errors) without fixing the request
    • Log error responses for debugging purposes
  3. Resource Limits:

    • Verify video duration limits before submission
    • Ensure input and target resolutions are within allowed limits
    • Check file extension validity before uploading
  4. API Key Management:

    • Store API keys securely using environment variables or secure vaults
    • Never commit API keys to version control
    • Rotate API keys periodically for security
  5. File URL Requirements:

    • Ensure image and video URLs are publicly accessible
    • Use HTTPS URLs for better security
    • Verify URLs are valid before submitting requests

Complete Workflow Example (Python)

Here's a complete example showing the entire workflow from submission to result retrieval:

import requests
import json
import time

class HitPawAPIClient:
def __init__(self, api_key, base_url="https://api-base.hitpaw.com"):
self.api_key = api_key
self.base_url = base_url
self.headers = {
"Content-Type": "application/json",
"Apikey": api_key
}

def enhance_photo(self, img_url, model_name="enhanced_v1", extension=".jpg", exif=True, dpi=300):
"""Submit a photo enhancement job"""
url = f"{self.base_url}/api/photo-enhancer"
payload = {
"model_name": model_name,
"img_url": img_url,
"extension": extension,
"exif": exif,
"DPI": dpi
}

response = requests.post(url, headers=self.headers, data=json.dumps(payload))

if response.status_code == 200:
return response.json()
else:
raise Exception(f"Error {response.status_code}: {response.text}")


def check_status(self, job_id):
"""Check job status"""
url = f"{self.base_url}/api/task-status"
payload = {"job_id": job_id}

response = requests.post(url, headers=self.headers, data=json.dumps(payload))

if response.status_code == 200:
return response.json()
else:
raise Exception(f"Error {response.status_code}: {response.text}")

def wait_for_completion(self, job_id, max_attempts=120, poll_interval=5):
"""Poll job status until completion or error"""
attempt = 0

while attempt < max_attempts:
try:
result = self.check_status(job_id)
status = result['status']

print(f"[Attempt {attempt + 1}/{max_attempts}] Status: {status}")

if status == "COMPLETED":
print("✓ Job completed successfully!")
return result
elif status == "ERROR":
raise Exception("Job failed with ERROR status")
elif status == "CONVERTING":
print(f" Still processing... waiting {poll_interval} seconds")
time.sleep(poll_interval)

attempt += 1
except Exception as e:
print(f"Error checking status: {str(e)}")
raise

raise Exception(f"Job did not complete within {max_attempts * poll_interval} seconds")

# Usage example
if __name__ == "__main__":
# Initialize client
client = HitPawAPIClient(api_key="YOUR_API_KEY")

try:
# Example 1: Photo Enhancement
print("=== Photo Enhancement ===")
photo_result = client.enhance_photo(
img_url="https://example.com/photo.jpg",
model_name="enhanced_v1",
extension=".jpg"
)
print(f"Job ID: {photo_result['job_id']}")
print(f"Coins consumed: {photo_result['consume_coins']}")

# Wait for completion
final_result = client.wait_for_completion(photo_result['job_id'])
print(f"Result URL: {final_result['res_url']}")


except Exception as e:
print(f"Error: {str(e)}")

Support

For API key requests, billing questions, or technical support, please contact our support team.