a month ago
We want read-only access to the cost and usage metrics of one background worker service in an existing project, to raise budget alerts at 5 and 7 USD. Our OAuth workspace read fails in a way we cannot interpret.
Setup. Native/Public OAuth app, PKCE, no client secret. Scopes requested and returned: exactly openid email profile workspace:viewer, on one explicitly selected workspace (we followed the OAuth troubleshooting page: email and profile alongside a workspace scope). Bearer token accepted, 3600 s expiry. Refresh token discarded, never used. No /oauth/me call.
Test 1 (6 Oct 2026). One token exchange, one POST to https://backboard.railway.com/graphql/v2:
query($workspaceId: String!, $projectId: String!) {
workspace(workspaceId: $workspaceId) { id customer { billingPeriod { start end } } }
project(id: $projectId) { id workspaceId deletedAt services { edges { node { id deletedAt } } } }
}Result: HTTP 200, 138 ms, one error, code INTERNAL_SERVER_ERROR, path ["workspace"], message classified as authorization denied. No data returned. No retry.
Test 2 (same day, new token, same app and scopes). Suggested in this thread. Two reads, stopped at the first failure:
query { me { workspaces { id name } } }query($workspaceId: String!) { workspace(workspaceId: $workspaceId) { id name } }me { workspaces }succeeded (HTTP 200, 165 ms): one workspace, the one we selected.workspace(workspaceId) { id name }failed with the same error (HTTP 200, 121 ms,INTERNAL_SERVER_ERROR, path["workspace"], authorization denied). No partial data.- We did not run the isolated
billingPeriodread, since the previous read had failed. No retries.
So the refusal is not limited to billing fields: even the workspace id and name are refused, while listing visible workspaces works.
Not yet tested: usage(projectId, ..., groupBy: [PROJECT_ID, SERVICE_ID]) and project(id) on its own. We have no separate result for either.
Impact. No cost figures from this path (unavailable, not zero) and no per-service attribution. We are not estimating anything.
Questions
- Is
workspace(workspaceId)intentionally inaccessible to OAuth tokens withworkspace:viewer, or is this a defect? - What is the documented way to read, with this token, the costs and usage of a single service in an existing project?
- Are
usage(projectId, ...)andproject(id)accessible withworkspace:viewerwithout going throughworkspace(...)?
Not asking for: a transferred session, an admin token, or any automatic increase of permissions. We will not retry or try a broader scope before understanding this. No secret, OAuth code, raw response or workspace/project/service ID is included.
Pinned Solution
a month ago
whether the denial of workspace(workspaceId) is intended
As far I can tell, it is intended, from the docs it's only described to work for Workspace and Account tokens, not OAuth tokens.
and the documented way to turn these usage measurements into dollar costs
You can get all the pricing for individual resources from https://railway.com/pricing and from there you can do some math to get the USD cost. For example if your measurement contains 1000 units of memory_gb per month then you just multiply that by the monthly cost for memory to get the cost.
7 Replies
a month ago
This thread has been opened as a bounty so the community can help solve it.
Status changed to Open Railway • about 2 months ago
a month ago
I believe the failure is caused by the customer.billingPeriod part of the query rather than by workspace:viewer itself.
Railway's OAuth docs confirm that workspace:viewer is a valid read-only workspace scope, and OAuth workspace access is tied to the corresponding workspace role:
https://docs.railway.com/integrations/oauth/scopes-and-user-consent
For OAuth workspace discovery, Railway specifically documents using:
query {
me {
workspaces {
id
name
}
}
}with a workspace scope plus email and profile:
https://docs.railway.com/integrations/oauth/fetching-workspaces-or-projects
The query in the bounty, however, is requesting more than workspace metadata:
workspace(workspaceId: $workspaceId) {
id
customer {
billingPeriod {
start
end
}
}
}Railway's workspace documentation states that billing settings are Admin-only:
https://docs.railway.com/projects/workspaces
The docs do not explicitly say that customer.billingPeriod.start/end specifically requires workspace:admin, so I would not treat that as proven. But it is the most likely authorization boundary to test.
There is also an important clue in the error format. Railway's Public API documentation explains that GraphQL authorization failures can be returned as HTTP 200 with INTERNAL_SERVER_ERROR and an authorization message such as Not Authorized:
https://docs.railway.com/integrations/api
So:
HTTP 200
INTERNAL_SERVER_ERROR
path: ["workspace"]
authorization-denied messageis consistent with a GraphQL authorization failure rather than necessarily being a backend outage.
I would isolate it with these two reads using the exact same token:
query {
me {
workspaces {
id
name
}
}
}Then:
query W($workspaceId: String!) {
workspace(workspaceId: $workspaceId) {
id
name
}
}If those succeed, but adding:
customer {
billingPeriod {
start
end
}
}causes Not Authorized, that identifies the failing field/resolver without requiring a broader scope.
For projects, Railway also documents workspace-scoped project listing:
https://docs.railway.com/integrations/api/manage-projects
For usage, I would test the usage operation independently after workspace/project access succeeds rather than assuming that failure of workspace.customer.billingPeriod means usage itself is forbidden.
So my conclusion is:
openid email profile workspace:vieweris a documented OAuth combination.me.workspacesis the documented way to resolve OAuth-accessible workspaces.- The suspicious part of the failing query is
customer.billingPeriod, which crosses into billing/customer data. HTTP 200 + INTERNAL_SERVER_ERROR + Not Authorizedmatches Railway's documented GraphQL authorization error behavior.- The key remaining question for Railway is whether
customer.billingPeriodis intentionally unavailable toworkspace:viewer, or whether that resolver is incorrectly enforcing Admin authorization.
This can be reproduced cleanly without retries or broader permissions by comparing the workspace query with and without customer.billingPeriod.
a month ago
Thanks a lot for the detailed answer and the isolation plan.
I ran your suggested test once, with the same token type (openid email profile workspace:viewer, no broader scope, no retry). Results:
me { workspaces { id name } } succeeded and returned the selected workspace.
workspace(workspaceId: ...) { id name } failed with the same error as before: HTTP 200, INTERNAL_SERVER_ERROR, path ["workspace"], authorization-denied message.
So the refusal is not limited to customer.billingPeriod: even the workspace id and name are denied with workspace:viewer. I did not run the third read (with billingPeriod) because the second one already failed.
This leaves two open questions: is workspace(workspaceId) intentionally unavailable to workspace:viewer OAuth tokens, and which documented path should be used to read usage for a single service?
Thanks again, your suggestion narrowed it down a lot.
mcallengrind
Thanks a lot for the detailed answer and the isolation plan. I ran your suggested test once, with the same token type (openid email profile workspace:viewer, no broader scope, no retry). Results: me { workspaces { id name } } succeeded and returned the selected workspace. workspace(workspaceId: ...) { id name } failed with the same error as before: HTTP 200, INTERNAL_SERVER_ERROR, path ["workspace"], authorization-denied message. So the refusal is not limited to customer.billingPeriod: even the workspace id and name are denied with workspace:viewer. I did not run the third read (with billingPeriod) because the second one already failed. This leaves two open questions: is workspace(workspaceId) intentionally unavailable to workspace:viewer OAuth tokens, and which documented path should be used to read usage for a single service? Thanks again, your suggestion narrowed it down a lot.
a month ago
Thanks for running the isolation test. That result changes the diagnosis:
customer.billingPeriod is not the cause, because even the minimal
query W($workspaceId: String!) {
workspace(workspaceId: $workspaceId) {
id
name
}
}is denied with the same INTERNAL_SERVER_ERROR / authorization message.
This points to an OAuth authorization mismatch on the workspace(workspaceId) resolver itself.
Railway's OAuth documentation says that workspace:viewer grants access to user-selected workspaces and specifically documents:
query {
me {
workspaces {
id
name
}
}
}for discovering those selected workspaces:
https://docs.railway.com/integrations/oauth/fetching-workspaces-or-projects
https://docs.railway.com/integrations/oauth/scopes-and-user-consent
But Railway's Public API documentation shows workspace(workspaceId) as the example for workspace tokens, and says an account token can use it when the account is a member:
https://docs.railway.com/integrations/api
Given the controlled result here, I would not describe workspace(workspaceId) as an available operation for a workspace:viewer OAuth token. The documented OAuth path is me.workspaces; the subsequent direct workspace resolver appears to be rejected for this token class.
The error code is also consistent with Railway's documented behavior: GraphQL authorization failures can return HTTP 200 with extensions.code = INTERNAL_SERVER_ERROR and an authorization message:
https://docs.railway.com/integrations/api
For the second question, Railway's current usage documentation confirms that service-level cost attribution exists:
railway usage projects --project <PROJECT> --period currentThe documented output is a service-level breakdown including CPU, memory, egress, volume, backup and total cost:
https://docs.railway.com/cli/usage
https://docs.railway.com/projects/project-usage
What is not currently documented is an OAuth-specific usage(...) GraphQL example showing that workspace:viewer is authorized to read those cost records.
The practical least-privilege path appears to be:
OAuth viewer
↓
me.workspaces
↓
obtain/identify the project
↓
query usage directly by projectId
↓
group/filter by SERVICE_IDrather than:
OAuth viewer
↓
workspace(workspaceId)For project-scoped OAuth, Railway documents externalWorkspaces { projects { ... } } with project:viewer / project:member, which may be the more appropriate grant when the application only needs one project:
https://docs.railway.com/integrations/oauth/fetching-workspaces-or-projects
Railway also explicitly says the Public API supports live GraphQL introspection, so the final question of whether usage(projectId: ...) is authorized for the viewer grant can be settled from the live schema/permission behavior rather than guessing at fields:
https://docs.railway.com/integrations/api
So I think the reproducible issue is now quite precise:
me.workspaces works with workspace:viewer, but workspace(workspaceId) does not, despite the OAuth documentation saying selected workspace resources can be queried through the Public API.
That is an OAuth/API authorization gap (or documentation mismatch) independent of billing permissions.
For the usage requirement, Railway documents the capability at the CLI level but does not currently document an OAuth-specific least-privilege GraphQL permission path for service-level cost attribution. That is the part Railway would need to clarify or expose explicitly.
faisal-business
Thanks for running the isolation test. That result changes the diagnosis: `customer.billingPeriod` is not the cause, because even the minimal ```graphql query W($workspaceId: String!) { workspace(workspaceId: $workspaceId) { id name } } ``` is denied with the same `INTERNAL_SERVER_ERROR` / authorization message. This points to an OAuth authorization mismatch on the `workspace(workspaceId)` resolver itself. Railway's OAuth documentation says that `workspace:viewer` grants access to user-selected workspaces and specifically documents: ```graphql query { me { workspaces { id name } } } ``` for discovering those selected workspaces: https://docs.railway.com/integrations/oauth/fetching-workspaces-or-projects https://docs.railway.com/integrations/oauth/scopes-and-user-consent But Railway's Public API documentation shows `workspace(workspaceId)` as the example for **workspace tokens**, and says an account token can use it when the account is a member: https://docs.railway.com/integrations/api Given the controlled result here, I would not describe `workspace(workspaceId)` as an available operation for a `workspace:viewer` OAuth token. The documented OAuth path is `me.workspaces`; the subsequent direct workspace resolver appears to be rejected for this token class. The error code is also consistent with Railway's documented behavior: GraphQL authorization failures can return HTTP 200 with `extensions.code = INTERNAL_SERVER_ERROR` and an authorization message: https://docs.railway.com/integrations/api For the second question, Railway's current usage documentation confirms that service-level cost attribution exists: ```text railway usage projects --project <PROJECT> --period current ``` The documented output is a service-level breakdown including CPU, memory, egress, volume, backup and total cost: https://docs.railway.com/cli/usage https://docs.railway.com/projects/project-usage What is *not* currently documented is an OAuth-specific `usage(...)` GraphQL example showing that `workspace:viewer` is authorized to read those cost records. The practical least-privilege path appears to be: ```text OAuth viewer ↓ me.workspaces ↓ obtain/identify the project ↓ query usage directly by projectId ↓ group/filter by SERVICE_ID ``` rather than: ```text OAuth viewer ↓ workspace(workspaceId) ``` For project-scoped OAuth, Railway documents `externalWorkspaces { projects { ... } }` with `project:viewer` / `project:member`, which may be the more appropriate grant when the application only needs one project: https://docs.railway.com/integrations/oauth/fetching-workspaces-or-projects Railway also explicitly says the Public API supports live GraphQL introspection, so the final question of whether `usage(projectId: ...)` is authorized for the viewer grant can be settled from the live schema/permission behavior rather than guessing at fields: https://docs.railway.com/integrations/api So I think the reproducible issue is now quite precise: **`me.workspaces` works with `workspace:viewer`, but `workspace(workspaceId)` does not, despite the OAuth documentation saying selected workspace resources can be queried through the Public API.** That is an OAuth/API authorization gap (or documentation mismatch) independent of billing permissions. For the usage requirement, Railway documents the capability at the CLI level but does not currently document an OAuth-specific least-privilege GraphQL permission path for service-level cost attribution. That is the part Railway would need to clarify or expose explicitly.
a month ago
Follow-up with a result. I retried your suggestion once, with the same token type (openid email profile workspace:viewer, no broader scope, no retry), and it worked: usage(projectId, ...) is readable and does not go through workspace(...).
The read returned HTTP 200 with no error and 14 rows, covering the five measurement types (memory, CPU, network egress, disk and backup), with a breakdown by service (4 distinct services, deleted ones included).
So for this token class: me { workspaces } works, workspace(workspaceId) is denied (even for id and name), and usage(projectId, ...) is readable. My earlier posts say usage was never tested; that is now outdated.
Two things remain open: whether the denial of workspace(workspaceId) is intended, and the documented way to turn these usage measurements into dollar costs, since the response contains measurements, not prices. I'm leaving the thread open for a Railway answer.
Thanks again, your suggestion is what made this work.
a month ago
whether the denial of workspace(workspaceId) is intended
As far I can tell, it is intended, from the docs it's only described to work for Workspace and Account tokens, not OAuth tokens.
and the documented way to turn these usage measurements into dollar costs
You can get all the pricing for individual resources from https://railway.com/pricing and from there you can do some math to get the USD cost. For example if your measurement contains 1000 units of memory_gb per month then you just multiply that by the monthly cost for memory to get the cost.
dev
> whether the denial of workspace(workspaceId) is intended As far I can tell, it is intended, from [the docs](https://docs.railway.com/integrations/api#using-a-workspace-token) it's only described to work for `Workspace` and `Account` tokens, not `OAuth` tokens. > and the documented way to turn these usage measurements into dollar costs You can get all the pricing for individual resources from https://railway.com/pricing and from there you can do some math to get the USD cost. For example if your measurement contains 1000 units of memory_gb per month then you just multiply that by the monthly cost for memory to get the cost.
a month ago
Thanks, that clears it up. Understood that workspace(workspaceId) is documented for Workspace and Account tokens only, so the denial for OAuth tokens is expected.
For anyone finding this later: with a workspace:viewer OAuth token (plus offline_access to get a refresh token), me { workspaces } and usage(projectId, ...) both worked for us, and the usage response is broken down by service.
On pricing, we converted the measurements with the per-resource rates from the pricing page and the result matched our invoice within about 2%, the gap being explained by our window start. One note for others: in our data the values are per-minute quantities (GB-minutes for memory and disk, vCPU-minutes for CPU, GB for egress), so the monthly price has to be divided by 43,200 minutes before multiplying.
One remaining question: is reading usage(projectId, ...) with a workspace:viewer OAuth token an intended, supported path, or just currently allowed? We would like to rely on it for budget alerts.
a month ago
Glad you got it all sorted now!
One remaining question: is reading usage(projectId, ...) with a workspace:viewer OAuth token an intended, supported path, or just currently allowed? We would like to rely on it for budget alerts.
Yes, as far as I know it's intended and you should be fine to rely on it for a good amount of time
Status changed to Awaiting User Response Railway • about 1 month ago
Status changed to Solved dev • about 1 month ago


