openai

package
v1.0.13 Latest Latest
Warning

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

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

Documentation

Overview

Package openai is a thin wrapper around the official OpenAI SDK (github.com/openai/openai-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 OpenAI 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, regional endpoint, or OpenAI-compatible provider).

func (*Client) Complete

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

Complete performs a single-turn, non-streaming call to the Chat Completions 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 completion 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 OpenAI-compatible endpoint doesn't implement GET /v1/models (ListModels) — common for third-party proxies that only mirror the Chat Completions 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
	OwnedBy string
}

ModelInfo is the subset of the Models-List response fields relevant to Artel. It is intentionally thinner than Anthropic's ModelInfo: OpenAI's GET /v1/models response only carries an id and an owning org — no display name or token-limit metadata is returned.

type Usage

type Usage struct {
	InputTokens  int64
	OutputTokens int64
}

Usage mirrors the Chat Completions API response's usage object. Unlike Anthropic's Usage, there are no cache-related fields: OpenAI's prompt-caching accounting (prompt_tokens_details.cached_tokens) has no analogue in this narrow wrapper and is intentionally left unmapped.

Jump to

Keyboard shortcuts

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