DataForSEO's SDK is lazily loaded on first API call to avoid blocking isolate startup, and all calls are metered via credit checks before execution and spend tracking after completion, with callers able to override the billing feature per-call. The metering system tracks spend under a "dataforseo" provider, handles validation errors without charging when DataForSEO incurs no cost, bypasses all billing in self-hosted mode, and batches related task submissions (like rank checks) under a single charge. A credit feature is a billing category label (e.g. "rank_tracking") that determines which usage bucket a DataForSEO API call is charged against; incorrect feature selection misattributes costs to the wrong product area.
In src/server/lib/dataforseo/client.ts, the DataForSEO sections module (and the ~3 MB dataforseo-client SDK it imports) is lazily loaded via a single loadDataforseoSections() call, deferred until the first API call, to keep it out of the eager isolate startup graph.[1]
meterDataforseoCall in src/server/lib/dataforseo/client.ts calls assertUsageCreditsAvailable before executing the DataForSEO API call, and then calls trackUsageCreditSpend (via trackDataforseoCost) after a successful call or a billed error.[1] The meter helper in src/server/lib/dataforseo/client.ts accepts a defaultFeature credit feature, but callers can override it per-call by passing creditFeature in the input object; the extra field is ignored by the underlying section fetchers.[1] trackDataforseoCost in src/server/lib/dataforseo/client.ts falls back to mapDataforseoPathToCreditFeature(billing.path) when no explicit creditFeature is provided, deriving the billing feature from the DataForSEO API path.[1] On every billing event, trackDataforseoCost in src/server/lib/dataforseo/client.ts records the provider as "dataforseo" and sets fromCache: false unconditionally.[1] When a DataforseoChargedTaskError is thrown in src/server/lib/dataforseo/client.ts and the error is an invalid-field type with zero cost, it is re-thrown as a non-reportable VALIDATION_ERROR AppError without charging the customer; if DataForSEO still billed (costUsd > 0), the spend is tracked before re-throwing.[1] meterDataforseoCall in src/server/lib/dataforseo/client.ts bypasses all billing checks and credit gating in non-hosted (self-hosted) mode, executing the API call and returning the result directly.[1]
In src/server/lib/dataforseo/client.ts, task_post endpoints (reviewsTaskPost, updatesTaskPost, rankCheckTaskPost) are metered at post time; collection endpoints run unmetered because DataForSEO only bills at task submission.[1] The serp.rankCheckTaskPost entry in src/server/lib/dataforseo/client.ts posts up to 100 queued rank-check tasks in one call, and one metered charge covers the entire batch.[1]
In src/server/lib/dataforseo/client.ts, labs.keywordOverview defaults to "rank_tracking" as its credit feature, but callers (e.g. the keyword-metrics MCP tool) can override it by passing creditFeature in the input.[1]
Sources