meshapi

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 13 Imported by: 0

README

meshapi-go-sdk

Go client for the MeshAPI AI model gateway.

Requirements

  • Go ≥ 1.21
  • Zero external dependencies

Installation

go get meshapi-go-sdk  # local module
# or after publishing:
go get github.com/yourorg/meshapi-go-sdk@v0.1.0

Quick Start

import "meshapi-go-sdk"

client := meshapi.New(meshapi.Config{
    BaseURL: "http://localhost:8000",
    Token:   "rsk_...",
})

// Non-streaming
model := "openai/gpt-4o-mini"
resp, err := client.Chat.Completions.Create(ctx, meshapi.ChatCompletionParams{
    Model:    &model,
    Messages: []meshapi.ChatMessage{{Role: "user", Content: "What is 2+2?"}},
})

// Streaming
chunkCh, errCh := client.Chat.Completions.Stream(ctx, params)
for chunk := range chunkCh {
    if len(chunk.Choices) > 0 && chunk.Choices[0].Delta != nil {
        fmt.Print(*chunk.Choices[0].Delta.Content)
    }
}
if err := <-errCh; err != nil {
    log.Fatal(err)
}

// Models
models, _ := client.Models.List(ctx, meshapi.ListModelsParams{})
free, _   := client.Models.Free(ctx)

// Templates
tmpl, _ := client.Templates.Create(ctx, meshapi.CreateTemplateParams{Name: "my-tpl"})
client.Templates.Delete(ctx, tmpl.ID)

// Responses (Reasoning)
respModel := "openai/o3-mini"
resp, _ := client.Responses.Create(ctx, meshapi.ResponsesParams{
    Model: &respModel,
    Input: "Solve for X: 2x + 5 = 15",
})

// Embeddings
embModel := "openai/text-embedding-3-small"
emb, _ := client.Embeddings.Create(ctx, meshapi.EmbeddingsParams{
    Model: &embModel,
    Input: []string{"The quick brown fox"},
})

// Image Generation
imgModel := "openai/gpt-image-1"
imgSize := "1024x1024"
imgQuality := "high"
imgOutputFormat := "webp"
imgN := 1
img, _ := client.Images.Generate(ctx, meshapi.ImageGenerationParams{
    Model:        &imgModel,
    Prompt:       "A watercolor of a fox in a snowy forest",
    N:            &imgN,
    Size:         &imgSize,
    Quality:      &imgQuality,
    OutputFormat: &imgOutputFormat,
})

// Image Generation — streaming
chunkCh, imgErrCh := client.Images.Stream(ctx, meshapi.ImageGenerationParams{
    Model:        &imgModel,
    Prompt:       "A watercolor of a fox in a snowy forest",
    N:            &imgN,
    Size:         &imgSize,
    Quality:      &imgQuality,
    OutputFormat: &imgOutputFormat,
})
for chunk := range chunkCh {
    if chunk.Status != nil && *chunk.Status == "processing" {
        fmt.Println("Generating...")
    } else if len(chunk.Data) > 0 && chunk.Data[0].URL != nil {
        fmt.Println("Done:", *chunk.Data[0].URL)
    }
}
if err := <-imgErrCh; err != nil {
    log.Fatal(err)
}

// Compare (Multi-model)
compCh, errCh := client.Compare.Stream(ctx, meshapi.CompareParams{
    Models: []string{"openai/gpt-4o-mini", "anthropic/claude-3-haiku"},
    Messages: []meshapi.ChatMessage{{Role: "user", Content: "Hello"}},
})
for range compCh {
}
if err := <-errCh; err != nil {
    log.Fatal(err)
}

// Files & Batches
file, _ := client.Files.Upload(ctx, meshapi.UploadBatchFileParams{
    Purpose: "batch",
    Requests: []meshapi.BatchRequestItem{
        {
            CustomID: "req-1",
            Body: map[string]interface{}{
                "model": "openai/gpt-4o-mini",
                "messages": []map[string]interface{}{{"role": "user", "content": "Hello"}},
            },
        },
    },
})
batch, _ := client.Batches.Create(ctx, meshapi.CreateBatchParams{
    InputFileID:      file.ID,
    Endpoint:         "/v1/chat/completions",
    CompletionWindow: "24h",
})

Error Handling

