Errors
Every error is an RFC 9457 problem with a stable code:
{
"type": "https://docs.mynicepanel.com/errors/insufficient_balance",
"title": "Insufficient balance",
"status": 402,
"code": "insufficient_balance",
"detail": "the available balance is lower than the payout amount plus fee",
"request_id": "req_01JD3QH2Y8ZKX4M9T6V0R1B2C3",
"errors": [{ "field": "amount", "message": "…" }]
}- Switch on
code, never ontitleordetail(those are for people and may change). request_idis on every response (also as theNP-Request-Idheader). Quote it when you contact us.errorslists field problems forinvalid_request.- Some problems carry more members, e.g.
existing_idonduplicate_merchant_reference.
The SDKs raise NicePayError (TypeScript) / NicePay\Exception\ApiException (PHP) with code (PHP: errorCode), status, requestId, retryable, detail and errors; and a connection error with outcomeUnknown when there was no answer at all (idempotency).
runs in CI
samples/ts/errors.ts samples/php/errors.php// Errors: every failure has a stable code, a request id for support, and whether
// sending it again can help.
import { NicePay, NicePayConnectionError, NicePayError } from "@nicepay/sdk-ts";
const nicepay = new NicePay({
keyId: process.env["NICEPAY_KEY_ID"] ?? "",
secret: process.env["NICEPAY_KEY_SECRET"] ?? "",
...(process.env["NICEPAY_API_BASE"] ? { baseUrl: process.env["NICEPAY_API_BASE"] } : {}),
});
async function attempt(label: string, call: () => Promise<unknown>): Promise<void> {
try {
await call();
console.log(`${label}: ok`);
} catch (error) {
if (error instanceof NicePayError) {
// error.code is one of the documented codes; switch on it, not on the message.
const fields = error.errors.map((e) => e.field).join(",");
console.log(`${label}: ${String(error.status)} ${error.code} retryable=${String(error.retryable)} request_id=${String(error.requestId)}${fields ? ` fields=${fields}` : ""}`);
} else if (error instanceof NicePayConnectionError) {
console.log(`${label}: no answer, outcome unknown=${String(error.outcomeUnknown)}`);
} else {
throw error;
}
}
}
// 402: more than the available balance. Nothing is created.
await attempt("huge payout", () =>
nicepay.createPayout({ merchant_payout_id: `WD-HUGE-${String(Date.now())}`, amount: "99999999.00", currency: "INR", method: "upi", destination: { vpa: "ramesh@okhdfc", holder_name: "Ramesh Kumar" } }),
);
// 400: the request does not match the schema; `errors` names the fields.
await attempt("bad amount", () => nicepay.createPayin({ merchant_order_id: "DEP-BAD", amount: "10.999", currency: "INR", method: "upi", customer: { ref: "p1" } }));
// 404: an id that is not yours (or does not exist) — the same answer either way.
await attempt("unknown pay-in", () => nicepay.getPayin("pi_00000000000000000000000000"));
// 422: fees would leave you nothing.
await attempt("tiny pay-in", () => nicepay.createPayin({ merchant_order_id: `DEP-TINY-${String(Date.now())}`, amount: "1.00", currency: "INR", method: "upi", customer: { ref: "p1" } }));<?php
// Errors: a stable code, a request id for support, and whether trying again can help.
declare(strict_types=1);
require 'vendor/autoload.php';
use NicePay\Exception\ApiException;
use NicePay\Exception\ConnectionException;
$config = ['key_id' => getenv('NICEPAY_KEY_ID') ?: '', 'secret' => getenv('NICEPAY_KEY_SECRET') ?: ''];
if (getenv('NICEPAY_API_BASE')) {
$config['base_url'] = getenv('NICEPAY_API_BASE');
}
$nicepay = new NicePay\Client($config);
function attempt(string $label, callable $call): void
{
try {
$call();
echo "{$label}: ok\n";
} catch (ApiException $e) {
// Switch on $e->errorCode (documented, stable), never on the message.
$fields = implode(',', array_map(static fn (array $f): string => $f['field'], $e->errors));
echo "{$label}: {$e->status} {$e->errorCode} retryable=" . var_export($e->retryable, true) . " request_id={$e->requestId}" . ($fields !== '' ? " fields={$fields}" : '') . "\n";
} catch (ConnectionException $e) {
echo "{$label}: no answer, outcome unknown=" . var_export($e->outcomeUnknown, true) . "\n";
} catch (InvalidArgumentException $e) {
echo "{$label}: refused before sending: {$e->getMessage()}\n";
}
}
attempt('huge payout', static fn () => $nicepay->createPayout([
'merchant_payout_id' => 'WD-HUGE-' . time(), 'amount' => '99999999.00', 'currency' => 'INR', 'method' => 'upi',
'destination' => ['vpa' => 'ramesh@okhdfc', 'holder_name' => 'Ramesh Kumar'],
]));
attempt('bad amount', static fn () => $nicepay->createPayin([
'merchant_order_id' => 'DEP-BAD', 'amount' => '10.999', 'currency' => 'INR', 'method' => 'upi', 'customer' => ['ref' => 'p1'],
]));
attempt('unknown pay-in', static fn () => $nicepay->getPayin('pi_00000000000000000000000000'));
attempt('float amount', static fn () => $nicepay->createPayin([
'merchant_order_id' => 'DEP-FLOAT', 'amount' => 10.5, 'currency' => 'INR', 'method' => 'upi', 'customer' => ['ref' => 'p1'],
]));Every code
| Code | HTTP | What to do |
|---|---|---|
missing_credentials | 401 | A signing header is missing (NP-Key-Id, NP-Timestamp, NP-Nonce, NP-Algorithm, NP-Signature), or NP-Nonce is not 16+ random bytes in base64url without padding. Fix the client; do not retry as is. |
invalid_key | 401 | The key id is malformed, unknown, revoked or expired. Check that you send the key id (np_test_kid_… or np_live_kid_…), not the secret, and that the key was not revoked in the portal. |
invalid_signature | 401 | The signature does not match. Compare your canonical string with the test vectors: raw body bytes, sorted query, no trailing newline, the right secret, NP-Algorithm matching the key. |
timestamp_out_of_range | 401 | NP-Timestamp is more than 300 seconds from our clock, or is not whole seconds (milliseconds are refused). Sync your server's clock (NTP) and sign each attempt afresh. |
nonce_reused | 401 | This key already used this nonce. Generate a new random nonce for every request, including every retry. |
ip_not_allowed | 403 | The request came from an address outside the key's IP allowlist. The list is fixed when a key is created: create a key that includes your server's egress address, then revoke this one. |
edge_auth_failed | 403 | The request did not come through our edge. Use https://api.mynicepanel.com, never another host or an IP address. |
insufficient_scope | 403 | The key lacks the scope this endpoint needs (see the reference). Create a key with that scope in the portal. |
test_mode_only | 403 | Simulation endpoints work with test keys only. |
merchant_not_active | 403 | Your merchant account is closed, or it is frozen and you asked for a payout or a settlement. Contact your account manager. |
invalid_request | 400 | The request does not match the schema; errors names each field. Fix the request; retrying the same one fails the same way. |
amount_too_small | 422 | The fees would leave you nothing of this amount. Ask for a larger amount; nothing was created. |
invalid_destination | 422 | The payout destination is malformed or does not match the method (IFSC, VPA, address checksum and chain). Correct it; nothing was created. |
unsupported_version | 400 | NP-Version names a version we do not serve. Send a supported version date or omit the header. |
idempotency_key_required | 400 | This endpoint creates or moves money: send an Idempotency-Key (your own order or withdrawal id). |
idempotency_key_reused | 409 | This idempotency key was used with a different request body. Use a new key for a new request; never change the body of a retry. |
request_in_progress | 409 | A request with this idempotency key is still running. Retry the same request (same key) after a short wait. |
duplicate_merchant_reference | 409 | An object with this merchant_order_id / merchant_payout_id already exists; existing_id is its id. Fetch it instead of creating another. |
reference_already_used | 409 | This payment reference (UTR) was already submitted for another pay-in. Ask the customer to check it. |
not_found | 404 | No such object for this key's project and mode. Check the id and that you use the key of the mode the object was created in. |
invalid_state | 409 | The object's status does not allow this (e.g. cancelling a payout that is no longer queued). Fetch the object and act on its current status. |
limit_exceeded | 403 | A limit applies — for example a customer's number of open pay-ins, or the number of webhook endpoints of a project; detail says which. Nothing was created. |
insufficient_balance | 402 | The available balance is lower than the amount plus fee. Nothing was created; top up, or wait for pending money to become available. |
rail_unavailable | 503 | No rail can serve this request now. Retry later or offer the customer another method. |
address_pool_empty | 503 | No deposit address is ready this moment. Retry after a few seconds. |
invoice_already_open | 409 | This customer already has an open USDT invoice on this chain. Use the open one, or cancel it first. |
method_not_available | 422 | This method or settlement is not configured for your project. Contact your account manager. |
rate_limited | 429 | Too many requests for this key. Wait for Retry-After seconds; the SDKs do this for you. |
internal_error | 500 | Something failed on our side. Retry with the same idempotency key; quote request_id if it persists. |
service_unavailable | 503 | We are briefly unavailable. Retry with the same idempotency key after a short wait. |
Rate limits
Each key has separate per-minute buckets for reads, pay-in creation and payout creation. Every response carries RateLimit-Limit, RateLimit-Remaining and RateLimit-Reset; over the limit you get 429 rate_limited with Retry-After. The SDKs wait and retry.
Limits
Request bodies are at most 64 KB. Lists return at most 100 objects per page.