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)
| 2299 | // request, letting the server apply its own defaults (typically the last |
| 2300 | // 30 days). |
| 2301 | func (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 |