Skip to contentSkip to page list

Docs

Get pull request usage

Assistant usage for one pull request: sessions, tokens and cost, grouped by contributor and agent, plus per-model totals, over the pull request's whole lifetime rather than a time window. Every row and the totals split cost three ways: the part priced per token, the part a bundled subscription already covers, and the list-price total of both. Per-model totals carry the list price only. Cost is calculated from the tokens the agent reported and LangWatch's model prices, so it estimates spend rather than restating a provider invoice. Authenticate with an organization API key and nothing else: no project id is sent anywhere. A key created for you reads with your own access; an organization service key, such as one a continuous integration job holds, reads with the access its bindings grant. Rows appear only for projects the key may view, and cost only for those it may price.

GET/api/v1/coding-agent/pull-request-usage
Request and response examples
request.py
import osimport requests​origin = "https://app.langwatch.ai"path = "/api/v1/coding-agent/pull-request-usage"api_key = os.environ["LANGWATCH_API_KEY"]headers = {    "Authorization": "Bearer " + api_key,}​response = requests.get(    origin + path,    headers=headers,)print(response.json())

Success

application/json · Generated from schema

{  "pullRequest": {    "repositoryHost": "string",    "repositoryFullName": "string",    "prNumber": 0,    "headBranch": "string",    "htmlUrl": "string",    "state": "string",    "isDraft": false,    "authorLogin": "string",    "prCreatedAtMs": 0,    "prClosedAtMs": 0,    "prMergedAtMs": 0  },  "rows": [    {      "projectId": "string",      "projectSlug": "string",      "contributorLabel": "string",      "contributorIsProject": false,      "agent": "string",      "models": [        "string"      ],      "sessionsCount": 0,      "inputTokens": 0,      "outputTokens": 0,      "cacheReadTokens": 0,      "cacheCreationTokens": 0,      "totalTokens": 0,      "costUsd": 0,      "billedCostUsd": 0,      "nonBilledCostUsd": 0    }  ],  "totals": {    "sessionsCount": 0,    "inputTokens": 0,    "outputTokens": 0,    "cacheReadTokens": 0,    "cacheCreationTokens": 0,    "totalTokens": 0,    "costUsd": 0,    "billedCostUsd": 0,    "nonBilledCostUsd": 0  },  "modelBreakdown": [    {      "model": "string",      "inputTokens": 0,      "outputTokens": 0,      "cacheReadTokens": 0,      "cacheCreationTokens": 0,      "totalTokens": 0,      "costUsd": 0,      "tokensKnown": false,      "aiUnits": 0    }  ]}
api-reference/coding-agents/get-pull-request-usage

Authorization

Authorizationstringheaderrequired

Admin API key for organization-level operations (managing projects, API keys). Create one in Settings > API Keys or via POST /api/api-keys. Format: sk-lw-{id}_{secret}.

Query parameters

repositorystringrequired

The repository as "owner/name". Case is folded by the mapping store.

Pattern ^[^/\s]+\/[^/\s]+$
pullRequestintegerrequired

The pull request number.

Maximum 9007199254740991
hoststring

The repository's host, e.g. github.com.

At least 1 character

Responses

200

Success

application/json

pullRequestobjectrequired
repositoryHoststringrequired
repositoryFullNamestringrequired
prNumbernumberrequired
headBranchstringrequired
htmlUrlstringrequired
statestringrequired
isDraftbooleanrequired
authorLoginstring | nullrequired
prCreatedAtMsnumberrequired
prClosedAtMsnumber | nullrequired
prMergedAtMsnumber | nullrequired
rowsobject[]required
projectIdstringrequired
projectSlugstringrequired
contributorLabelstringrequired
contributorIsProjectbooleanrequired
agentstringrequired
modelsstring[]required
sessionsCountnumberrequired
inputTokensnumberrequired
outputTokensnumberrequired
cacheReadTokensnumberrequired
cacheCreationTokensnumberrequired
totalTokensnumberrequired
costUsdnumber | nullrequired
billedCostUsdnumber | nullrequired
nonBilledCostUsdnumber | nullrequired
totalsobjectrequired
sessionsCountnumberrequired
inputTokensnumberrequired
outputTokensnumberrequired
cacheReadTokensnumberrequired
cacheCreationTokensnumberrequired
totalTokensnumberrequired
costUsdnumber | nullrequired
billedCostUsdnumber | nullrequired
nonBilledCostUsdnumber | nullrequired
modelBreakdownobject[]required
modelstringrequired
inputTokensnumberrequired
outputTokensnumberrequired
cacheReadTokensnumberrequired
cacheCreationTokensnumberrequired
totalTokensnumberrequired
costUsdnumber | nullrequired
tokensKnownbooleanrequired
aiUnitsnumber | nullrequired
400

Bad Request

application/json

errorstringrequired
messagestring
401

Unauthorized

application/json

errorstringrequired
messagestring
422

Unprocessable Entity

application/json

errorstringrequired
messagestring
500

Internal Server Error

application/json

errorstringrequired
messagestring

Documentation