resp, err := client.Chat.Completions.Create(ctx, params)
if err != nil {
    var svcErr *meshapi.MeshAPIError
    if errors.As(err, &svcErr) {
        fmt.Println(svcErr.Status)     // HTTP status
        fmt.Println(svcErr.Code)       // "unauthorized", "rate_limit_exceeded", etc.
        fmt.Println(svcErr.RequestID)  // req_<ULID>
    }
}

Retry / Backoff

Retries on 429/502/503/504 with exponential backoff (default 3 retries, 500 ms base, 30 s max, ±20% jitter). Respects Retry-After header.

maxRetries := 5
client := meshapi.New(meshapi.Config{
    MaxRetries: &maxRetries,
})

Streaming Failure Recovery

Streams do not retry. On connection failure, the error channel receives a MeshAPIError with Code="stream_interrupted". Restart a new Stream call to reconnect.

Running Tests

# Unit + contract tests
go test ./...

# Integration tests (requires localhost:8000)
MESHAPI_BASE_URL=http://localhost:8000 \
MESHAPI_TOKEN=rsk_... \
go test -tags integration ./...

Versioning

fmt.Println(meshapi.Version)  // "0.1.0"

Documentation

Overview

Package meshapi is a Go client for the MeshAPI AI model gateway.

Quick start

client := meshapi.NewClient(meshapi.Config{
    BaseURL: "http://localhost:8000",
    Token:   "rsk_...",
})

model := "openai/gpt-4o-mini"
resp, err := client.Chat.Completions.Create(ctx, meshapi.ChatCompletionParams{
    Model:    &model,
    Messages: []meshapi.ChatMessage{{Role: "user", Content: "Hello!"}},
})

Package meshapi provides a typed Go client for the MeshAPI AI model gateway.

Index

Constants

View Source
const Version = "0.1.0"

Version is the current SDK version.

Variables

This section is empty.

Functions

This section is empty.

Types

type AudioOutputOptions added in v0.1.3

type AudioOutputOptions struct {
	Voice  *string `json:"voice,omitempty"`
	Format *string `json:"format,omitempty"`
}

type BatchListResponse added in v0.1.3

type BatchListResponse struct {
	Object  string        `json:"object"`
	Data    []BatchObject `json:"data"`
	HasMore bool          `json:"has_more"`
	FirstID *string       `json:"first_id,omitempty"`
	LastID  *string       `json:"last_id,omitempty"`
}

type BatchObject added in v0.1.3

type BatchObject struct {
	ID           string  `json:"id"`
	Object       *string `json:"object,omitempty"`
	Endpoint     *string `json:"endpoint,omitempty"`
	InputFileID  *string `json:"input_file_id,omitempty"`
	OutputFileID *string `json:"output_file_id,omitempty"`
	Status       *string `json:"status,omitempty"`
	Model        *string `json:"model,omitempty"`
	Provider     *string `json:"provider,omitempty"`
	CreatedAt    *int64  `json:"created_at,omitempty"`
	CompletedAt  *int64  `json:"completed_at,omitempty"`
	UsageSynced  *bool   `json:"usage_synced,omitempty"`
}

type BatchRequestItem added in v0.1.3

type BatchRequestItem struct {
	CustomID string                 `json:"custom_id"`
	Method   string                 `json:"method,omitempty"`
	URL      string                 `json:"url,omitempty"`
	Body     map[string]interface{} `json:"body"`
}

type BatchesResource added in v0.1.3

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

func (*BatchesResource) Cancel added in v0.1.3

func (r *BatchesResource) Cancel(ctx context.Context, batchID string) (*BatchObject, error)

func (*BatchesResource) Create added in v0.1.3

func (*BatchesResource) Get added in v0.1.3

func (r *BatchesResource) Get(ctx context.Context, batchID string) (*BatchObject, error)

func (*BatchesResource) List added in v0.1.3

func (r *BatchesResource) List(ctx context.Context, after *string, limit *int) (*BatchListResponse, error)

type BuiltinTool added in v0.1.3

type BuiltinTool struct {
	Type string `json:"type"`
}

type ChatCompletionChoice

type ChatCompletionChoice struct {
	Index        int                    `json:"index"`
	Message      *ChatCompletionMessage `json:"message,omitempty"`
	FinishReason *string                `json:"finish_reason,omitempty"`
	Logprobs     interface{}            `json:"logprobs,omitempty"`
}

ChatCompletionChoice is one result choice in a non-streaming response.

type ChatCompletionChunk

