anthropic

package
v1.0.21 Latest Latest
Warning

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

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

Documentation

Overview

Package anthropic is a thin wrapper around the official Anthropic SDK (github.com/anthropics/anthropic-sdk-go), used to validate a user-supplied API key (via ListModels, a zero-token metadata call) and to run single-turn, non-streaming completions (via Complete) for the tract engine's "Call LLM" step.

No streaming, no tool use, no multi-turn conversation — deliberately out of scope for this first pass. See docs/byok/04_tract_llm_step.md for the full design rationale.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StatusCode

func StatusCode(err error) (code int, ok bool)

StatusCode extracts the HTTP status code from an error returned by this client, when the error originated from an actual API response (as opposed to a network-level failure like a timeout or DNS error, which the SDK does not wrap in *sdk.Error). ok is false for those network-level cases.

Types

type Client

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

Client wraps the Anthropic SDK client with the narrow surface the connection service and tract engine actually need.

func New

func New(apiKey, baseUrl string) *Client

New constructs a Client authenticated with apiKey. If baseUrl is non-empty, it overrides the SDK's default API host (e.g. for a proxy or regional endpoint).

func (*Client) Complete

func (c *Client) Complete(ctx context.Context, req CompleteRequest) (CompleteResult, error)

Complete performs a single-turn, non-streaming call to the Messages API.

func (*Client) ListModels

func (c *Client) ListModels(ctx context.Context) ([]ModelInfo, error)

ListModels wraps the SDK's models-list call (GET /v1/models). It is a metadata endpoint — no beta header, zero tokens billed — so it doubles as the key-validation call: an auth failure surfaces here as an error before any completion is ever attempted.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context, model string) error

Ping confirms apiKey authenticates and model is usable by sending the cheapest possible completion request, discarding the reply. It exists as a fallback key-validation path for providers whose Anthropic-compatible endpoint doesn't implement GET /v1/models (ListModels) — common for third-party proxies that only mirror the Messages API surface.

type CompleteRequest

type CompleteRequest struct {
	Model        string
	SystemPrompt string
	Prompt       string
	MaxTokens    int64
}

CompleteRequest is a single-turn, non-streaming completion request: one user message (Prompt), an optional SystemPrompt, and a model. No tool use, no thinking, no history.

type CompleteResult

type CompleteResult struct {
	Text  string
	Usage Usage
}

CompleteResult is the text of the model's reply plus its token usage.

type ModelInfo

type ModelInfo struct {
	Id             string
	DisplayName    string
	MaxInputTokens int64
	MaxTokens      int64
}

ModelInfo is the subset of the Models-List response fields relevant to Artel: a model catalog entry used both to confirm a key is valid and to populate a connection's available-models cache / the Call LLM step's model picker.

type Usage

type Usage struct {
	InputTokens              int64
	OutputTokens             int64
	CacheCreationInputTokens int64
	CacheReadInputTokens     int64
}

Usage mirrors the Messages API response's usage object.

Jump to

Keyboard shortcuts

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