Analytics - Go SDK

Analytics method reference

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

Overview

Analytics and usage endpoints

Available Operations

GetUserActivity

Returns user activity data grouped by endpoint for the last 30 (completed) UTC days. 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.Analytics.GetUserActivity(ctx, nil, nil, nil)
18 if err != nil {
19 log.Fatal(err)
20 }
21 if res != nil {
22 // handle response
23 }
24}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context✔️The context to use for the request.
date*stringFilter by a single UTC date in the last 30 days (YYYY-MM-DD format).2025-08-24
apiKeyHash*stringFilter by API key hash (SHA-256 hex string, as returned by the keys API).abc123def456…
userID*stringFilter by org member user ID. Only applicable for organization accounts.user_abc123
opts[]operations.OptionThe options for this request.

Response

*components.ActivityResponse, error

Errors

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