mirror of
https://github.com/hanzo-go/sdk.git
synced 2026-11-20 20:13:42 +00:00
743 lines
27 KiB
Go
743 lines
27 KiB
Go
/*
|
|
Hanzo Cloud API
|
|
|
|
The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
|
|
|
|
API version: v1
|
|
*/
|
|
|
|
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
|
|
|
|
package hanzoai
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"io"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
// UsageAPIService UsageAPI service
|
|
type UsageAPIService service
|
|
|
|
type UsageAPIGetUsageAnalyticsRequest struct {
|
|
ctx context.Context
|
|
ApiService *UsageAPIService
|
|
end *string
|
|
plan *string
|
|
range_ *string
|
|
start *string
|
|
}
|
|
|
|
// End is the exclusive window end, RFC3339. Read only when Range is custom.
|
|
func (r UsageAPIGetUsageAnalyticsRequest) End(end string) UsageAPIGetUsageAnalyticsRequest {
|
|
r.end = &end
|
|
return r
|
|
}
|
|
|
|
// Plan is the plan id whose entitlement decides access and retention. INTERIM: cloud has no org-to-plan resolver yet, so the caller names the plan; when that resolver lands this becomes the caller org's own plan.
|
|
func (r UsageAPIGetUsageAnalyticsRequest) Plan(plan string) UsageAPIGetUsageAnalyticsRequest {
|
|
r.plan = &plan
|
|
return r
|
|
}
|
|
|
|
// Range is the window: a count and a unit — 24h, 7d, 90d, any <N>h or <N>d — or day, week, month, all, custom. Empty means 24h. The window is then clamped forward to the plan's retention entitlement.
|
|
func (r UsageAPIGetUsageAnalyticsRequest) Range_(range_ string) UsageAPIGetUsageAnalyticsRequest {
|
|
r.range_ = &range_
|
|
return r
|
|
}
|
|
|
|
// Start is the inclusive window start, RFC3339. Read only when Range is custom, and clamped forward to the plan's retention floor.
|
|
func (r UsageAPIGetUsageAnalyticsRequest) Start(start string) UsageAPIGetUsageAnalyticsRequest {
|
|
r.start = &start
|
|
return r
|
|
}
|
|
|
|
func (r UsageAPIGetUsageAnalyticsRequest) Execute() (*UsageUsageAnalyticsView, *http.Response, error) {
|
|
return r.ApiService.GetUsageAnalyticsExecute(r)
|
|
}
|
|
|
|
/*
|
|
GetUsageAnalytics Is the entitlement-GATED per-provider breakdown of the caller org's LLM usage — the paid lens over the same warehouse ledger GET /v1/usage/summary reads its totals from.
|
|
|
|
Is the entitlement-GATED per-provider breakdown of the caller org's LLM
|
|
usage — the paid lens over the same warehouse ledger GET /v1/usage/summary reads
|
|
its totals from. Basic own-org usage stays ungated at /v1/usage/summary.
|
|
|
|
A plan that does not grant the analytics datastore is refused with 402, and an
|
|
unresolvable plan fails closed to the free floor, which does not grant it. The
|
|
window is clamped forward to the plan's retention entitlement, so a tenant can
|
|
never read older than its plan allows even with a custom start. The response is
|
|
marked no-store.
|
|
|
|
INTERIM (mirrors apps/world's limits echo): no org→plan resolver exists in cloud
|
|
yet — the subscription lookup is owned by the billing plane and the gateway
|
|
principal carries no plan claim — so the caller passes the plan and the gate
|
|
resolves THAT plan's access.
|
|
|
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
|
@return UsageAPIGetUsageAnalyticsRequest
|
|
*/
|
|
func (a *UsageAPIService) GetUsageAnalytics(ctx context.Context) UsageAPIGetUsageAnalyticsRequest {
|
|
return UsageAPIGetUsageAnalyticsRequest{
|
|
ApiService: a,
|
|
ctx: ctx,
|
|
}
|
|
}
|
|
|
|
// Execute executes the request
|
|
//
|
|
// @return UsageUsageAnalyticsView
|
|
func (a *UsageAPIService) GetUsageAnalyticsExecute(r UsageAPIGetUsageAnalyticsRequest) (*UsageUsageAnalyticsView, *http.Response, error) {
|
|
var (
|
|
localVarHTTPMethod = http.MethodGet
|
|
localVarPostBody interface{}
|
|
formFiles []formFile
|
|
localVarReturnValue *UsageUsageAnalyticsView
|
|
)
|
|
|
|
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "UsageAPIService.GetUsageAnalytics")
|
|
if err != nil {
|
|
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
|
|
}
|
|
|
|
localVarPath := localBasePath + "/v1/usage/analytics"
|
|
|
|
localVarHeaderParams := make(map[string]string)
|
|
localVarQueryParams := url.Values{}
|
|
localVarFormParams := url.Values{}
|
|
|
|
if r.end != nil {
|
|
parameterAddToHeaderOrQuery(localVarQueryParams, "end", r.end, "form", "")
|
|
}
|
|
if r.plan != nil {
|
|
parameterAddToHeaderOrQuery(localVarQueryParams, "plan", r.plan, "form", "")
|
|
}
|
|
if r.range_ != nil {
|
|
parameterAddToHeaderOrQuery(localVarQueryParams, "range", r.range_, "form", "")
|
|
}
|
|
if r.start != nil {
|
|
parameterAddToHeaderOrQuery(localVarQueryParams, "start", r.start, "form", "")
|
|
}
|
|
// to determine the Content-Type header
|
|
localVarHTTPContentTypes := []string{}
|
|
|
|
// set Content-Type header
|
|
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
|
|
if localVarHTTPContentType != "" {
|
|
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
|
|
}
|
|
|
|
// to determine the Accept header
|
|
localVarHTTPHeaderAccepts := []string{"application/json", "application/problem+json"}
|
|
|
|
// set Accept header
|
|
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
|
|
if localVarHTTPHeaderAccept != "" {
|
|
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
|
|
}
|
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
|
if err != nil {
|
|
return localVarReturnValue, nil, err
|
|
}
|
|
|
|
localVarHTTPResponse, err := a.client.callAPI(req)
|
|
if err != nil || localVarHTTPResponse == nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
|
|
localVarHTTPResponse.Body.Close()
|
|
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
|
|
if err != nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
if localVarHTTPResponse.StatusCode >= 300 {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: localVarHTTPResponse.Status,
|
|
}
|
|
var v ProblemDetails
|
|
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr.error = err.Error()
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
|
|
newErr.model = v
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: err.Error(),
|
|
}
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
return localVarReturnValue, localVarHTTPResponse, nil
|
|
}
|
|
|
|
type UsageAPIGetUsageAnalyticsAccessRequest struct {
|
|
ctx context.Context
|
|
ApiService *UsageAPIService
|
|
plan *string
|
|
}
|
|
|
|
// Plan is a plan id from the live @hanzo/plans catalog. Empty resolves the free floor, and so does an id the catalog does not know — this never fails on an unknown plan.
|
|
func (r UsageAPIGetUsageAnalyticsAccessRequest) Plan(plan string) UsageAPIGetUsageAnalyticsAccessRequest {
|
|
r.plan = &plan
|
|
return r
|
|
}
|
|
|
|
func (r UsageAPIGetUsageAnalyticsAccessRequest) Execute() (*UsageUsageAnalyticsAccess, *http.Response, error) {
|
|
return r.ApiService.GetUsageAnalyticsAccessExecute(r)
|
|
}
|
|
|
|
/*
|
|
GetUsageAnalyticsAccess Echoes a plan's resolved analytics entitlement so a dashboard can configure itself against the LIVE catalog instead of hardcoding tier numbers.
|
|
|
|
Echoes a plan's resolved analytics entitlement so a dashboard can
|
|
configure itself against the LIVE catalog instead of hardcoding tier numbers. An
|
|
empty plan resolves the free floor, and a catalog resolution failure serves that
|
|
same floor rather than erroring — so this always answers 200. It is a read-only
|
|
contract echo and carries no tenant data.
|
|
|
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
|
@return UsageAPIGetUsageAnalyticsAccessRequest
|
|
*/
|
|
func (a *UsageAPIService) GetUsageAnalyticsAccess(ctx context.Context) UsageAPIGetUsageAnalyticsAccessRequest {
|
|
return UsageAPIGetUsageAnalyticsAccessRequest{
|
|
ApiService: a,
|
|
ctx: ctx,
|
|
}
|
|
}
|
|
|
|
// Execute executes the request
|
|
//
|
|
// @return UsageUsageAnalyticsAccess
|
|
func (a *UsageAPIService) GetUsageAnalyticsAccessExecute(r UsageAPIGetUsageAnalyticsAccessRequest) (*UsageUsageAnalyticsAccess, *http.Response, error) {
|
|
var (
|
|
localVarHTTPMethod = http.MethodGet
|
|
localVarPostBody interface{}
|
|
formFiles []formFile
|
|
localVarReturnValue *UsageUsageAnalyticsAccess
|
|
)
|
|
|
|
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "UsageAPIService.GetUsageAnalyticsAccess")
|
|
if err != nil {
|
|
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
|
|
}
|
|
|
|
localVarPath := localBasePath + "/v1/usage/analytics/access"
|
|
|
|
localVarHeaderParams := make(map[string]string)
|
|
localVarQueryParams := url.Values{}
|
|
localVarFormParams := url.Values{}
|
|
|
|
if r.plan != nil {
|
|
parameterAddToHeaderOrQuery(localVarQueryParams, "plan", r.plan, "form", "")
|
|
}
|
|
// to determine the Content-Type header
|
|
localVarHTTPContentTypes := []string{}
|
|
|
|
// set Content-Type header
|
|
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
|
|
if localVarHTTPContentType != "" {
|
|
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
|
|
}
|
|
|
|
// to determine the Accept header
|
|
localVarHTTPHeaderAccepts := []string{"application/json", "application/problem+json"}
|
|
|
|
// set Accept header
|
|
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
|
|
if localVarHTTPHeaderAccept != "" {
|
|
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
|
|
}
|
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
|
if err != nil {
|
|
return localVarReturnValue, nil, err
|
|
}
|
|
|
|
localVarHTTPResponse, err := a.client.callAPI(req)
|
|
if err != nil || localVarHTTPResponse == nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
|
|
localVarHTTPResponse.Body.Close()
|
|
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
|
|
if err != nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
if localVarHTTPResponse.StatusCode >= 300 {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: localVarHTTPResponse.Status,
|
|
}
|
|
var v ProblemDetails
|
|
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr.error = err.Error()
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
|
|
newErr.model = v
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: err.Error(),
|
|
}
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
return localVarReturnValue, localVarHTTPResponse, nil
|
|
}
|
|
|
|
type UsageAPIGetUsageSamplesRequest struct {
|
|
ctx context.Context
|
|
ApiService *UsageAPIService
|
|
account *string
|
|
provider *string
|
|
range_ *string
|
|
window *string
|
|
}
|
|
|
|
// Account narrows to ONE linked account of that provider. Empty covers every account the caller has linked there.
|
|
func (r UsageAPIGetUsageSamplesRequest) Account(account string) UsageAPIGetUsageSamplesRequest {
|
|
r.account = &account
|
|
return r
|
|
}
|
|
|
|
// Provider is the upstream to read, e.g. anthropic. Required.
|
|
func (r UsageAPIGetUsageSamplesRequest) Provider(provider string) UsageAPIGetUsageSamplesRequest {
|
|
r.provider = &provider
|
|
return r
|
|
}
|
|
|
|
// Range is the window to read: a count and a unit — 1h, 24h, 90d, any <N>h or <N>d — or day, week, month, all. Empty means 24h. A label that is not a count, or one reaching past the 730-day horizon, is refused rather than silently replaced.
|
|
func (r UsageAPIGetUsageSamplesRequest) Range_(range_ string) UsageAPIGetUsageSamplesRequest {
|
|
r.range_ = &range_
|
|
return r
|
|
}
|
|
|
|
// Window narrows to ONE window class: 6h, day, week or month. Empty covers every class.
|
|
func (r UsageAPIGetUsageSamplesRequest) Window(window string) UsageAPIGetUsageSamplesRequest {
|
|
r.window = &window
|
|
return r
|
|
}
|
|
|
|
func (r UsageAPIGetUsageSamplesRequest) Execute() (*UsageDashResp, *http.Response, error) {
|
|
return r.ApiService.GetUsageSamplesExecute(r)
|
|
}
|
|
|
|
/*
|
|
GetUsageSamples Is the PER-PROVIDER view: one connected account's own consumption of its own plan — \"my plan is 47% through its 6h window, resets at 14:20\".
|
|
|
|
Is the PER-PROVIDER view: one connected account's own consumption of its
|
|
own plan — "my plan is 47% through its 6h window, resets at 14:20".
|
|
|
|
`current` is the newest instance of each lane (the headline); `windows` is the
|
|
history behind it. Both come from ONE deduped read, so they can never disagree.
|
|
The rows are the caller's OWN linked accounts, scoped to the validated principal
|
|
and its subject — never another user's, and never another org's.
|
|
|
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
|
@return UsageAPIGetUsageSamplesRequest
|
|
*/
|
|
func (a *UsageAPIService) GetUsageSamples(ctx context.Context) UsageAPIGetUsageSamplesRequest {
|
|
return UsageAPIGetUsageSamplesRequest{
|
|
ApiService: a,
|
|
ctx: ctx,
|
|
}
|
|
}
|
|
|
|
// Execute executes the request
|
|
//
|
|
// @return UsageDashResp
|
|
func (a *UsageAPIService) GetUsageSamplesExecute(r UsageAPIGetUsageSamplesRequest) (*UsageDashResp, *http.Response, error) {
|
|
var (
|
|
localVarHTTPMethod = http.MethodGet
|
|
localVarPostBody interface{}
|
|
formFiles []formFile
|
|
localVarReturnValue *UsageDashResp
|
|
)
|
|
|
|
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "UsageAPIService.GetUsageSamples")
|
|
if err != nil {
|
|
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
|
|
}
|
|
|
|
localVarPath := localBasePath + "/v1/usage/samples"
|
|
|
|
localVarHeaderParams := make(map[string]string)
|
|
localVarQueryParams := url.Values{}
|
|
localVarFormParams := url.Values{}
|
|
|
|
if r.account != nil {
|
|
parameterAddToHeaderOrQuery(localVarQueryParams, "account", r.account, "form", "")
|
|
}
|
|
if r.provider != nil {
|
|
parameterAddToHeaderOrQuery(localVarQueryParams, "provider", r.provider, "form", "")
|
|
}
|
|
if r.range_ != nil {
|
|
parameterAddToHeaderOrQuery(localVarQueryParams, "range", r.range_, "form", "")
|
|
}
|
|
if r.window != nil {
|
|
parameterAddToHeaderOrQuery(localVarQueryParams, "window", r.window, "form", "")
|
|
}
|
|
// to determine the Content-Type header
|
|
localVarHTTPContentTypes := []string{}
|
|
|
|
// set Content-Type header
|
|
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
|
|
if localVarHTTPContentType != "" {
|
|
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
|
|
}
|
|
|
|
// to determine the Accept header
|
|
localVarHTTPHeaderAccepts := []string{"application/json", "application/problem+json"}
|
|
|
|
// set Accept header
|
|
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
|
|
if localVarHTTPHeaderAccept != "" {
|
|
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
|
|
}
|
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
|
if err != nil {
|
|
return localVarReturnValue, nil, err
|
|
}
|
|
|
|
localVarHTTPResponse, err := a.client.callAPI(req)
|
|
if err != nil || localVarHTTPResponse == nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
|
|
localVarHTTPResponse.Body.Close()
|
|
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
|
|
if err != nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
if localVarHTTPResponse.StatusCode >= 300 {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: localVarHTTPResponse.Status,
|
|
}
|
|
var v ProblemDetails
|
|
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr.error = err.Error()
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
|
|
newErr.model = v
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: err.Error(),
|
|
}
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
return localVarReturnValue, localVarHTTPResponse, nil
|
|
}
|
|
|
|
type UsageAPIGetUsageSummaryRequest struct {
|
|
ctx context.Context
|
|
ApiService *UsageAPIService
|
|
range_ *string
|
|
start *string
|
|
end *string
|
|
}
|
|
|
|
// Range is the window: a count and a unit — 24h, 7d, 90d, any <N>h or <N>d — or day, week, month, all, custom. Empty means 24h. A label this surface does not know, or one reaching past the 730-day horizon, is refused rather than silently replaced.
|
|
func (r UsageAPIGetUsageSummaryRequest) Range_(range_ string) UsageAPIGetUsageSummaryRequest {
|
|
r.range_ = &range_
|
|
return r
|
|
}
|
|
|
|
// Start is the inclusive window start, RFC3339. Read only when Range is custom.
|
|
func (r UsageAPIGetUsageSummaryRequest) Start(start string) UsageAPIGetUsageSummaryRequest {
|
|
r.start = &start
|
|
return r
|
|
}
|
|
|
|
// End is the exclusive window end, RFC3339. Read only when Range is custom.
|
|
func (r UsageAPIGetUsageSummaryRequest) End(end string) UsageAPIGetUsageSummaryRequest {
|
|
r.end = &end
|
|
return r
|
|
}
|
|
|
|
func (r UsageAPIGetUsageSummaryRequest) Execute() (*UsageUsageSummary, *http.Response, error) {
|
|
return r.ApiService.GetUsageSummaryExecute(r)
|
|
}
|
|
|
|
/*
|
|
GetUsageSummary Answers GET /v1/usage/summary: the caller's own usage footprint over one window — the categorized spend roll-up from the commerce ledger, the org's LLM usage totals from the warehouse (with what the prompt cache served and saved), the org's Kai decisions, and the caller's OWN linked provider accounts beside the org's Hanzo-routed usage.
|
|
|
|
Answers GET /v1/usage/summary: the caller's own usage footprint over one
|
|
window — the categorized spend roll-up from the commerce ledger, the org's LLM
|
|
usage totals from the warehouse (with what the prompt cache served and saved),
|
|
the org's Kai decisions, and the caller's OWN linked provider accounts beside
|
|
the org's Hanzo-routed usage.
|
|
|
|
Every source degrades INDEPENDENTLY to honest zeros and says so in `sources` and
|
|
in its own `available` flag, so a partial deploy reports "no data" rather than
|
|
fabricating spend. The account rows and the Hanzo rows are concatenated and never
|
|
summed: a plan's percent is not money.
|
|
|
|
The response is org-scoped from the validated principal and marked no-store — a
|
|
signed-out caller is refused.
|
|
|
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
|
@return UsageAPIGetUsageSummaryRequest
|
|
*/
|
|
func (a *UsageAPIService) GetUsageSummary(ctx context.Context) UsageAPIGetUsageSummaryRequest {
|
|
return UsageAPIGetUsageSummaryRequest{
|
|
ApiService: a,
|
|
ctx: ctx,
|
|
}
|
|
}
|
|
|
|
// Execute executes the request
|
|
//
|
|
// @return UsageUsageSummary
|
|
func (a *UsageAPIService) GetUsageSummaryExecute(r UsageAPIGetUsageSummaryRequest) (*UsageUsageSummary, *http.Response, error) {
|
|
var (
|
|
localVarHTTPMethod = http.MethodGet
|
|
localVarPostBody interface{}
|
|
formFiles []formFile
|
|
localVarReturnValue *UsageUsageSummary
|
|
)
|
|
|
|
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "UsageAPIService.GetUsageSummary")
|
|
if err != nil {
|
|
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
|
|
}
|
|
|
|
localVarPath := localBasePath + "/v1/usage/summary"
|
|
|
|
localVarHeaderParams := make(map[string]string)
|
|
localVarQueryParams := url.Values{}
|
|
localVarFormParams := url.Values{}
|
|
|
|
if r.range_ != nil {
|
|
parameterAddToHeaderOrQuery(localVarQueryParams, "range", r.range_, "form", "")
|
|
}
|
|
if r.start != nil {
|
|
parameterAddToHeaderOrQuery(localVarQueryParams, "start", r.start, "form", "")
|
|
}
|
|
if r.end != nil {
|
|
parameterAddToHeaderOrQuery(localVarQueryParams, "end", r.end, "form", "")
|
|
}
|
|
// to determine the Content-Type header
|
|
localVarHTTPContentTypes := []string{}
|
|
|
|
// set Content-Type header
|
|
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
|
|
if localVarHTTPContentType != "" {
|
|
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
|
|
}
|
|
|
|
// to determine the Accept header
|
|
localVarHTTPHeaderAccepts := []string{"application/json", "application/problem+json"}
|
|
|
|
// set Accept header
|
|
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
|
|
if localVarHTTPHeaderAccept != "" {
|
|
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
|
|
}
|
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
|
if err != nil {
|
|
return localVarReturnValue, nil, err
|
|
}
|
|
|
|
localVarHTTPResponse, err := a.client.callAPI(req)
|
|
if err != nil || localVarHTTPResponse == nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
|
|
localVarHTTPResponse.Body.Close()
|
|
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
|
|
if err != nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
if localVarHTTPResponse.StatusCode >= 300 {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: localVarHTTPResponse.Status,
|
|
}
|
|
var v ProblemDetails
|
|
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr.error = err.Error()
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
|
|
newErr.model = v
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: err.Error(),
|
|
}
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
return localVarReturnValue, localVarHTTPResponse, nil
|
|
}
|
|
|
|
type UsageAPIPostUsageRequest struct {
|
|
ctx context.Context
|
|
ApiService *UsageAPIService
|
|
usageReportReq *UsageReportReq
|
|
}
|
|
|
|
func (r UsageAPIPostUsageRequest) UsageReportReq(usageReportReq UsageReportReq) UsageAPIPostUsageRequest {
|
|
r.usageReportReq = &usageReportReq
|
|
return r
|
|
}
|
|
|
|
func (r UsageAPIPostUsageRequest) Execute() (*UsageReportResp, *http.Response, error) {
|
|
return r.ApiService.PostUsageExecute(r)
|
|
}
|
|
|
|
/*
|
|
PostUsage Ingests a batch of account-usage samples — what a developer's OWN AI accounts have consumed of their OWN plans, metered from each provider's own login — and appends them to the warehouse series.
|
|
|
|
Ingests a batch of account-usage samples — what a developer's OWN AI
|
|
accounts have consumed of their OWN plans, metered from each provider's own
|
|
login — and appends them to the warehouse series. Answers 202.
|
|
|
|
Send either a `samples` array or one sample's fields at the top level. Every
|
|
sample needs a provider, a machine and a known window class; an unknown window or
|
|
kind is refused rather than silently rewritten, because a dash filled with a class
|
|
nobody reported is worse than an error. There is no timestamp field: the server
|
|
owns the observation clock, and a sample says which window it measured with
|
|
windowStart or resetsAt.
|
|
|
|
It is FAIL-SOFT on storage: a warehouse outage costs a poll of history
|
|
(stored:false), never a failed request. It records usage ONLY — the link registry
|
|
is refreshed separately via POST /v1/link, so there is one and only one way to
|
|
update an account row.
|
|
|
|
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
|
@return UsageAPIPostUsageRequest
|
|
*/
|
|
func (a *UsageAPIService) PostUsage(ctx context.Context) UsageAPIPostUsageRequest {
|
|
return UsageAPIPostUsageRequest{
|
|
ApiService: a,
|
|
ctx: ctx,
|
|
}
|
|
}
|
|
|
|
// Execute executes the request
|
|
//
|
|
// @return UsageReportResp
|
|
func (a *UsageAPIService) PostUsageExecute(r UsageAPIPostUsageRequest) (*UsageReportResp, *http.Response, error) {
|
|
var (
|
|
localVarHTTPMethod = http.MethodPost
|
|
localVarPostBody interface{}
|
|
formFiles []formFile
|
|
localVarReturnValue *UsageReportResp
|
|
)
|
|
|
|
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "UsageAPIService.PostUsage")
|
|
if err != nil {
|
|
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
|
|
}
|
|
|
|
localVarPath := localBasePath + "/v1/usage"
|
|
|
|
localVarHeaderParams := make(map[string]string)
|
|
localVarQueryParams := url.Values{}
|
|
localVarFormParams := url.Values{}
|
|
if r.usageReportReq == nil {
|
|
return localVarReturnValue, nil, reportError("usageReportReq is required and must be specified")
|
|
}
|
|
|
|
// to determine the Content-Type header
|
|
localVarHTTPContentTypes := []string{"application/json"}
|
|
|
|
// set Content-Type header
|
|
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
|
|
if localVarHTTPContentType != "" {
|
|
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
|
|
}
|
|
|
|
// to determine the Accept header
|
|
localVarHTTPHeaderAccepts := []string{"application/json", "application/problem+json"}
|
|
|
|
// set Accept header
|
|
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
|
|
if localVarHTTPHeaderAccept != "" {
|
|
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
|
|
}
|
|
// body params
|
|
localVarPostBody = r.usageReportReq
|
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
|
if err != nil {
|
|
return localVarReturnValue, nil, err
|
|
}
|
|
|
|
localVarHTTPResponse, err := a.client.callAPI(req)
|
|
if err != nil || localVarHTTPResponse == nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
|
|
localVarHTTPResponse.Body.Close()
|
|
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
|
|
if err != nil {
|
|
return localVarReturnValue, localVarHTTPResponse, err
|
|
}
|
|
|
|
if localVarHTTPResponse.StatusCode >= 300 {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: localVarHTTPResponse.Status,
|
|
}
|
|
var v ProblemDetails
|
|
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr.error = err.Error()
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
|
|
newErr.model = v
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
|
|
if err != nil {
|
|
newErr := &GenericOpenAPIError{
|
|
body: localVarBody,
|
|
error: err.Error(),
|
|
}
|
|
return localVarReturnValue, localVarHTTPResponse, newErr
|
|
}
|
|
|
|
return localVarReturnValue, localVarHTTPResponse, nil
|
|
}
|