type ChatCompletionChunk struct {
	ID      string                      `json:"id"`
	Object  string                      `json:"object"`
	Created int64                       `json:"created"`
	Model   string                      `json:"model"`
	Choices []ChatCompletionChunkChoice `json:"choices"`
	Usage   *UsageInfo                  `json:"usage,omitempty"`
	Cost    *string                     `json:"cost,omitempty"`
}

ChatCompletionChunk is a single SSE chunk in a streaming completion.

type ChatCompletionChunkChoice

type ChatCompletionChunkChoice struct {
	Index        int                       `json:"index"`
	Delta        *ChatCompletionChunkDelta `json:"delta,omitempty"`
	FinishReason *string                   `json:"finish_reason,omitempty"`
}

ChatCompletionChunkChoice is one choice in a streaming chunk.

type ChatCompletionChunkDelta

type ChatCompletionChunkDelta struct {
	Role      *string                `json:"role,omitempty"`
	Content   *string                `json:"content,omitempty"`
	ToolCalls []ToolCall             `json:"tool_calls,omitempty"`
	Audio     map[string]interface{} `json:"audio,omitempty"`
}

ChatCompletionChunkDelta is the partial content in a streaming chunk.

type ChatCompletionMessage

type ChatCompletionMessage struct {
	Role      string                 `json:"role"`
	Content   *string                `json:"content,omitempty"`
	ToolCalls []ToolCall             `json:"tool_calls,omitempty"`
	Audio     map[string]interface{} `json:"audio,omitempty"`
}

ChatCompletionMessage is a completed message in a non-streaming response.

type ChatCompletionParams

type ChatCompletionParams struct {
	Messages         []ChatMessage       `json:"messages"`
	Model            *string             `json:"model,omitempty"`
	Stream           *bool               `json:"stream,omitempty"`
	Template         *string             `json:"template,omitempty"`
	Variables        map[string]string   `json:"variables,omitempty"`
	SessionID        *string             `json:"session_id,omitempty"`
	Temperature      *float64            `json:"temperature,omitempty"`
	MaxTokens        *int                `json:"max_tokens,omitempty"`
	TopP             *float64            `json:"top_p,omitempty"`
	FrequencyPenalty *float64            `json:"frequency_penalty,omitempty"`
	PresencePenalty  *float64            `json:"presence_penalty,omitempty"`
	Stop             interface{}         `json:"stop,omitempty"` // string or []string
	Seed             *int                `json:"seed,omitempty"`
	Tools            []Tool              `json:"tools,omitempty"`
	ToolChoice       interface{}         `json:"tool_choice,omitempty"`
	Transforms       []string            `json:"transforms,omitempty"`
	Models           []string            `json:"models,omitempty"`
	User             *string             `json:"user,omitempty"`
	Modality         *string             `json:"modality,omitempty"`
	Image            *ImageOptions       `json:"image,omitempty"`
	AsyncMode        *bool               `json:"async_mode,omitempty"`
	Modalities       []string            `json:"modalities,omitempty"`
	Audio            *AudioOutputOptions `json:"audio,omitempty"`
}

ChatCompletionParams is the request body for POST /v1/chat/completions.

type ChatCompletionResponse

type ChatCompletionResponse struct {
	ID                string                 `json:"id"`
	Object            string                 `json:"object"`
	Created           int64                  `json:"created"`
	Model             string                 `json:"model"`
	Choices           []ChatCompletionChoice `json:"choices"`
	Usage             *UsageInfo             `json:"usage,omitempty"`
	SystemFingerprint *string                `json:"system_fingerprint,omitempty"`
}

ChatCompletionResponse is the full non-streaming response body.

type ChatMessage

type ChatMessage struct {
	Role       string      `json:"role"`
	Content    interface{} `json:"content,omitempty"` // string or []ContentPart
	Name       *string     `json:"name,omitempty"`
	ToolCallID *string     `json:"tool_call_id,omitempty"`
	ToolCalls  []ToolCall  `json:"tool_calls,omitempty"`
}

ChatMessage represents a single message in the conversation.

type ChatResource

type ChatResource struct {
	Completions *CompletionsResource
}

ChatResource groups chat-related sub-resources.

type Client

type Client struct {
	Chat       *ChatResource
	Responses  *ResponsesResource
	Embeddings *EmbeddingsResource
	Compare    *CompareResource
	Files      *FilesResource
	Batches    *BatchesResource
	Models     *ModelsResource
	Templates  *TemplatesResource
	Images     *ImagesResource
}

