sdk

module
v0.7.28 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: Apache-2.0

README

Wyolet Relay Go SDK

github.com/wyolet/relay/sdk is the Go client for Wyolet Relay. You build one canonical request and send it through a relay or straight to a provider. The module also holds relay's canonical protocol, the vendor translators and the public model catalog, so you can use it without running a relay.

go get github.com/wyolet/relay/sdk@latest

Requires Go 1.27 or later.

Modes

client.ForMode picks where a call goes:

Mode The call goes to Relay records it
proxy Relay, with your relay key yes, as a routed request
telemetry the provider, with your provider key yes, reported over OTLP with your relay key
direct the provider, with your provider key no

The mode comes from client.WithMode, then WR_MODE. Without either, the client uses proxy when WR_BASE_URL and WR_API_KEY are set and direct otherwise. Telemetry is never chosen by default. In telemetry and direct mode, the model reference is resolved against the catalog embedded in the SDK, and the provider key is read from OPENAI_API_KEY, ANTHROPIC_API_KEY or GEMINI_API_KEY.

c, err := client.ForMode("gpt-4o")
if err != nil {
	log.Fatal(err)
}
defer c.Close() // in telemetry mode, sends the calls still queued

resp, err := c.Generate(ctx, &v1.Request{
	Input: []v1.Item{&v1.Message{Role: v1.RoleUser, Content: []v1.Part{&v1.TextPart{Text: "Hello"}}}},
})
if err != nil {
	log.Fatal(err)
}
if cost, ok := resp.Cost(); ok { // priced from the catalog; not set in proxy mode
	fmt.Printf("cost: $%.6f\n", cost)
}

In telemetry and direct mode, Models and Catalog read the latest release from https://catalog.wyolet.com. Set WR_CATALOG_URL to use another catalog server, or to off to use only the embedded catalog.

Packages

Package Contents
client ForMode, Relay, RelayWS, For, and explicit OpenAI / Anthropic / Gemini constructors; Generate, GenerateStream, Cost
v1 the canonical request, response and stream event types, and the Translator interface
adapters/openai, adapters/anthropic, adapters/gemini translators between each vendor's wire shapes and v1
catalog, catalogsource the embedded catalog, model reference resolution, per-binding cost; loading newer catalog releases
telemetry the OTLP emitter used by telemetry mode (OpenTelemetry GenAI conventions)
provider, host, model read-only catalog discovery views

Stability

The SDK is v0: its API may change between minor versions. Releases are tagged sdk/vX.Y.Z in the relay repository.

The module imports nothing from the relay server module, so it can be vendored on its own.

Documentation

Directories

