Skip to main content

Errors

gfin errors use HTTP status codes plus a JSON body with a stable machine-readable error.code and human-readable error.message.

Error Shape

{
"error": {
"code": "bad_request",
"message": "research requires q=, query=, or term=.",
"next_action": "fix_request",
"request_id": "..."
}
}

Rate-limit responses also include rate_limit details:

{
"error": {
"code": "rate_limited",
"message": "Request limit exceeded."
},
"rate_limit": {
"tier": "anonymous",
"scope": "request",
"retry_after_seconds": 42
}
}

429 responses include a Retry-After header.

Common Error Codes

HTTP statuserror.codeRetry?Meaning
400bad_requestNoThe request is missing a required parameter or uses an invalid shape.
401invalid_api_keyNoThe supplied API key is invalid.
404not_foundNoThe public route was not found.
405method_not_allowedNoThe route does not support the HTTP method used.
429rate_limitedYes, after Retry-AfterThe request exceeded the current tier limit.
429request_coalescedYes, after Retry-AfterAnother request is already refreshing the same cache key.
502origin_response_errorYesThe data provider returned an unusable response.
502response_too_largeNoThe response exceeded gfin's configured response-size cap.
504origin_transport_errorYesgfin could not reach the data provider in time.

Retry Guidance

Retry only errors that are explicitly temporary:

  • rate_limited
  • request_coalesced
  • origin_response_error
  • origin_transport_error

For 429, wait for Retry-After or rate_limit.retry_after_seconds. For 502 and 504 errors, use exponential backoff with jitter and a small retry budget.

Do not retry malformed requests. Fix request parameters instead.

SDK Behavior

Python:

from gfin import Client, GfinError, GfinRateLimitError

client = Client(contact="you@example.com")

try:
client.quote_summary("AAPL", exchange="NASDAQ")
except GfinRateLimitError:
print("retry after the rate-limit window")
except GfinError as exc:
print("request failed", exc)

TypeScript:

import { Client, GfinError, GfinRateLimitError } from "@gfin/sdk";

const client = new Client({ contact: "you@example.com" });

try {
await client.quoteSummary("AAPL", { exchange: "NASDAQ" });
} catch (error) {
if (error instanceof GfinRateLimitError) {
console.log("retry after", error.retryAfterSeconds);
} else if (error instanceof GfinError) {
console.log(error.status, error.code);
}
}

Practical Rules

  • Branch on error.code, not the text of error.message.
  • Use Retry-After for 429 handling.
  • Treat 400-level errors as caller bugs unless the user supplied bad input.
  • Show unavailable states for missing financial data instead of converting missing values to errors in your app.