Client is the MeshAPI SDK client.

One instance = one auth realm. Use separate instances for different tokens:

inferenceClient := meshapi.New(meshapi.Config{Token: "rsk_..."})
mgmtClient      := meshapi.New(meshapi.Config{Token: "<jwt>"})

func New

func New(cfg Config) *Client

New creates a new MeshAPI client with the given configuration.

type CompareParams added in v0.1.3

type CompareParams struct {
	Models                 []string          `json:"models"`
	Messages               []ChatMessage     `json:"messages"`
	ModelOverrides         []ModelOverride   `json:"model_overrides,omitempty"`
	ComparisonModel        *string           `json:"comparison_model,omitempty"`
	ComparisonInstructions *string           `json:"comparison_instructions,omitempty"`
	Temperature            *float64          `json:"temperature,omitempty"`
	MaxTokens              *int              `json:"max_tokens,omitempty"`
	Stream                 *bool             `json:"stream,omitempty"`
	Template               *string           `json:"template,omitempty"`
	Variables              map[string]string `json:"variables,omitempty"`
	SkipComparison         *bool             `json:"skip_comparison,omitempty"`
}

type CompareResource added in v0.1.3

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

func (*CompareResource) Create added in v0.1.3

func (*CompareResource) Stream added in v0.1.3

func (r *CompareResource) Stream(ctx context.Context, params CompareParams) (<-chan CompareStreamEvent, <-chan error)

type CompareResponse added in v0.1.3

type CompareResponse struct {
	ComparisonID           string               `json:"comparison_id"`
	Object                 string               `json:"object"`
	Created                int64                `json:"created"`
	Models                 []string             `json:"models"`
	Results                []ModelCompareResult `json:"results"`
	Comparison             *string              `json:"comparison,omitempty"`
	ComparisonModel        *string              `json:"comparison_model,omitempty"`
	ComparisonUsage        *TokenUsage          `json:"comparison_usage,omitempty"`
	ComparisonFallbackUsed bool                 `json:"comparison_fallback_used"`
	TotalLatencyMs         int                  `json:"total_latency_ms"`
	Partial                bool                 `json:"partial"`
	SkipComparison         bool                 `json:"skip_comparison"`
}

type CompareStreamEvent added in v0.1.3

type CompareStreamEvent map[string]interface{}

type CompletionsResource

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

CompletionsResource handles POST /v1/chat/completions.

func (*CompletionsResource) Create

Create sends a non-streaming chat completion request and returns the full response.

func (*CompletionsResource) Stream

func (r *CompletionsResource) Stream(ctx context.Context, params ChatCompletionParams) (<-chan ChatCompletionChunk, <-chan error)

Stream opens a streaming chat completion. It returns two channels:

  • chunkCh: receives parsed ChatCompletionChunks until [DONE] or error
  • errCh: receives at most one error, then is closed

Both channels are always closed when the stream finishes. Callers must drain chunkCh before reading errCh, or use a select loop.

Streams are NEVER retried. On failure, catch the error from errCh and restart a new Stream call if reconnection is needed.

type Config

type Config struct {
	// BaseURL is the MeshAPI gateway base URL (required).
	BaseURL string
	// Token is the Bearer token for this auth realm (required).
	Token string
	// TimeoutMs is the request timeout in milliseconds (default 60_000).
	// For streaming requests this applies to TTFB only.
	TimeoutMs *int
	// MaxRetries is the number of retry attempts on retryable errors (default 3).
	MaxRetries *int
	// HTTPClient allows injecting a custom *http.Client (optional).
	HTTPClient *http.Client
}

Config holds the client configuration.

type ContentPart

type ContentPart struct {
	Type       string      `json:"type"`
	Text       *string     `json:"text,omitempty"`
	ImageURL   *ImageURL   `json:"image_url,omitempty"`
	InputAudio *InputAudio `json:"input_audio,omitempty"`
}

ContentPart is one element of a multimodal message content array.

type CreateBatchParams added in v0.1.3

type CreateBatchParams struct {
	InputFileID      string                 `json:"input_file_id"`
	Endpoint         string                 `json:"endpoint"`
	CompletionWindow string                 `json:"completion_window"`
	Metadata         map[string]interface{} `json:"metadata,omitempty"`
}

type CreateTemplateParams

