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

Method GetChatCostUsers

codersdk/chats.go:2329–2360  ·  view source on GitHub ↗

GetChatCostUsers returns a per-user cost rollup for the deployment (admin only). 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, opts ChatCostUsersOptions)

Source from the content-addressed store, hash-verified

2327// the request, letting the server apply its own defaults (typically the
2328// last 30 days).
2329func (c *ExperimentalClient) GetChatCostUsers(ctx context.Context, opts ChatCostUsersOptions) (ChatCostUsersResponse, error) {
2330 qp := url.Values{}
2331 if !opts.StartDate.IsZero() {
2332 qp.Set("start_date", opts.StartDate.Format(time.RFC3339))
2333 }
2334 if !opts.EndDate.IsZero() {
2335 qp.Set("end_date", opts.EndDate.Format(time.RFC3339))
2336 }
2337 if opts.Username != "" {
2338 qp.Set("username", opts.Username)
2339 }
2340 if opts.Limit > 0 {
2341 qp.Set("limit", strconv.Itoa(opts.Limit))
2342 }
2343 if opts.Offset > 0 {
2344 qp.Set("offset", strconv.Itoa(opts.Offset))
2345 }
2346 reqURL := "/api/experimental/chats/cost/users"
2347 if len(qp) > 0 {
2348 reqURL += "?" + qp.Encode()
2349 }
2350 res, err := c.Request(ctx, http.MethodGet, reqURL, nil)
2351 if err != nil {
2352 return ChatCostUsersResponse{}, err
2353 }
2354 defer res.Body.Close()
2355 if res.StatusCode != http.StatusOK {
2356 return ChatCostUsersResponse{}, ReadBodyAsError(res)
2357 }
2358 var resp ChatCostUsersResponse
2359 return resp, json.NewDecoder(res.Body).Decode(&resp)
2360}
2361
2362// GetChatSystemPrompt returns the deployment-wide chat system prompt.
2363func (c *ExperimentalClient) GetChatSystemPrompt(ctx context.Context) (ChatSystemPromptResponse, error) {

Callers 1

TestChatCostUsersFunction · 0.95

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

TestChatCostUsersFunction · 0.76