How do the Python and Node SDKs handle previews, paging and errors?

View as Markdown

What the SDKs do for you, what they hand back, and the units to check before you write code.

Both SDKs are thin wrappers over the same REST API, so anything in the API docs applies to them too. What they add is the shape of a response, when a call is retried, and which error is raised.

pip install sentisense      # Python 3.8+
npm install sentisense      # Node 18+, also ships the npx sentisense CLI

Both clients read your key from the SENTISENSE_API_KEY environment variable when you do not pass one. Keep it there rather than in your code.

Previews

On the free plan some endpoints return a shorter preview (see why your data says preview). The two SDKs show it differently:

  • Python unwraps it. You read the payload straight off the result, and result.is_preview, result.preview_reason and result.total_count sit beside it. result.data is there when you want the raw payload.
  • Node returns the envelope as sent: { isPreview, previewReason, data, totalCount }. Read rows from result.data.

Paging

Where an endpoint pages, the total size comes back with the page: total_count in Python, totalCount in Node. It counts the whole matching set on every plan, so compare it with the rows you got to decide whether to ask for the next offset. A missing count means the endpoint returned everything, not that there were zero rows.

Retries

Both clients retry the per-minute 429 and server errors, three times by default, and honour the Retry-After header. They never retry quota_exceeded, because waiting does not refill a monthly allowance (the two kinds of 429). Long charts (10Y, MAX) can answer 202 the first time a rarely requested stock is asked for; the SDKs wait and retry that too, so a call that succeeds always carries the range you asked for.

Set max_retries=0 (Python) or maxRetries: 0 (Node) to handle rate limits and server errors yourself.

Errors

What happened Python Node
Missing or invalid key AuthenticationError AuthenticationError
Unknown or uncovered ticker NotFoundError NotFoundError
Rate limit or allowance RateLimitError (.retry_after, .code) RateLimitError (.retryAfter, .code)
Long chart still building DeepHistoryUnavailable DeepHistoryUnavailableError
Server busy for longer than the client will wait TemporarilyUnavailable (.retry_after) TemporarilyUnavailableError (.retryAfter)
Anything else APIError APIError

Errors from the API carry its error code in .code, so you can branch on "quota_exceeded" or "no_coverage" instead of parsing the message. For a 404, why a ticker can return 404 explains the coverage answer.

Units and missing values

  • Timestamps are not all in one unit. Price and quote times, chart bars, metric points and the metrics start_time / startTime window are epoch milliseconds; many others are epoch seconds. Each field's unit is in the API docs.
  • Calendar dates are "YYYY-MM-DD" strings.
  • When the API cannot fill a field it usually leaves it out or sends null, rather than a zero. Check before you do math with it.

More in Getting started

Plans and billing: see the FAQ. Still stuck? Contact us.