type CreateTemplateParams struct {
	Name        string                   `json:"name"`
	Description *string                  `json:"description,omitempty"`
	System      *string                  `json:"system,omitempty"`
	Messages    []map[string]interface{} `json:"messages,omitempty"`
	Model       *string                  `json:"model,omitempty"`
	Params      map[string]interface{}   `json:"params,omitempty"`
	Variables   []string                 `json:"variables,omitempty"`
}

CreateTemplateParams is the request body for POST /v1/templates.

type EmbeddingItem added in v0.1.3

type EmbeddingItem struct {
	Object    string      `json:"object"`
	Index     int         `json:"index"`
	Embedding interface{} `json:"embedding"`
}

type EmbeddingsParams added in v0.1.3

type EmbeddingsParams struct {
	Model          *string     `json:"model,omitempty"`
	Input          interface{} `json:"input"`
	Dimensions     *int        `json:"dimensions,omitempty"`
	EncodingFormat *string     `json:"encoding_format,omitempty"`
	InputType      *string     `json:"input_type,omitempty"`
	Provider       interface{} `json:"provider,omitempty"`
	User           *string     `json:"user,omitempty"`
}

type EmbeddingsResource added in v0.1.3

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

func (*EmbeddingsResource) Create added in v0.1.3

type EmbeddingsResponse added in v0.1.3

type EmbeddingsResponse struct {
	Object string           `json:"object"`
	Data   []EmbeddingItem  `json:"data"`
	Model  string           `json:"model"`
	Usage  *EmbeddingsUsage `json:"usage,omitempty"`
}

type EmbeddingsUsage added in v0.1.3

type EmbeddingsUsage struct {
	PromptTokens int `json:"prompt_tokens"`
	TotalTokens  int `json:"total_tokens"`
}

type FileObject added in v0.1.3

type FileObject struct {
	ID            string      `json:"id"`
	Object        *string     `json:"object,omitempty"`
	Bytes         *int        `json:"bytes,omitempty"`
	CreatedAt     *int64      `json:"created_at,omitempty"`
	Filename      *string     `json:"filename,omitempty"`
	Purpose       *string     `json:"purpose,omitempty"`
	Status        *string     `json:"status,omitempty"`
	StatusDetails interface{} `json:"status_details,omitempty"`
}

type FilesResource added in v0.1.3

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

func (*FilesResource) Content added in v0.1.3

func (r *FilesResource) Content(ctx context.Context, fileID string) ([]byte, error)

func (*FilesResource) Delete added in v0.1.3

func (r *FilesResource) Delete(ctx context.Context, fileID string) error

func (*FilesResource) Get added in v0.1.3

func (r *FilesResource) Get(ctx context.Context, fileID string) (*FileObject, error)

func (*FilesResource) Upload added in v0.1.3

type ImageGenerationChunk added in v0.1.3

type ImageGenerationChunk struct {
	ID      *string     `json:"id,omitempty"`
	Object  *string     `json:"object,omitempty"`
	Created int64       `json:"created"`
	Model   *string     `json:"model,omitempty"`
	Data    []ImageItem `json:"data"`
	Status  *string     `json:"status,omitempty"`
}

type ImageGenerationParams added in v0.1.3

type ImageGenerationParams struct {
	Prompt         string  `json:"prompt"`
	Model          *string `json:"model,omitempty"`
	N              *int    `json:"n,omitempty"`
	Size           *string `json:"size,omitempty"`
	Quality        *string `json:"quality,omitempty"`
	ResponseFormat *string `json:"response_format,omitempty"`
	OutputFormat   *string `json:"output_format,omitempty"`
	Stream         *bool   `json:"stream,omitempty"`
}

type ImageGenerationResponse added in v0.1.3

type ImageGenerationResponse struct {
	Created      int64       `json:"created"`
	Data         []ImageItem `json:"data"`
	Background   *string     `json:"background,omitempty"`
	OutputFormat *string     `json:"output_format,omitempty"`
	Quality      *string     `json:"quality,omitempty"`
	Size         *string     `json:"size,omitempty"`
	Usage        *ImageUsage `json:"usage,omitempty"`
}

type ImageItem added in v0.1.3

type ImageItem struct {
	URL           *string `json:"url,omitempty"`
	B64JSON       *string `json:"b64_json,omitempty"`
	RevisedPrompt *string `json:"revised_prompt,omitempty"`
}

