Skip to content

SDK Reference

Complete reference documentation for the PromptKit SDK API.

The SDK provides a pack-first API that reduces boilerplate by ~80%.

Opens a conversation from a pack file.

func Open(packPath string, promptName string, opts ...Option) (*Conversation, error)

Parameters:

  • packPath - Path to the .pack.json file
  • promptName - Name of the prompt from the pack
  • opts - Optional configuration options

Returns:

  • *Conversation - Ready-to-use conversation
  • error - Error if pack or prompt not found

Example:

conv, err := sdk.Open("./app.pack.json", "assistant")

Override the model.

sdk.WithModel("gpt-4o")

Override temperature.

sdk.WithTemperature(0.8)

Override max tokens.

sdk.WithMaxTokens(2000)

Attach an image from a file.

sdk.WithImageFile("/path/to/image.png")

Attach an image from a URL.

sdk.WithImageURL("https://example.com/image.jpg")

Attach image from raw bytes.

sdk.WithImageData(imageBytes, "image/png")

Attach a PDF document from a file.

sdk.WithDocumentFile("/path/to/document.pdf")

Attach a PDF document from raw bytes.

sdk.WithDocumentData(pdfBytes, "application/pdf")

Attach an audio file.

sdk.WithAudioFile("/path/to/audio.mp3")

Attach a video file.

sdk.WithVideoFile("/path/to/video.mp4")

Send a message and get a response.

func (c *Conversation) Send(ctx context.Context, message any) (*Response, error)

Stream a response.

func (c *Conversation) Stream(ctx context.Context, message string) <-chan StreamChunk

Set a template variable.

func (c *Conversation) SetVar(key string, value any)

Get a template variable.

func (c *Conversation) GetVar(key string) any

Set multiple variables.

func (c *Conversation) SetVars(vars map[string]any)

Register a tool handler.

func (c *Conversation) OnTool(name string, handler ToolHandler)

Register a tool handler with context.

func (c *Conversation) OnToolCtx(name string, handler ToolHandlerCtx)

Register multiple tool handlers.

func (c *Conversation) OnTools(handlers map[string]ToolHandler)

Register a tool with approval workflow.

func (c *Conversation) OnToolAsync(name string, check CheckFunc, execute ToolHandler)

Register an HTTP tool.

func (c *Conversation) OnToolHTTP(name string, config *tools.HTTPToolConfig)

Subscribe to events.

func (c *Conversation) Subscribe(event string, handler func(hooks.Event))

Get conversation history.

func (c *Conversation) Messages() []types.Message

Clear conversation history.

func (c *Conversation) Clear()

Create an isolated copy.

func (c *Conversation) Fork() *Conversation

Close the conversation.

func (c *Conversation) Close() error

Get conversation ID.

func (c *Conversation) ID() string

Approve a pending tool.

func (c *Conversation) ResolveTool(id string) (*ToolResult, error)

Reject a pending tool.

func (c *Conversation) RejectTool(id string, reason string) (*ToolResult, error)

Get response text.

func (r *Response) Text() string

Check for tool calls.

func (r *Response) HasToolCalls() bool

Get tool calls.

func (r *Response) ToolCalls() []ToolCall

Get pending approvals.

func (r *Response) PendingTools() []PendingTool
type StreamChunk struct {
Type ChunkType // ChunkText, ChunkToolCall, ChunkDone
Text string // Text content
Error error // Error if any
}
const (
ChunkText ChunkType = "text"
ChunkToolCall ChunkType = "tool_call"
ChunkDone ChunkType = "done"
)
type ToolHandler func(args map[string]any) (any, error)
type ToolHandlerCtx func(ctx context.Context, args map[string]any) (any, error)
var (
ErrPackNotFound = errors.New("pack file not found")
ErrPromptNotFound = errors.New("prompt not found in pack")
ErrInvalidPack = errors.New("invalid pack format")
ErrProviderError = errors.New("provider error")
ErrConversationClosed = errors.New("conversation closed")
ErrToolNotRegistered = errors.New("tool not registered")
)
import (
"github.com/AltairaLabs/PromptKit/sdk"
"github.com/AltairaLabs/PromptKit/sdk/hooks"
"github.com/AltairaLabs/PromptKit/sdk/tools"
)
  • Audio API - VAD mode, ASM mode, turn detection, audio streaming
  • TTS API - Text-to-speech services, voices, formats, providers
  • Streaming Package - Bidirectional streaming utilities, response collection, audio streaming