Get user AI spend by organization
Returns the user's effective AI budget and current-period spend in each organization that the user is a current member of and that the caller can read. Organizations the caller cannot read are omitted, so the response for a given user can differ between callers. Each organization's effective group is resolved the same way AI Gateway resolves a budget for a request in that organization, falling back to the organization's Everyone group. organization_id is the organization of the user's site-wide effective group, as reported by GET /users/{user}/ai/spend, and is null when that organization is not in organizations. Access requires permission to read the user, as for GET /users/{user}/ai/spend.
CoderSessionTokenCoder-Session-Token<token>user*stringUser ID, username, or me
OK
application/json- response
organization_id?stringOrganizationID is the organization of the user's site-wide effective group, as reported by UserAISpendStatus. Null when no group resolves or when that organization is not in Organizations.
uuidorganizations?array<>Organizations is the spend per organization the user is a current member of and the caller can read, ordered by organization name.
period_end?stringPeriodEnd is the exclusive upper bound of the applied period.
date-timeperiod_start?stringPeriodStart is the inclusive lower bound of the applied period.
date-timeThe samples read CODER_URL and CODER_SESSION_TOKEN: set up your environment.
curl -X GET \ "$CODER_URL/api/v2/users/{user}/ai/spend/organizations" \ -H "Coder-Session-Token: $CODER_SESSION_TOKEN"const { CODER_URL, CODER_SESSION_TOKEN } = process.env;const url = `${CODER_URL}/api/v2/users/{user}/ai/spend/organizations`;const response = await fetch(url, { method: "GET", headers: { "Coder-Session-Token": CODER_SESSION_TOKEN, },});console.log(response.status, await response.text());import osimport requestsurl = os.environ["CODER_URL"] + "/api/v2/users/{user}/ai/spend/organizations"token = os.environ["CODER_SESSION_TOKEN"]response = requests.get( url, headers={ "Coder-Session-Token": token, },)print(response.status_code, response.text)package mainimport ( "fmt" "io" "net/http" "os")func main() { url := os.Getenv("CODER_URL") + "/api/v2/users/{user}/ai/spend/organizations" token := os.Getenv("CODER_SESSION_TOKEN") req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { panic(err) } req.Header.Set("Coder-Session-Token", token) resp, err := http.DefaultClient.Do(req) if err != nil { panic(err) } defer resp.Body.Close() out, err := io.ReadAll(resp.Body) if err != nil { panic(err) } fmt.Println(resp.Status, string(out))}{ "organization_id": "7c60d51f-b44e-4682-87d6-449835ea4de6", "organizations": [ { "current_spend_micros": 0, "effective_budget": { "limit_source": "user_override", "spend_limit_micros": 0 }, "effective_group_id": "85e2b926-ddfb-4c66-b68e-b66e5acec6c0", "organization": { "display_name": "string", "icon": "string", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "name": "string" } } ], "period_end": "2019-08-24T14:15:22Z", "period_start": "2019-08-24T14:15:22Z"}