import requests
url = "https://app.langwatch.ai/api/v1/coding-agent/pull-request-usage"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://app.langwatch.ai/api/v1/coding-agent/pull-request-usage', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));curl --request GET \
--url https://app.langwatch.ai/api/v1/coding-agent/pull-request-usage \
--header 'Authorization: Bearer <token>'{
"pullRequest": {
"repositoryHost": "<string>",
"repositoryFullName": "<string>",
"prNumber": 123,
"headBranch": "<string>",
"htmlUrl": "<string>",
"state": "<string>",
"isDraft": true,
"authorLogin": "<string>",
"prCreatedAtMs": 123,
"prClosedAtMs": 123,
"prMergedAtMs": 123
},
"rows": [
{
"projectId": "<string>",
"projectSlug": "<string>",
"contributorLabel": "<string>",
"contributorIsProject": true,
"agent": "<string>",
"models": [
"<string>"
],
"sessionsCount": 123,
"inputTokens": 123,
"outputTokens": 123,
"cacheReadTokens": 123,
"cacheCreationTokens": 123,
"totalTokens": 123,
"costUsd": 123,
"billedCostUsd": 123,
"nonBilledCostUsd": 123
}
],
"totals": {
"sessionsCount": 123,
"inputTokens": 123,
"outputTokens": 123,
"cacheReadTokens": 123,
"cacheCreationTokens": 123,
"totalTokens": 123,
"costUsd": 123,
"billedCostUsd": 123,
"nonBilledCostUsd": 123
},
"modelBreakdown": [
{
"model": "<string>",
"inputTokens": 123,
"outputTokens": 123,
"cacheReadTokens": 123,
"cacheCreationTokens": 123,
"totalTokens": 123,
"costUsd": 123,
"tokensKnown": true
}
]
}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.
import requests
url = "https://app.langwatch.ai/api/v1/coding-agent/pull-request-usage"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://app.langwatch.ai/api/v1/coding-agent/pull-request-usage', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));curl --request GET \
--url https://app.langwatch.ai/api/v1/coding-agent/pull-request-usage \
--header 'Authorization: Bearer <token>'{
"pullRequest": {
"repositoryHost": "<string>",
"repositoryFullName": "<string>",
"prNumber": 123,
"headBranch": "<string>",
"htmlUrl": "<string>",
"state": "<string>",
"isDraft": true,
"authorLogin": "<string>",
"prCreatedAtMs": 123,
"prClosedAtMs": 123,
"prMergedAtMs": 123
},
"rows": [
{
"projectId": "<string>",
"projectSlug": "<string>",
"contributorLabel": "<string>",
"contributorIsProject": true,
"agent": "<string>",
"models": [
"<string>"
],
"sessionsCount": 123,
"inputTokens": 123,
"outputTokens": 123,
"cacheReadTokens": 123,
"cacheCreationTokens": 123,
"totalTokens": 123,
"costUsd": 123,
"billedCostUsd": 123,
"nonBilledCostUsd": 123
}
],
"totals": {
"sessionsCount": 123,
"inputTokens": 123,
"outputTokens": 123,
"cacheReadTokens": 123,
"cacheCreationTokens": 123,
"totalTokens": 123,
"costUsd": 123,
"billedCostUsd": 123,
"nonBilledCostUsd": 123
},
"modelBreakdown": [
{
"model": "<string>",
"inputTokens": 123,
"outputTokens": 123,
"cacheReadTokens": 123,
"cacheCreationTokens": 123,
"totalTokens": 123,
"costUsd": 123,
"tokensKnown": true
}
]
}Authorizations
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
The repository as "owner/name".
^[^/\s]+\/[^/\s]+$The pull request number.
The GitHub host. Defaults to this instance's configured GitHub host, which is github.com unless an operator named a GitHub Enterprise Server.
1Was this page helpful?