Choose the operation
A purpose-built response is easier to validate than a general scrape plus custom parsing.
Do not crawl an entire site when one page or a sitemap lookup answers the question.
Protect your API key
CONTEXT_DEV_API_KEY is a bearer credential. Store it in a server-side secret manager or environment variable.
- Do not include it in browser JavaScript, mobile bundles, public environment variables, or client-side
localStorage. - Do not print the value while debugging. Log only whether the variable exists.
- Rotate a key that appears in source control, build logs, screenshots, or chat history.
- Grant only the API-key scopes the integration needs. Dashboard team roles and key scopes govern different access.
- Use a backend route when a browser needs Context.dev data.
Limit each request
Set cost and time limits at the request boundary:
Start with a small page cap and inspect the result before increasing it. For current operation prices, use the endpoint badge in the API reference and the pricing page.
Set cache freshness
maxAgeMs controls how old a Context.dev cached result may be. Your own database or object cache controls how long your application reuses the response after receiving it.
Ask two different questions:
- How fresh must the source fetch be when Context.dev handles the request?
- How long can this application reuse the returned value without another API call?
maxAgeMs=0 for fresh data and honor positive sub-day values. The direct-URL Brand variant does not accept maxAgeMs.
Inspect cache_metadata.status and cache_metadata.age_ms when cache behavior matters. A Brand profile assembled during a request reports a miss if any contributing scrape missed its cache; when all contributing scrapes hit, it reports the oldest contributing age. A stored Brand-cache hit uses the profile’s stored age. Store the time of your own successful retrieval as separate metadata.
Plan for slow requests
A cache miss can require browser work, crawling, or model inference. It can take materially longer than a cache hit.- Show an honest loading state when the user must wait.
- Run crawls, batches, and broad product extraction in a background job.
- Prefetch eligible Brand or styleguide data when you learn the identifier before the result is needed.
- Set
timeoutOpts.millisecondsaccording to the product’s latency budget, not an arbitrary HTTP-client default. - Use
timeoutOpts.behavior: "return-partial"when usable incomplete data helps. Preservepartial: trueorfinalDOMState: "still-loading"in your UI and storage; see Timeouts and partial results.
Set a retry policy
Use the status anderror_code together:
Published SDKs can already retry selected network errors and statuses. The API gateway can also retry transient network failures and upstream 502/503/504 responses up to twice, after 1 and 2 seconds, when the request is replayable. Bodies above 1 MiB are streamed without replay, and cancellation stops further attempts. Account for these layers before adding an application retry loop. Use operation-specific idempotency controls for writes; retries do not guarantee exactly-once execution.
A bounded policy needs all four values: retryable conditions, maximum attempts, delay with jitter, and final fallback.
Handle missing fields
A200 means the API produced a usable result. In partial mode, work may still be unfinished; inspect the completion marker. Optional fields can also be missing from a complete response.
- Keep the user’s original input as a fallback.
- Do not assume array index zero is the correct asset for every UI.
- Distinguish “not returned” from a false or zero business value.
- Do not describe discovered addresses, headcounts, contacts, or classifications as verified legal records.
Validate extracted data
For structured extraction, validatedata against the same schema your application sent. Then validate the business meaning your product needs.
Examples:
- A valid URL can still point to the wrong kind of source.
- A number can satisfy the schema but use the wrong unit.
- A classification code can be valid while its confidence is too low for automatic action.
- A required, non-null field can force a poor fallback when the source never states a value.
factCheck when values must be page-supported, and retain urls_analyzed for audit-sensitive workflows.
Track usage and failures
Record enough metadata to diagnose behavior:- Operation and a non-sensitive request identifier.
- HTTP status and
error_code. - Attempt count and total latency.
- Cache status and age when returned.
- Crawl totals, not scraped page bodies, unless your data policy permits content logs.
key_metadata.credits_consumedwhen cost attribution is required.- Request tags for product or environment attribution.
Before launch
- Secret key exists only on the server.
- The operation, page cap, timeout, and cache age are explicit.
- Expected no-result states have a product fallback.
- Retries are bounded and exclude permanent failures.
- Optional fields and empty arrays are handled.
- Structured output is schema-validated.
- Usage, latency, and error categories are observable.
Next steps
Troubleshooting
Diagnose failed requests and handle expected no-result states.
Rate limits
Pace requests and handle 429 responses with bounded retries.
API stability
Check versioning, compatibility, and SDK upgrade requirements.