Skip to main content

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

package main

import(
	"context"
	"os"
	openrouter "github.com/OpenRouterTeam/go-sdk"
	"log"
)

func main() {
    ctx := context.Background()

    s := openrouter.New(
        openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
    )

    res, err := s.Beta.Analytics.GetAnalyticsMeta(ctx)
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        // handle response
    }
}

Parameters

ParameterTypeRequiredDescription
ctxcontext.Context:heavy_check_mark:The context to use for the request.
opts[]operations.Option:heavy_minus_sign:The 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

package main

import(
	"context"
	"os"
	openrouter "github.com/OpenRouterTeam/go-sdk"
	"github.com/OpenRouterTeam/go-sdk/types"
	"github.com/OpenRouterTeam/go-sdk/models/operations"
	"log"
)

func main() {
    ctx := context.Background()

    s := openrouter.New(
        openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
    )

    res, err := s.Beta.Analytics.QueryAnalytics(ctx, operations.QueryAnalyticsRequest{
        Dimensions: []string{
            "model",
        },
        Granularity: openrouter.Pointer("day"),
        Limit: openrouter.Pointer[int64](100),
        Metrics: []string{
            "request_count",
        },
        TimeRange: &operations.TimeRange{
            End: types.MustTimeFromString("2025-01-08T00:00:00Z"),
            Start: types.MustTimeFromString("2025-01-01T00:00:00Z"),
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        // handle response
    }
}

Parameters

ParameterTypeRequiredDescription
ctxcontext.Context:heavy_check_mark:The context to use for the request.
requestoperations.QueryAnalyticsRequest:heavy_check_mark:The request object to use for the request.
opts[]operations.Option:heavy_minus_sign:The 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*/*