type ImageOptions added in v0.1.3

type ImageOptions struct {
	N              *int    `json:"n,omitempty"`
	Size           *string `json:"size,omitempty"`
	Quality        *string `json:"quality,omitempty"`
	ResponseFormat *string `json:"response_format,omitempty"`
}

type ImageURL

type ImageURL struct {
	URL    string  `json:"url"`
	Detail *string `json:"detail,omitempty"`
}

ImageURL holds the URL and rendering detail for an image content part.

type ImageUsage added in v0.1.3

type ImageUsage struct {
	PromptTokens        int                    `json:"prompt_tokens"`
	CompletionTokens    int                    `json:"completion_tokens"`
	TotalTokens         int                    `json:"total_tokens"`
	InputTokensDetails  map[string]interface{} `json:"input_tokens_details,omitempty"`
	OutputTokensDetails map[string]interface{} `json:"output_tokens_details,omitempty"`
}

type ImagesResource added in v0.1.3

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

func (*ImagesResource) Generate added in v0.1.3

Generate sends a non-streaming image generation request and returns the full response.

func (*ImagesResource) Stream added in v0.1.3

func (r *ImagesResource) Stream(ctx context.Context, params ImageGenerationParams) (<-chan ImageGenerationChunk, <-chan error)

Stream opens a streaming image generation request. It returns two channels:

  • chunkCh: receives parsed ImageGenerationChunks until [DONE] or error
  • errCh: receives at most one error, then is closed

Both channels are always closed when the stream finishes. Callers must drain chunkCh before reading errCh, or use a select loop.

type InputAudio added in v0.1.3

type InputAudio struct {
	Data   string `json:"data"`
	Format string `json:"format"`
}

type ListModelsParams

type ListModelsParams struct {
	Free *bool // nil = no filter
}

ListModelsParams holds optional query parameters for listing models.

type MeshAPIError

type MeshAPIError struct {
	// Status is the HTTP status code (0 for stream/parse errors).
	Status int
	// Code is the machine-readable error code slug (e.g. "unauthorized").
	Code string
	// RequestID is the req_<ULID> tracing identifier from the response.
	RequestID string
	// Message is the human-readable error description.
	Message string
	// Details contains validation error details (non-nil on 422 responses).
	Details []interface{}
	// ProviderError contains upstream provider error details when available.
	ProviderError map[string]interface{}
	// RetryAfterSeconds is set on 429 responses.
	RetryAfterSeconds *int
}

MeshAPIError is returned when MeshAPI responds with a non-2xx status or sends an error frame mid-stream.

func (*MeshAPIError) Error

func (e *MeshAPIError) Error() string

type ModelCompareResult added in v0.1.3

type ModelCompareResult struct {
	Model        string                 `json:"model"`
	ResponseBody map[string]interface{} `json:"response_body,omitempty"`
	Content      *string                `json:"content,omitempty"`
	LatencyMs    int                    `json:"latency_ms"`
	Error        *string                `json:"error,omitempty"`
	ErrorCode    *string                `json:"error_code,omitempty"`
	Usage        *TokenUsage            `json:"usage,omitempty"`
	RequestID    string                 `json:"request_id"`
}

type ModelInfo

type ModelInfo struct {
	ID                     string        `json:"id"`
	Name                   string        `json:"name"`
	ContextLength          *int          `json:"context_length,omitempty"`
	IsFree                 bool          `json:"is_free"`
	Pricing                *ModelPricing `json:"pricing,omitempty"`
	Description            *string       `json:"description,omitempty"`
	SupportsThinking       *bool         `json:"supports_thinking,omitempty"`
	SupportsCompletionsAPI *bool         `json:"supports_completions_api,omitempty"`
	SupportsResponsesAPI   *bool         `json:"supports_responses_api,omitempty"`
	ModelType              *string       `json:"model_type,omitempty"`
	InputModalities        []string      `json:"input_modalities,omitempty"`
	OutputModalities       []string      `json:"output_modalities,omitempty"`
}

ModelInfo describes an available model.

type ModelOverride added in v0.1.3

type ModelOverride struct {
	Model        string   `json:"model"`
	Temperature  *float64 `json:"temperature,omitempty"`
	MaxTokens    *int     `json:"max_tokens,omitempty"`
	SystemPrompt *string  `json:"system_prompt,omitempty"`
}

type ModelPricing

