octoryn

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

README

Octoryn Go SDK

Governed model access for Go 1.23+.

go get github.com/octoryn/octoryn-go@v0.1.1
client, err := octoryn.NewClient(os.Getenv("OCTORYN_API_KEY"))
result, err := client.GenerateText(ctx, octoryn.GenerateTextParams{
    Model:  "policy/au-enterprise",
    Prompt: "Explain this routing decision.",
})
fmt.Println(result.Text, result.Octoryn.EvidenceHash)

StreamText exposes replayable iterators, typed tool-call payloads, usage and governance metadata. GenerateObject sends strict JSON Schema and decodes the validated result into a Go type.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Status     int
	Code       string
	Type       string
	Message    string
	RequestID  string
	RetryAfter string
}

func (*APIError) Error

func (e *APIError) Error() string

type AuditTimestamp

type AuditTimestamp = time.Time

type ChatCompletion

type ChatCompletion struct {
	ID      string   `json:"id"`
	Object  string   `json:"object"`
	Created int64    `json:"created"`
	Model   string   `json:"model"`
	Choices []Choice `json:"choices"`
	Usage   *Usage   `json:"usage,omitempty"`
}

type Choice

type Choice struct {
	Index        int     `json:"index"`
	Message      Message `json:"message"`
	FinishReason string  `json:"finish_reason"`
}

type Client

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

func NewClient

func NewClient(apiKey string, options ...Option) (*Client, error)

func (*Client) GenerateObject

func (client *Client) GenerateObject(
	ctx context.Context,
	params GenerateObjectParams,
	target any,
) (TextResult, error)

func (*Client) GenerateText

func (client *Client) GenerateText(
	ctx context.Context,
	params GenerateTextParams,
) (TextResult, error)

func (*Client) StreamText

func (client *Client) StreamText(
	ctx context.Context,
	params GenerateTextParams,
) (*TextStream, error)

type FunctionCall

type FunctionCall struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
}

type FunctionDefinition

type FunctionDefinition struct {
	Name        string         `json:"name"`
	Description string         `json:"description,omitempty"`
	Parameters  map[string]any `json:"parameters"`
}

type GenerateObjectParams

type GenerateObjectParams struct {
	GenerateTextParams
	Schema            map[string]any
	SchemaName        string
	SchemaDescription string
}

type GenerateTextParams

type GenerateTextParams struct {
	Model           string
	Prompt          string
	Messages        []Message
	System          string
	Tools           []ToolDefinition
	ToolChoice      any
	Temperature     *float64
	TopP            *float64
	MaxOutputTokens *int
	Metadata        map[string]string
}

type GovernanceMetadata

type GovernanceMetadata struct {
	RunID          string   `json:"run_id,omitempty"`
	Upstream       string   `json:"upstream,omitempty"`
	BYOK           string   `json:"byok,omitempty"`
	Region         string   `json:"region,omitempty"`
	Route          string   `json:"route,omitempty"`
	PolicyDecision string   `json:"policy_decision,omitempty"`
	EvidenceHash   string   `json:"evidence_hash,omitempty"`
	EstimatedCost  *float64 `json:"estimated_cost,omitempty"`
}

type Message

type Message struct {
	Role       string     `json:"role"`
	Content    any        `json:"content"`
	Name       string     `json:"name,omitempty"`
	ToolCallID string     `json:"tool_call_id,omitempty"`
	ToolCalls  []ToolCall `json:"tool_calls,omitempty"`
}

type ObjectResult

type ObjectResult[T any] struct {
	Object T
	TextResult
}

func GenerateObject

func GenerateObject[T any](
	ctx context.Context,
	client *Client,
	params GenerateObjectParams,
) (ObjectResult[T], error)

type Option

type Option func(*Client)

func WithBaseURL

func WithBaseURL(baseURL string) Option

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

func WithHeader

func WithHeader(name, value string) Option

type StreamEvent

type StreamEvent struct {
	Type         string
	Text         string
	ToolCall     *ToolCall
	Usage        *Usage
	FinishReason string
	Octoryn      GovernanceMetadata
	Provider     json.RawMessage
	Err          error
}

type StreamIterator

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

func (*StreamIterator) Err

func (iterator *StreamIterator) Err() error

func (*StreamIterator) Event

func (iterator *StreamIterator) Event() StreamEvent

func (*StreamIterator) Next

func (iterator *StreamIterator) Next(ctx context.Context) bool

type TextResult

type TextResult struct {
	Text         string
	ToolCalls    []ToolCall
	FinishReason string
	Usage        *Usage
	Octoryn      GovernanceMetadata
	Response     ChatCompletion
}

type TextStream

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

func (*TextStream) Iterator

func (stream *TextStream) Iterator() *StreamIterator

func (*TextStream) Result

func (stream *TextStream) Result(ctx context.Context) (TextResult, error)

type ToolCall

type ToolCall struct {
	ID       string       `json:"id"`
	Type     string       `json:"type"`
	Function FunctionCall `json:"function"`
}

func (ToolCall) DecodeInput

func (call ToolCall) DecodeInput(target any) error

type ToolDefinition

type ToolDefinition struct {
	Type     string             `json:"type"`
	Function FunctionDefinition `json:"function"`
}

func Tool

func Tool(name, description string, schema map[string]any) ToolDefinition

type Usage

type Usage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

Jump to

Keyboard shortcuts

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