MCPcopy Index your code
hub / github.com/coder/coder / GetChatCostSummary

Method GetChatCostSummary

codersdk/chats.go:2301–2323  ·  view source on GitHub ↗

GetChatCostSummary returns an aggregate cost summary for the specified user. Zero-valued StartDate or EndDate fields are omitted from the request, letting the server apply its own defaults (typically the last 30 days).

(ctx context.Context, user string, opts ChatCostSummaryOptions)

Source from the content-addressed store, hash-verified

2299// request, letting the server apply its own defaults (typically the last
2300// 30 days).
2301func (c *ExperimentalClient) GetChatCostSummary(ctx context.Context, user string, opts ChatCostSummaryOptions) (ChatCostSummary, error) {
2302 qp := url.Values{}
2303 if !opts.StartDate.IsZero() {
2304 qp.Set("start_date", opts.StartDate.Format(time.RFC3339))
2305 }
2306 if !opts.EndDate.IsZero() {
2307 qp.Set("end_date", opts.EndDate.Format(time.RFC3339))
2308 }
2309 reqURL := fmt.Sprintf("/api/experimental/chats/cost/%s/summary", user)
2310 if len(qp) > 0 {
2311 reqURL += "?" + qp.Encode()
2312 }
2313 res, err := c.Request(ctx, http.MethodGet, reqURL, nil)
2314 if err != nil {
2315 return ChatCostSummary{}, err
2316 }
2317 defer res.Body.Close()
2318 if res.StatusCode != http.StatusOK {
2319 return ChatCostSummary{}, ReadBodyAsError(res)
2320 }
2321 var summary ChatCostSummary
2322 return summary, json.NewDecoder(res.Body).Decode(&summary)
2323}
2324
2325// GetChatCostUsers returns a per-user cost rollup for the deployment
2326// (admin only). Zero-valued StartDate or EndDate fields are omitted from

Callers 1

Calls 7

ReadBodyAsErrorFunction · 0.85
EncodeMethod · 0.80
SetMethod · 0.65
FormatMethod · 0.65
CloseMethod · 0.65
IsZeroMethod · 0.45
RequestMethod · 0.45

Tested by 1