type ModelPricing struct {
	PromptUSDPer1K               *string `json:"prompt_usd_per_1k,omitempty"`
	CompletionUSDPer1K           *string `json:"completion_usd_per_1k,omitempty"`
	ImageUSDPerImage             *string `json:"image_usd_per_image,omitempty"`
	DiscountPct                  *string `json:"discount_pct,omitempty"`
	PromptUSDPer1KDiscounted     *string `json:"prompt_usd_per_1k_discounted,omitempty"`
	CompletionUSDPer1KDiscounted *string `json:"completion_usd_per_1k_discounted,omitempty"`
}

ModelPricing holds per-token pricing for a model.

type ModelsResource

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

ModelsResource provides access to the /v1/models endpoints.

func (*ModelsResource) Free

func (r *ModelsResource) Free(ctx context.Context) ([]ModelInfo, error)

Free returns only free-tier models.

func (*ModelsResource) List

func (r *ModelsResource) List(ctx context.Context, params ListModelsParams) ([]ModelInfo, error)

List returns all available models. Pass a non-nil Free pointer to filter.

func (*ModelsResource) Paid

func (r *ModelsResource) Paid(ctx context.Context) ([]ModelInfo, error)

Paid returns only paid-tier models.

type ProviderPreferences added in v0.1.3

type ProviderPreferences struct {
	Order             []string `json:"order,omitempty"`
	AllowFallbacks    *bool    `json:"allow_fallbacks,omitempty"`
	RequireParameters *bool    `json:"require_parameters,omitempty"`
	DataCollection    *string  `json:"data_collection,omitempty"`
}

type ResponsesFunctionTool added in v0.1.3

type ResponsesFunctionTool struct {
	Type        string      `json:"type"`
	Name        string      `json:"name"`
	Description *string     `json:"description,omitempty"`
	Parameters  interface{} `json:"parameters,omitempty"`
	Strict      *bool       `json:"strict,omitempty"`
}

type ResponsesParams added in v0.1.3

type ResponsesParams struct {
	Model           *string                `json:"model,omitempty"`
	Input           interface{}            `json:"input"`
	Template        *string                `json:"template,omitempty"`
	Variables       map[string]string      `json:"variables,omitempty"`
	SessionID       *string                `json:"session_id,omitempty"`
	Stream          *bool                  `json:"stream,omitempty"`
	MaxOutputTokens *int                   `json:"max_output_tokens,omitempty"`
	Temperature     *float64               `json:"temperature,omitempty"`
	TopP            *float64               `json:"top_p,omitempty"`
	Seed            *int                   `json:"seed,omitempty"`
	Reasoning       map[string]interface{} `json:"reasoning,omitempty"`
	Tools           []interface{}          `json:"tools,omitempty"`
	ToolChoice      interface{}            `json:"tool_choice,omitempty"`
	ResponseFormat  map[string]interface{} `json:"response_format,omitempty"`
	Plugins         []interface{}          `json:"plugins,omitempty"`
	User            *string                `json:"user,omitempty"`
}

type ResponsesResource added in v0.1.3

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

func (*ResponsesResource) Create added in v0.1.3

func (*ResponsesResource) Stream added in v0.1.3

func (r *ResponsesResource) Stream(ctx context.Context, params ResponsesParams) (<-chan ResponsesStreamEvent, <-chan error)

type ResponsesResponse added in v0.1.3

type ResponsesResponse struct {
	ID     *string                `json:"id,omitempty"`
	Object *string                `json:"object,omitempty"`
	Model  *string                `json:"model,omitempty"`
	Output []interface{}          `json:"output,omitempty"`
	Usage  *ResponsesUsage        `json:"usage,omitempty"`
	Status *string                `json:"status,omitempty"`
	Extra  map[string]interface{} `json:"-"`
}

type ResponsesStreamEvent added in v0.1.3

type ResponsesStreamEvent map[string]interface{}

type ResponsesUsage added in v0.1.3

type ResponsesUsage struct {
	InputTokens             *int                   `json:"input_tokens,omitempty"`
	OutputTokens            *int                   `json:"output_tokens,omitempty"`
	TotalTokens             *int                   `json:"total_tokens,omitempty"`
	PromptTokens            *int                   `json:"prompt_tokens,omitempty"`
	CompletionTokens        *int                   `json:"completion_tokens,omitempty"`
	PromptTokensDetails     map[string]interface{} `json:"prompt_tokens_details,omitempty"`
	CompletionTokensDetails map[string]interface{} `json:"completion_tokens_details,omitempty"`
	ClassifierTokens        *int                   `json:"classifier_tokens,omitempty"`
}

