All Products
Search
Document Center

API Gateway:custom-response

Last Updated:Jun 08, 2026

The custom-response plug-in returns custom HTTP status codes, headers, and bodies. Use it for mock responses or to override responses for specific status codes, such as returning a custom response when a throttling policy is triggered.

Plug-in type

Transmission protocol-related plug-in.

Fields

Field

Data type

Required

Default value

Description

status_code

number

No

200

Custom HTTP status code.

headers

array of string

No

-

Custom HTTP response headers. Separate keys and values with =.

body

string

No

-

Custom HTTP response body.

enable_on_status

array of number

No

-

The HTTP status code that triggers the custom response. If not specified, the custom response applies to all requests without checking the original status code.

Examples

Return a custom response in mock response scenarios

status_code: 200
headers:
- Content-Type=application/json
- Hello=World
body: "{\"hello\":\"world\"}"

This configuration returns the following response:

HTTP/1.1 200 OK
Content-Type: application/json
Hello: World
Content-Length: 17

{"hello":"world"}

Return a custom response when throttling is triggered

enable_on_status: 
- 429
status_code: 302
headers:
- Location=https://example.com

Throttling typically returns HTTP status code 429. With this configuration, the following custom response is returned instead:

HTTP/1.1 302 Found
Location: https://example.com

This redirects the throttled user to another page, such as a static page on CDN.

To return other status codes when throttling is triggered, configure the fields as described in the "Return a custom response in mock response scenarios" section.

Block requests for specific routes or domain names

Apply the following plug-in configurations to the route-a and route-b routes:

body: "{\"hello\":\"world\"}"

Apply the following plug-in configuration to the *.example.com and test.com domain names:

  enable_on_status: 
  - 429
  status_code: 200
  headers:
  - Content-Type=application/json
  body: "{\"errmsg\": \"rate limited\"}"
Note
  • route-a and route-b are the routes specified when gateway routes are created. If a request matches a route, the rules configured for that route take effect.

  • *.example.com and test.com match domain names in requests. If a request matches a domain name, the rules configured for that domain name take effect.

  • Rules take effect in sequence. Once a rule matches, subsequent rules are skipped.