Path Synopsis
adapters
anthropic
Package anthropic translates the Anthropic Messages wire shape to and from the canonical v1 protocol.
Package anthropic translates the Anthropic Messages wire shape to and from the canonical v1 protocol.
gemini
Package gemini implements v1.Translator for the Google Gemini generateContent / streamGenerateContent wire shape (v1beta).
Package gemini implements v1.Translator for the Google Gemini generateContent / streamGenerateContent wire shape (v1beta).
openai
Package openai translates the OpenAI Chat Completions and Responses wire shapes to and from the canonical v1 protocol.
Package openai translates the OpenAI Chat Completions and Responses wire shapes to and from the canonical v1 protocol.
Package catalog is the pure SDK view of the public relay catalog: embedded host/bindings/pricing data plus model-ref resolution and per-binding cost.
Package catalog is the pure SDK view of the public relay catalog: embedded host/bindings/pricing data plus model-ref resolution and per-binding cost.
Package catalogsource yields a full *catalog.IndexedCatalog from one of four places: the catalog embedded in this SDK version, a local catalog file, a relay-catalog release asset fetched by tag and cached on disk (Release), or the newest release of this SDK's schema channel, refreshed periodically with labelled fallbacks (Latest).
Package catalogsource yields a full *catalog.IndexedCatalog from one of four places: the catalog embedded in this SDK version, a local catalog file, a relay-catalog release asset fetched by tag and cached on disk (Release), or the newest release of this SDK's schema channel, refreshed periodically with labelled fallbacks (Latest).
Package client is a thin Go client that speaks the relay canonical shape (sdk/v1).
Package client is a thin Go client that speaks the relay canonical shape (sdk/v1).
Package host is the public, read-only discovery view of a serving endpoint: its base URL, display metadata, and the slugs of the models it serves.
Package host is the public, read-only discovery view of a serving endpoint: its base URL, display metadata, and the slugs of the models it serves.
internal
atomicfile
Package atomicfile replaces a file in one rename so a concurrent reader sees either the old bytes or the new ones, never a partial write.
Package atomicfile replaces a file in one rename so a concurrent reader sees either the old bytes or the new ones, never a partial write.
catalogpick
Package catalogpick holds the rule for which host's binding stands for a model when the caller names no host, shared by modeldir (the rate sheet a file carries) and modelroutes (routes that leave host selection to a relay).
Package catalogpick holds the rule for which host's binding stands for a model when the caller names no host, shared by modeldir (the rate sheet a file carries) and modelroutes (routes that leave host selection to a relay).
dataurl
Package dataurl reads RFC 2397 data: URLs for the vendor adapters whose wire takes inline media only as a media type plus base64 data.
Package dataurl reads RFC 2397 data: URLs for the vendor adapters whose wire takes inline media only as a media type plus base64 data.
fidelity
Package fidelity is test support for vendor adapters: it builds a canonical request with every request-level field set to a distinctive value, and checks a serialized body either carries each field or names it in an explicit drop list.
Package fidelity is test support for vendor adapters: it builds a canonical request with every request-level field set to a distinctive value, and checks a serialized body either carries each field or names it in an explicit drop list.
graph
Package graph is the SDK's internal catalog-discovery graph: a denormalized, cross-linked view of the embedded catalog (models, the hosts that serve them, and the providers that author them) built once from sdk/catalog.
Package graph is the SDK's internal catalog-discovery graph: a denormalized, cross-linked view of the embedded catalog (models, the hosts that serve them, and the providers that author them) built once from sdk/catalog.
jsonscan
Package jsonscan walks the members of a JSON object and the elements of a JSON array in raw bytes without decoding them, for the vendor adapters' per-frame checks on stream hot paths.
Package jsonscan walks the members of a JSON object and the elements of a JSON array in raw bytes without decoding them, for the vendor adapters' per-frame checks on stream hot paths.
sse
Package sse splits server-sent-event bytes into events per the WHATWG event-stream rules, for the vendor adapters' to-canonical stream parsers and usage walkers: events end at a blank line, an event's data is its data lines joined with "\n", lines end in LF, CRLF or CR, and comments and unknown fields are ignored.
Package sse splits server-sent-event bytes into events per the WHATWG event-stream rules, for the vendor adapters' to-canonical stream parsers and usage walkers: events end at a blank line, an event's data is its data lines joined with "\n", lines end in LF, CRLF or CR, and comments and unknown fields are ignored.
Package model is the public, read-only discovery view of a catalogued model: its identity, capabilities, the provider that authored it, and the hosts that serve it.
Package model is the public, read-only discovery view of a catalogued model: its identity, capabilities, the provider that authored it, and the hosts that serve it.
Package modeldir keeps a consumer's model list as a directory of YAML files, one self-contained file per model, and loads that directory as a *catalog.IndexedCatalog so Resolve, Cost and the context-window fields work unchanged.
Package modeldir keeps a consumer's model list as a directory of YAML files, one self-contained file per model, and loads that directory as a *catalog.IndexedCatalog so Resolve, Cost and the context-window fields work unchanged.
Package modelroutes reads and edits a model-routes file: one TOML file listing the models a consumer's picker shows, in order, and the route each one takes (a catalog host, a base URL, an auth hint, an adapter override, an account and a label).
Package modelroutes reads and edits a model-routes file: one TOML file listing the models a consumer's picker shows, in order, and the route each one takes (a catalog host, a base URL, an auth hint, an adapter override, an account and a label).
Package oauth provides minimal, vendor-neutral OAuth 2.0 flow helpers for acquiring and refreshing provider credentials.
Package oauth provides minimal, vendor-neutral OAuth 2.0 flow helpers for acquiring and refreshing provider credentials.
Package provider is the public, read-only discovery view of a model author (the vendor): its display metadata and the slugs of the models it authors.
Package provider is the public, read-only discovery view of a model author (the vendor): its display metadata and the slugs of the models it authors.
Package telemetry reports model calls made directly to a provider to an OTLP/HTTP endpoint, relay's receiver or any other backend, in the OpenTelemetry GenAI semantic conventions.
Package telemetry reports model calls made directly to a provider to an OTLP/HTTP endpoint, relay's receiver or any other backend, in the OpenTelemetry GenAI semantic conventions.
Package usage holds the pure wire shapes for usage reporting, token counts and upstream timing, shared by the public client and the server's usage records.
Package usage holds the pure wire shapes for usage reporting, token counts and upstream timing, shared by the public client and the server's usage records.
Package v1 defines the relay's canonical protocol — the wire-neutral internal representation that all vendor adapters translate to and from.
Package v1 defines the relay's canonical protocol — the wire-neutral internal representation that all vendor adapters translate to and from.
Package wirerules is the table of upstreams that read the Chat Completions shape differently from OpenAI's definition, and the v1.WireRules each one needs, looked up by catalog host name or by the host part of a base URL.
Package wirerules is the table of upstreams that read the Chat Completions shape differently from OpenAI's definition, and the v1.WireRules each one needs, looked up by catalog host name or by the host part of a base URL.

Jump to

Keyboard shortcuts

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