@devtune/client provides typed methods for every project operation in the public API.
It uses fetch and has no runtime dependencies. Use ESM in Node 20+ or a modern
fetch-capable runtime. Keep project API keys in server-side environment variables.
Project configuration
Create a project API key in API Keys in the account sidebar. Select the scopes your integration needs, then setDEVTUNE_API_KEY and DEVTUNE_PROJECT_ID in your
environment. The key must belong to that project. See authentication.
projectId once. Method names match the public API’s operation
names. Pass other resource identifiers in path, filters in query and JSON in
body. Responses retain their envelope, metadata and nullable fields.
Operations with no response body return void; others return the parsed JSON
envelope. An operation with no declared response schema returns unknown, so
narrow the value before using it.
scopes are what the key holds now; a paused project keeps only read
scopes. features reports account features that gate operations separately from
scopes.
ProjectClient, OperationId, OperationInput<'listActions'>,
OperationResponse<'listActions'> and the generated OpenAPI operations, paths
and components. Types preserve the API’s required and optional fields. UUIDs,
numeric ranges and cross-field constraints are validated by the API.
Metrics and coverage
coverage.status === 'unavailable' and stats === null mean
the window has no measurement yet; report it as unmeasured.
AI Traffic returns project-wide sensor state alongside traffic totals. Domain and
path filters narrow totals, not sensor state. no_recent_traffic means a healthy
sensor was quiet; inactive needs attention. The browser snippet does not establish
server-side answer fetch or 404 coverage.
Managed-agent runs
Launching an agent can spend credits. UsetriggerManagedAgentRun only for an
explicitly intended task with the required agents.run scope, available evidence
and credits, and a key creator who belongs to the project with manage permission.
Reading status also requires agents.read.
Save a UUID with the intended request before launching, and supply it as
requestIdempotencyKey. Reuse that same key with the same agent and inputs if you
explicitly retry after a lost response. A new key can start another charged run.
The client never retries launches automatically.
The packaged recipes/managed-agent.ts requires these environment inputs:
DEVTUNE_API_KEYandDEVTUNE_PROJECT_IDDEVTUNE_APPROVED_METERED_RUN=true, acknowledging the intended metered taskDEVTUNE_AGENT_KEYandDEVTUNE_AGENT_INSTRUCTIONSDEVTUNE_RUN_IDEMPOTENCY_KEY, the saved request UUID
getManagedAgentRun with that task ID. Cancelling the
request does not cancel the server run. Completed drafts still need human approval
before publishing.
Shipped Action Results
interventionId from listOutcomesLedger.
The API keeps its /outcomes/ path and operation name for compatibility.
Results compare observed before/after windows. They show what moved, not what
caused it. Preserve evidence quality, null deltas, still_measuring and unmeasured
states, and report null conversion measurements as unmeasured.
Pagination
Every paged list takesquery.cursor and returns data.pagination.hasMore and
data.pagination.nextCursor; page size is limit or pageSize. paginate
follows the cursor with your filters unchanged, within a bound you set, and says
whether it read the whole list:
DevTunePaginationError when a page has no pagination, reports more rows without
a cursor, or repeats a cursor. Where a list reads a published generation or
snapshot, the cursor carries it. offset, page, generation and snapshotId
still work where they did, and are deprecated.
listVisibilityResponses returns only the latest 20 successful executions and has
no cursor. It cannot retrieve complete history and is not a sample for calculating
visibility rates. Use the measurement summary operations for those rates.
Use listVisibilityResponseHistory for paginated discovery of still-present
executions in an anchored 30/90-day started-at window. It includes all lifecycle
statuses by default. Optional filters are prompt UUID, platform and status. Page
size defaults to 50 and is capped at 100. Follow data.pagination.nextCursor with
unchanged filters and window; data.pageCursor replays the current page after
interruption.
Read retained public answer envelopes with getVisibilityResponse. Preserve nulls
and retained=false; missing evidence may have expired or never been captured.
History is live and has no analytical counts. Use devtune responses export for a
bounded SDK-backed NDJSON traversal with explicit completion and recovery.
Use listPrompts to read the project’s tracked prompts with their exact
promptText, topicId, topicName and on/off state, and listTopics for topic
names and descriptions. Both page by cursor with unchanged filters. By default only prompts that are on and whose
topic is on are listed, and only active topics; includeInactive: true adds the
others. Deleted prompts and topics are never listed. Ordering is by id and the
listing is live, not a snapshot. Pass a prompt id as promptId to
createPromptAction, and a topic id as topicId to listPrompts or
getVisibilitySummary:
prompts.write, createPrompt, updatePrompt,
deletePrompt, restorePrompt, createTopic, updateTopic and deleteTopic
change prompts and topics the same way the Prompts tab does. New and
re-enabled prompts count against the prompt allowance; a full allowance returns
HTTP 409 with reason prompt_limit_reached. Deleted prompts keep their history
and restorePrompt brings them back switched off:
setup.write, createBrand, updateBrand,
deleteBrand, restoreBrand, createDomain, updateDomain, deleteDomain,
createBrandTerm, updateBrandTerm and deleteBrandTerm change brands,
tracked domains and brand terms the same way Settings › Brands does;
listBrands, listDomains, listBrandTerms, getAgentPicksCatalogue and
getSearchPlatformCatalogue need setup.read. Changes
apply to answers collected from that day on:
agents.write, createCustomAgent, updateCustomAgent,
setAgentSchedule and turnOffAgentSchedule create and edit custom agents and
change agent schedules the same way the Agents tab does. A new agent starts
with no schedule, and each scheduled run uses agent credits.
archiveCustomAgent and restoreCustomAgent (SDK 0.4.0 or later) archive an
agent and bring it back;
listManagedAgents({ query: { archived: true } }) lists archived agents so you
can find the key to restore. A restored agent’s schedule stays off until you
turn it on:
getContentGapEvidence with a gap from listContentGaps to read the tracked
prompts and cited pages behind it, over the same window and asOfDate. Pass the
gap’s gapType and targetKey exactly as listed, and page by cursor; the
cursor carries coverage.snapshotId. Rows retain their recorded topic, domain and source classification,
so a prompt and URL can appear more than once when those attributes differ.
pagination.totalCount counts those groups, while attribution.pageCount counts
distinct URLs. If the window is republished while you page, the request fails with
409 and reason snapshot_changed; start again without a cursor. When
coverage.status is unavailable, no evidence was published for the window:
Timeouts and errors
The default timeout is 30 seconds for the entire call, including retries, waits and response body reading. ConfiguretimeoutMs on the client or a call, up to five
minutes, and pass signal for cancellation.
maxRetries from 0 to 5 to change the read budget. The client respects
Retry-After seconds or HTTP dates, falling back to X-RateLimit-Reset Unix seconds.
A required wait beyond the remaining budget returns the HTTP error immediately.
POST, PATCH, PUT and DELETE are never retried automatically.
DevTuneHttpError includes status, operation ID, attempts, sanitized documented error
fields, retry timing and rate limits. DevTuneNetworkError reports connection
failure, DevTuneAbortError reports cancellation or timeout, and
DevTuneProtocolError reports malformed success JSON or a success response that
contradicts its documented status/body contract. The client never logs
credentials or retains raw request headers or network causes. A timeout after a
write may mean the server accepted it; inspect state before deciding to retry.
For compatible environments and tests, configure baseUrl, including the API root
such as /api/v2, and a custom fetch implementation. Redirects are refused.
Runnable recipes
The package includesactions-report.ts, metrics.ts, managed-agent.ts and
action-results.ts with a shared environment.ts in its recipes/ directory.
Copy the directory into an ESM project with the client installed. Set the required
environment variables, then run:
Versions and updates
The SDK and CLI have separate versions. For reproducible CI jobs, pin the version rather than followinglatest. Check the published version before upgrading:
npm install @devtune/client@VERSION.
The public API reference lists every generated method’s request and response
contract. New methods can still require API scopes or product entitlements that
your current key does not have.
OAuth bearer tokens
SDK 0.2.0 and later acceptaccessToken for the
CLI-supported OAuth endpoints. SDK 0.1.x
uses apiKey. The SDK does not open a browser or persist credentials, so get the
token from your own OAuth client. The REST API advertises its authorization server
at https://devtune.ai/.well-known/oauth-protected-resource/api/v2; see
CLI OAuth for the endpoints that accept it. OAuth requires HTTPS, except for loopback development servers.
apiKey and accessToken. For refresh, accessToken also
accepts an async function (signal: AbortSignal) => Promise<string> that returns
a fresh token. The provider runs before each
request attempt within the call’s timeout and receives its abort signal. Writes
are never automatically retried, including after a 401; reconnect and inspect
any existing request before deciding whether to retry. Browser session tokens
without an OAuth client and project grant are refused.