HTTP 422 Tool Use / JSON Schema Invalid — Schema Validation Fix
Raised when tools or response_format json_schema uses unsupported keywords, omits additionalProperties: false, or has invalid tool names.
Need resilient routing with automatic multi-upstream failover and full request telemetry on API Store Hub?
Error runbook
| HTTP Status | 422 |
|---|---|
| Error type | invalid_tool_schema |
| Retry policy | Fix request first |
Raised when tools or response_format json_schema uses unsupported keywords, omits additionalProperties: false, or has invalid tool names.
Metadata & root causes
- Missing additionalProperties: false or omitted keys in required when strict: true is set.
- Tool function name contains spaces/special characters or exceeds 64 chars (must match [a-zA-Z0-9_-]).
- A role=tool message does not match the preceding assistant tool_call_id.
3 steps to resolve
- Immediate diagnosis: Read the param field in the error JSON to pinpoint the rejected tool index or property.
- Apply standard fix: Normalize every object schema with type: object, explicit properties, complete required list, and additionalProperties: false.
- Prevent recurrence in production: Generate schemas via Zod or Pydantic and validate them in CI unit tests before shipping.
Production retry & recovery snippet
cURL
curl https://apistorehub.com/v1/chat/completions \
-H "Authorization: Bearer sk-ash-your_key" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-6.2-sol","tools":[{"type":"function","function":{"name":"get_price","description":"Get ST rate","parameters":{"type":"object","properties":{"model_id":{"type":"string"}},"required":["model_id"],"additionalProperties":false}}}],"messages":[{"role":"user","content":"Check price of deepseek-v4-flash"}]}'TypeScript
export function sanitizeToolName(raw: string): string {
return raw.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 64) || "tool_fn";
}Frequently asked questions
- Am I billed on API Store Hub when an HTTP 422 (invalid_tool_schema) error occurs?
- No. Atomic pre-hold settlement on API Store Hub automatically releases any reserved amount for failed requests that return no valid completion.
- How do I tell whether the error originated from my client or upstream?
- 4xx codes (except 429) usually point to auth headers, wallet quota, or request payload formatting; 429/502/504/529 indicate load or transient upstream conditions visible on /status.
- Can I fall back to another model without changing SDKs?
- Yes. Pass the fallback model ID (e.g. across Claude, GPT, DeepSeek, or Gemini) inside your retry catch block using your existing sk-ash- API key.