tokenhub

package
v0.2.0-beta.9 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package tokenhub contains the provider-neutral configuration contract for TokenHub-compatible gateways. Transport and request conversion stay in the existing OpenAI/Anthropic adaptors until a channel is explicitly selected; this package deliberately does not read local credentials or log secrets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeBaseURL

func NormalizeBaseURL(raw string) (string, error)

NormalizeBaseURL validates and canonicalizes a configured gateway endpoint. Only HTTP(S) URLs with a host are accepted; credentials and query strings are rejected so an accidental secret cannot be embedded in the endpoint.

Types

type Client

type Client struct {
	Config Config
	// contains filtered or unexported fields
}

Client provides bounded, secret-safe probes for an explicitly configured TokenHub endpoint. Routing and billing stay in MyAPI's existing services.

func NewClient

func NewClient(config Config, apiKey string, httpClient *http.Client) Client

NewClient creates a probe client. The credential is kept private so a caller cannot accidentally serialize or print it as part of Client state.

func (Client) Health

func (c Client) Health(ctx context.Context) HealthSnapshot

func (Client) Models

func (c Client) Models(ctx context.Context) ([]Model, error)

type Config

type Config struct {
	BaseURL             string
	Region              string
	Protocol            Protocol
	ModelListPath       string
	HealthPath          string
	AllowModelDiscovery bool
	ModelAliases        map[string]string
}

Config is the stable boundary between MyAPI routing policy and a TokenHub upstream. APIKey is held by the caller and is never included in errors or String methods.

func FromSettings

func FromSettings(settings *dto.TokenHubSettings) (Config, error)

FromSettings converts persisted channel settings into a validated runtime config. It does not inspect or copy the channel credential.

func (Config) Endpoint

func (c Config) Endpoint(requestPath string) (string, error)

func (Config) ResolveModel

func (c Config) ResolveModel(model string) string

ResolveModel applies an optional administrative alias without changing the caller's model string when no alias is configured.

func (Config) Validate

func (c Config) Validate() error

type HealthSnapshot

type HealthSnapshot struct {
	Healthy      bool
	StatusCode   int
	Latency      time.Duration
	CheckedAt    time.Time
	FailureCause string
}

type Model

type Model struct {
	ID      string `json:"id"`
	OwnedBy string `json:"owned_by,omitempty"`
}

Model is the provider-neutral subset used by model discovery and UI metadata. Unknown fields are intentionally ignored for compatibility.

type Protocol

type Protocol string
const (
	ProtocolOpenAI    Protocol = "openai"
	ProtocolResponses Protocol = "responses"
	ProtocolAnthropic Protocol = "anthropic"
)

Jump to

Keyboard shortcuts

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