opencodego

package
v0.0.259 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package opencodego reads OpenCode Go subscription usage over HTTP.

Index

Constants

View Source
const (
	// DefaultBaseURL is the Go inference root. Usage is GET {base}/v1/usage.
	DefaultBaseURL = "https://opencode.ai/inference/go"
	// PathUsage is the usage meter path on DefaultBaseURL.
	PathUsage = "/v1/usage"
	// DefaultTokenFile is the plaintext API key llm-proxy also reads.
	DefaultTokenFile = "~/tmp/llm-token-opencode-go.txt"
	// UserAgent identifies this client; OpenCode rejects generic SDK names.
	UserAgent = "agent-pro-opencode-go/1.0"
)

Variables

This section is empty.

Functions

func ResolveTokenFile

func ResolveTokenFile(path string) (string, error)

ResolveTokenFile expands ~ and empty to DefaultTokenFile.

Types

type FetchOpts

type FetchOpts struct {
	// TokenFile is a plaintext file holding the Go API key. Empty uses
	// DefaultTokenFile. A nonempty Token skips the file.
	TokenFile string
	// Token is the Go API key. When set, TokenFile is not read.
	Token string
	// BaseURL overrides DefaultBaseURL (tests). Trailing slashes are stripped.
	BaseURL string
	// HTTP is the client; nil uses a 30s timeout client.
	HTTP *http.Client
}

FetchOpts configures one usage GET.

type Meter

type Meter struct {
	Status   string `json:"status"`
	Percent  int    `json:"percent"`
	ResetsAt string `json:"resetsAt"`
}

Meter is one Go limit window.

func (Meter) ResetTime

func (m Meter) ResetTime() time.Time

ResetTime parses ResetsAt. Zero means the API omitted a usable instant.

type Usage

type Usage struct {
	Rolling Meter `json:"rolling"`
	Weekly  Meter `json:"weekly"`
	Monthly Meter `json:"monthly"`
}

Usage is the shared Go allowance as three meters. Paid models share this pool; the API does not report remaining usage per model.

func Fetch

func Fetch(ctx context.Context, opts FetchOpts) (*Usage, error)

Fetch GETs the Go usage meters with the given key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL