# Codeformer API

> Provider: **Sczhou**
> Source: https://www.pixazo.ai/models/codeformer

Robust face restoration algorithm for old photos and AI-generated images.

## Codeformer

### Image Restoration

## Base URL

```
https://gateway.pixazo.ai/codeformer-image-restoration/v1
```

## Authentication

All requests require an API key passed via header.

Header

Type

Required

Description

Ocp-Apim-Subscription-Key

string

Yes

Your API subscription key

## Image Restoration - CodeFormer

## Request Code

HTTP Python JavaScript cURL

```
POST https://gateway.pixazo.ai/codeformer-image-restoration/v1/codeformer/generate
Content-Type: application/json
Cache-Control: no-cache
Ocp-Apim-Subscription-Key: YOUR_API_KEY

{
  "image": "https://pub-582b7213209642b9b995c96c95a30381.r2.dev/input_model.png"
}
```

```
import requests

url = "https://gateway.pixazo.ai/codeformer-image-restoration/v1/codeformer/generate"
headers = {
    "Content-Type": "application/json",
    "Cache-Control": "no-cache",
    "Ocp-Apim-Subscription-Key": "YOUR_API_KEY"
}
data = {
    "image": "https://pub-582b7213209642b9b995c96c95a30381.r2.dev/input_model.png"
}

response = requests.post(url, json=data, headers=headers)
print(response.json())
```

```
const url = 'https://gateway.pixazo.ai/codeformer-image-restoration/v1/codeformer/generate';
const headers = {
  'Content-Type': 'application/json',
  'Cache-Control': 'no-cache',
  'Ocp-Apim-Subscription-Key': 'YOUR_API_KEY'
};
const data = {
  image: 'https://pub-582b7213209642b9b995c96c95a30381.r2.dev/input_model.png'
};

fetch(url, {
  method: 'POST',
  headers: headers,
  body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
```

```
curl -X POST "https://gateway.pixazo.ai/codeformer-image-restoration/v1/codeformer/generate" \
  -H "Content-Type: application/json" \
  -H "Cache-Control: no-cache" \
  -H "Ocp-Apim-Subscription-Key: YOUR_API_KEY" \
  --data-raw '{
    "image": "https://pub-582b7213209642b9b995c96c95a30381.r2.dev/input_model.png"
  }'
```

## Output

```
{
  "request_id": "codeformer-image-restoration_019dxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "status": "QUEUED",
  "polling_url": "https://gateway.pixazo.ai/v2/requests/status/codeformer-image-restoration_019dxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
```

[Try Now](https://api.pixazo.ai/api-details#api=codeformer-image-restoration&operation=image-restore-request)

## Webhook (Optional)

Add the `X-Webhook-URL` header to your generate request to receive a POST callback instead of polling.

```
X-Webhook-URL: https://your-server.com/webhook/callback
```

## Request Parameters - Image Restoration

Parameter

Required

Type

Default

Range / Allowed

Description

image

Yes

string (URL)

—

valid URL

Input image to restore. Must be a publicly fetchable URL.

codeformer\_fidelity

No

number

0.5

0 – 1

Quality vs. fidelity trade-off. Lower = better visual quality (CodeFormer can hallucinate). Higher = stays closer to the input face.

background\_enhance

No

boolean

true

—

Run Real-ESRGAN over the background (non-face) regions to upscale them.

face\_upsample

No

boolean

true

—

Re-upsample restored faces to a higher resolution (useful for AI-generated faces).

upscale

No

integer

2

1 – 8

Final output upsampling factor. 2 = 2× resolution, 4 = 4×, etc. Larger values dramatically increase file size and compute time.

webhook

No

string (URL)

—

valid URL

Webhook URL for async notifications when restoration completes.

webhook\_events\_filter

No

array

—

"start", "output", "logs", "completed"

Event types to receive in the webhook callback.

## Example Request

```
{
  "image": "https://pub-582b7213209642b9b995c96c95a30381.r2.dev/input_model.png",
  "codeformer_fidelity": 0.5,
  "background_enhance": true,
  "face_upsample": true,
  "upscale": 2,
  "webhook": "https://your-domain.com/webhook",
  "webhook_events_filter": ["start", "output", "logs", "completed"]
}
```

## Response

```
{
  "request_id": "codeformer-image-restoration_019dxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "status": "QUEUED",
  "polling_url": "https://gateway.pixazo.ai/v2/requests/status/codeformer-image-restoration_019dxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
```

## Request Headers

Header

Value

Content-Type

application/json

Cache-Control

no-cache

Ocp-Apim-Subscription-Key

YOUR\_API\_KEY

## Response Handling

Common status codes.

Code

Meaning

202

Accepted — Request queued

400

Bad Request

401

Unauthorized

402

Insufficient Balance

403

Forbidden

429

Too Many Requests

500

Internal Server Error

## Error Responses

Queue system errors and model validation errors.

### Queue System Errors

```
// 402 — Insufficient balance
{
  "error": "Insufficient Balance",
  "message": "Your wallet does not have enough balance."
}
```

```
// 400 — Model not found
{
  "error": "Model not found",
  "message": "Model 'codeformer-image-restoration' not found or is disabled"
}
```

### Error via Status/Webhook

```
{
  "request_id": "codeformer-image-restoration_019dxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "status": "ERROR",
  "model_id": "codeformer-image-restoration",
  "error": "Description of the error",
  "output": null
}
```

## Retrieving Results

Poll the universal status endpoint to check progress and retrieve results.

### Endpoint

```
GET https://gateway.pixazo.ai/v2/requests/status/{request_id}
Ocp-Apim-Subscription-Key: YOUR_API_KEY
```

## cURL Example

```
curl -H "Ocp-Apim-Subscription-Key: YOUR_API_KEY" \
  "https://gateway.pixazo.ai/v2/requests/status/codeformer-image-restoration_019dxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
```

## Response (Completed)

```
{
  "request_id": "codeformer-image-restoration_019dxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "status": "COMPLETED",
  "model_id": "codeformer-image-restoration",
  "error": null,
  "output": {
    "media_url": [
      "https://pub-582b7213209642b9b995c96c95a30381.r2.dev/v1/codeformer-image-restoration_019dxxxx-xxxx/output.png"
    ],
    "media_type": "image/png"
  },
  "created_at": "2026-03-31T10:00:00.000Z",
  "updated_at": "2026-03-31T10:00:15.000Z",
  "completed_at": "2026-03-31T10:00:15.000Z"
}
```

## Response Fields

Field

Type

Description

request\_id

string

Unique request identifier

status

string

QUEUED, PROCESSING, COMPLETED, FAILED, or ERROR

model\_id

string

Model that processed the request

error

string|null

Error message if failed

output.media\_url

array

URLs to the restored image (R2 CDN)

output.media\_type

string

MIME type of the output (image/png)

created\_at

string

When request was created

completed\_at

string|null

When request completed

polling\_url

string

Status URL (initial response only)

## Status Values

Status

Description

QUEUED

Request accepted, waiting to be processed

PROCESSING

Being processed by the model

COMPLETED

Done — output contains the result

FAILED

Failed — check error field

ERROR

System error — not charged

## Status Flow

```
QUEUED → PROCESSING → COMPLETED
                    → FAILED
                    → ERROR
```

## Typical Workflow

1.  **Send a generate request** to the API endpoint
2.  **Save the `request_id`** from the response
3.  **Poll** every 5-10 seconds: `GET /v2/requests/status/{request_id}`
4.  **When `status` is `"COMPLETED"`**, download from `output.media_url`

**Tip:** Use `X-Webhook-URL` header to get a callback instead of polling.
