PaddlePaddle/PaddleOCR · error · InvalidRequestError
Bad request: ${text}
Error message
Bad request: ${text} What it means
InvalidRequestError is thrown when the API answers HTTP 400, meaning the request itself is malformed or violates the API contract. The server's explanation (from the body's msg/message/errorMsg field, or raw text) is embedded in the message, so it tells you exactly which parameter was wrong.
Source
Thrown at api_sdk/typescript/src/internal/http.ts:239
throw new NetworkError(`Connection failed: ${message}`);
} finally {
clearTimeout(timeoutID);
signal?.removeEventListener("abort", abort);
}
if (resp.ok) return resp;
let text = await resp.text();
try {
const payload = JSON.parse(text) as { msg?: string; message?: string; errorMsg?: string };
text = payload.msg || payload.message || payload.errorMsg || text;
} catch {
// Keep raw response text.
}
if (resp.status === 401 || resp.status === 403) {
throw new AuthError(`Authentication failed: ${text}`);
} else if (resp.status === 400) {
throw new InvalidRequestError(`Bad request: ${text}`);
} else if (resp.status === 429) {
throw new RateLimitError(`Rate limit exceeded: ${text}`);
} else if (resp.status === 503 || resp.status === 504) {
throw new ServiceUnavailableError(resp.status, `Service unavailable: ${text}`);
} else {
throw new APIError(resp.status, text);
}
}
}
function requireJobId(data: SubmitResponse): string {
if (!data || typeof data.jobId !== "string" || data.jobId.length === 0) {
throw new ResponseFormatError("Submit response is missing jobId.");
}
return data.jobId;
}
View on GitHub (pinned to 2661c7c0ef)
Solutions
- Read the embedded server message — it names the offending parameter
- Validate payload shape against the current SDK types/README before submitting (TypeScript compiler errors catch most cases)
- Check file constraints: supported formats, size limits, and pageRanges syntax
- Upgrade the SDK so request building matches the current server-side schema
Example fix
try {
await client.submitFile(model, filePath, {}, { pageRanges });
} catch (e) {
if (e instanceof InvalidRequestError) {
console.error("Server rejected request:", e.message); // names the bad param
}
} Defensive patterns
Strategy: validation
Validate before calling
const VALID_PAGE_RANGE = /^\d+-\d+$/;
function validateSubmitOptions(opts: { pageRanges?: string; batchId?: string }): string[] {
const errs: string[] = [];
if (opts.pageRanges !== undefined && !VALID_PAGE_RANGE.test(opts.pageRanges)) {
errs.push(`pageRanges must match 'N-M', got '${opts.pageRanges}'`);
}
return errs;
} Type guard
function isInvalidRequestError(e: unknown): e is InvalidRequestError {
return e instanceof InvalidRequestError;
} Try / catch
try {
await client.submitFile(model, filePath, payload, opts);
} catch (e) {
if (e instanceof InvalidRequestError) {
// permanent client error: surface e.message (names the bad param), never retry
throw new ValidationError(e.message);
}
throw e;
} Prevention
- Validate pageRanges format, file extension, and required payload fields before calling the API
- Let TypeScript type-check payloads at compile time; avoid `as any` escapes
- Read the embedded server message on 400s and fix the named parameter rather than retrying
When it happens
Trigger: submitJson with a payload missing required fields or with wrong types; submitFile with an unsupported file extension, an oversized file, or invalid pageRanges format; batchId referencing a non-existent batch; passing model names the backend does not recognize.
Common situations: Schema drift between SDK version and API version; hand-built payloads copied from outdated docs; page ranges like "5-" or non-numeric input; file formats the service rejects; forgetting required fields when moving from curl examples to code.
Related errors
- Bad request: {msg}
- File not found: ${path}
- Expected a JSON response body.
- PaddleOCR official API request failed.
- Response body is missing data.
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/a90a798d133d19c6.
Report an issue: GitHub.