type TemplateSummary

type TemplateSummary struct {
	ID          string                   `json:"id"`
	Name        string                   `json:"name"`
	Owner       *string                  `json:"owner"`
	IsGlobal    bool                     `json:"is_global"`
	Description *string                  `json:"description,omitempty"`
	System      *string                  `json:"system,omitempty"`
	Messages    []map[string]interface{} `json:"messages,omitempty"`
	Model       *string                  `json:"model,omitempty"`
	Params      map[string]interface{}   `json:"params,omitempty"`
	Variables   []string                 `json:"variables,omitempty"`
	CreatedAt   string                   `json:"created_at"`
	UpdatedAt   string                   `json:"updated_at"`
}

TemplateSummary is the response shape for all template operations.

type TemplatesResource

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

TemplatesResource provides access to the /v1/templates CRUD endpoints.

func (*TemplatesResource) Create

Create creates a new prompt template.

func (*TemplatesResource) Delete

func (r *TemplatesResource) Delete(ctx context.Context, id string) error

Delete deletes a template (returns nil on 204 No Content).

func (*TemplatesResource) Get

Get returns a single template by ID.

func (*TemplatesResource) List

List returns all templates owned by the authenticated user.

func (*TemplatesResource) Update

Update partially updates a template.

type TokenUsage added in v0.1.3

type TokenUsage struct {
	PromptTokens     *int `json:"prompt_tokens,omitempty"`
	CompletionTokens *int `json:"completion_tokens,omitempty"`
	TotalTokens      *int `json:"total_tokens,omitempty"`
}

type Tool

type Tool struct {
	Type     string       `json:"type"`
	Function ToolFunction `json:"function"`
}

Tool defines a callable function available to the model.

type ToolCall

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

ToolCall represents a tool invocation in an assistant message.

type ToolCallFunction

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

ToolCallFunction holds the name and JSON-encoded arguments for a tool call.

type ToolChoice

type ToolChoice interface{}

ToolChoice controls model tool use. Use "auto", "none", "required", or ToolChoiceObject.

type ToolChoiceFunction

type ToolChoiceFunction struct {
	Name string `json:"name"`
}

ToolChoiceFunction names the function to call.

type ToolChoiceObject

type ToolChoiceObject struct {
	Type     string             `json:"type"`
	Function ToolChoiceFunction `json:"function"`
}

ToolChoiceObject selects a specific function.

type ToolFunction

type ToolFunction struct {
	Name        string      `json:"name"`
	Description *string     `json:"description,omitempty"`
	Parameters  interface{} `json:"parameters,omitempty"`
}

ToolFunction describes a callable function.

type UpdateTemplateParams

type UpdateTemplateParams struct {
	Name        *string                  `json:"name,omitempty"`
	Description *string                  `json:"description,omitempty"`
	System      *string                  `json:"system,omitempty"`
	Messages    []map[string]interface{} `json:"messages,omitempty"`
	Model       *string                  `json:"model,omitempty"`
	Params      map[string]interface{}   `json:"params,omitempty"`
	Variables   []string                 `json:"variables,omitempty"`
}

UpdateTemplateParams is the request body for PATCH /v1/templates/{id}.

type UploadBatchFileParams added in v0.1.3

type UploadBatchFileParams struct {
	Purpose  string             `json:"purpose,omitempty"`
	Requests []BatchRequestItem `json:"requests"`
}

type UsageInfo

type UsageInfo struct {
	PromptTokens               int                    `json:"prompt_tokens"`
	CompletionTokens           int                    `json:"completion_tokens"`
	TotalTokens                int                    `json:"total_tokens"`
	PromptTokensDetails        map[string]interface{} `json:"prompt_tokens_details,omitempty"`
	CompletionTokensDetails    map[string]interface{} `json:"completion_tokens_details,omitempty"`
	ClassifierPromptTokens     *int                   `json:"classifier_prompt_tokens,omitempty"`
	ClassifierCompletionTokens *int                   `json:"classifier_completion_tokens,omitempty"`
	ClassifierTokens           *int                   `json:"classifier_tokens,omitempty"`
}

UsageInfo holds token counts for a completion.

Jump to

Keyboard shortcuts

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