Beta.Analytics - Go SDK

Beta.Analytics method reference

The Go SDK and docs are currently in beta. Report issues on GitHub.

Overview

beta.Analytics endpoints

Available Operations

GetAnalyticsMeta

Returns the available metrics, dimensions, filter operators, and granularities for the analytics query endpoint. Management key required.

Example Usage

1package main
2
3import(
4 "context"
5 "os"
6 openrouter "github.com/OpenRouterTeam/go-sdk"
7 "log"
8)
9
10func main() {
11 ctx := context.Background()
12
13 s := openrouter.New(
14 openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
15 )
16
17 res, err := s.Beta.Analytics.GetAnalyticsMeta(ctx)
18 if err != nil {
19 log.Fatal(err)
20 }
21 if res != nil {
22 // handle response
23 }
24}

Parameters

ParameterTypeRequiredDescription
ctxcontext.Context✔️The context to use for the request.
opts[]operations.OptionThe options for this request.

Response

*operations.GetAnalyticsMetaResponse, error

Errors

Error TypeStatus CodeContent Type
sdkerrors.UnauthorizedResponseError401application/json
sdkerrors.ForbiddenResponseError403application/json
sdkerrors.InternalServerResponseError500application/json
sdkerrors.APIError4XX, 5XX*/*

QueryAnalytics

Execute an analytics query with specified metrics, dimensions, filters, and time range. Management key required.

Example Usage

1package main
2
3import(
4 "context"
5 "os"
6 openrouter "github.com/OpenRouterTeam/go-sdk"
7 "github.com/OpenRouterTeam/go-sdk/types"
8 "github.com/OpenRouterTeam/go-sdk/models/operations"
9 "log"
10)
11
12func main() {
13 ctx := context.Background()
14
15 s := openrouter.New(
16 openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
17 )
18
19 res, err := s.Beta.Analytics.QueryAnalytics(ctx, operations.QueryAnalyticsRequest{
20 Dimensions: []string{
21 "model",
22 },
23 Granularity: openrouter.Pointer("day"),
24 Limit: openrouter.Pointer[int64](100),
25 Metrics: []string{
26 "request_count",
27 },
28 TimeRange: &operations.TimeRange{
29 End: types.MustTimeFromString("2025-01-08T00:00:00Z"),
30 Start: types.MustTimeFromString("2025-01-01T00:00:00Z"),
31 },
32 })
33 if err != nil {
34 log.Fatal(err)
35 }
36 if res != nil {
37 // handle response
38 }
39}

Parameters

ParameterTypeRequiredDescription
ctxcontext.Context✔️The context to use for the request.
requestoperations.QueryAnalyticsRequest✔️The request object to use for the request.
opts[]operations.OptionThe options for this request.

Response

*operations.QueryAnalyticsResponse, error

Errors

Error TypeStatus CodeContent Type
sdkerrors.BadRequestResponseError400application/json
sdkerrors.UnauthorizedResponseError401application/json
sdkerrors.ForbiddenResponseError403application/json
sdkerrors.RequestTimeoutResponseError408application/json
sdkerrors.InternalServerResponseError500application/json
sdkerrors.APIError4XX, 5XX*/*