responses

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewOutputItemFunctionCallID

func NewOutputItemFunctionCallID() string

func NewOutputItemMessageID

func NewOutputItemMessageID() string

func NewOutputItemReasoningID

func NewOutputItemReasoningID() string

Types

type Annotation

type Annotation struct {
	Type       string `json:"type"`
	Text       string `json:"text"`
	StartIndex int    `json:"start_index"`
	EndIndex   int    `json:"end_index"`
	Operation  string `json:"operation"`
}

type ChunkContentPart

type ChunkContentPart[T any] struct {
	Type           T                  `json:"type"`
	SequenceNumber int                `json:"sequence_number"`
	ItemId         string             `json:"item_id"`
	OutputIndex    int                `json:"output_index"`
	ContentIndex   int                `json:"content_index"`
	Part           OutputContentUnion `json:"part"`
}

type ChunkFunctionCall

type ChunkFunctionCall[T any] struct {
	Type T `json:"type"`

	SequenceNumber int    `json:"sequence_number"`
	ItemId         string `json:"item_id"`
	OutputIndex    int    `json:"output_index"`
	Delta          string `json:"delta"`
	Arguments      string `json:"arguments"`
	Obfuscation    string `json:"obfuscation"`
}

type ChunkImageGenerationCall

type ChunkImageGenerationCall[T any] struct {
	Type T `json:"type"`

	SequenceNumber int    `json:"sequence_number"`
	ItemId         string `json:"item_id"`
	OutputIndex    int    `json:"output_index"`

	// Only on response.image_generation_call.partial_image
	PartialImageIndex  int     `json:"partial_image_index"`
	PartialImageBase64 string  `json:"partial_image_b64"`
	Background         *string `json:"background,omitempty"`    // "opaque"
	OutputFormat       *string `json:"output_format,omitempty"` // "png"
	Quality            *string `json:"quality,omitempty"`       // "medium"
	Size               *string `json:"size,omitempty"`          // "1024x1024"
}

type ChunkOutputItem

type ChunkOutputItem[T any] struct {
	Type           T                   `json:"type"`
	SequenceNumber int                 `json:"sequence_number"`
	OutputIndex    int                 `json:"output_index"`
	Item           ChunkOutputItemData `json:"item"`
}

type ChunkOutputItemData

type ChunkOutputItemData struct {
	Type string `json:"type"` // "function_call" , "message", "reasoning", "image_generation_call"

	// Common fields
	Id     string `json:"id"`
	Status string `json:"status"`

	// For output_item of type "message"
	Content OutputContent  `json:"content"`
	Role    constants.Role `json:"role"`

	// For output_item of type "function_call"
	CallID    *string `json:"call_id,omitempty"`
	Name      *string `json:"name,omitempty"`
	Arguments *string `json:"arguments,omitempty"`

	// For "reasoning"
	EncryptedContent *string              `json:"encrypted_content,omitempty"`
	Summary          []SummaryTextContent `json:"summary,omitempty"`

	// For "image_generation_call"
	Background   *string `json:"background,omitempty"`    // "opaque"
	OutputFormat *string `json:"output_format,omitempty"` // "png"
	Quality      *string `json:"quality,omitempty"`       // "medium"
	Result       *string `json:"result,omitempty"`        // base64 image
	Size         *string `json:"size,omitempty"`          // "1024x1024"
}

type ChunkOutputText

type ChunkOutputText[T any] struct {
	Type           T             `json:"type"`
	SequenceNumber int           `json:"sequence_number"`
	ItemId         string        `json:"item_id"`
	OutputIndex    int           `json:"output_index"`
	ContentIndex   int           `json:"content_index"`
	Delta          string        `json:"delta"`
	Logprobs       []interface{} `json:"logprobs"`
	Obfuscation    string        `json:"obfuscation"`

	// Only on content.output_text.done (contains the accumulated content)
	Text *string `json:"text,omitempty"`
}

type ChunkReasoningSummaryPart

type ChunkReasoningSummaryPart[T any] struct {
	Type           T                  `json:"type"`
	SequenceNumber int                `json:"sequence_number"`
	ItemId         string             `json:"item_id"`
	OutputIndex    int                `json:"output_index"`
	SummaryIndex   int                `json:"summary_index"`
	Part           SummaryTextContent `json:"part"`
}

type ChunkReasoningSummaryText

type ChunkReasoningSummaryText[T any] struct {
	Type           T      `json:"type"`
	SequenceNumber int    `json:"sequence_number"`
	ItemId         string `json:"item_id"`
	OutputIndex    int    `json:"output_index"`
	SummaryIndex   int    `json:"summary_index"`

	// Only on response.reasoning_summary_text.delta
	Delta string `json:"delta"`

	// Only on response.reasoning_summary_text.done
	Text *string `json:"text,omitempty"`

	// Helpers - Anthropic sends signature as a separate delta with different type "signature_delta"
	// We would have been using "Delta" for storing the reasoning summary delta, and since we need another field
	// to store the signature, we use this field.
	// We don't use "Text" to avoid confusion.
	EncryptedContent *string `json:"encrypted_content,omitempty"`
}

type ChunkResponse

type ChunkResponse[T any] struct {
	Type           T                 `json:"type"`
	SequenceNumber int               `json:"sequence_number"`
	Response       ChunkResponseData `json:"response"`
}

type ChunkResponseData

type ChunkResponseData struct {
	Id                string               `json:"id"`
	Object            string               `json:"object"`
	CreatedAt         int                  `json:"created_at"`
	Status            string               `json:"status"`
	Background        bool                 `json:"background"`
	Error             interface{}          `json:"error"`
	IncompleteDetails interface{}          `json:"incomplete_details"`
	Output            []OutputMessageUnion `json:"output"`
	Usage             Usage                `json:"usage"`
	Request
}

type ChunkResponseUsage

type ChunkResponseUsage struct {
	InputTokens        int `json:"input_tokens"`
	InputTokensDetails struct {
		CachedTokens int `json:"cached_tokens"`
	} `json:"input_tokens_details"`
	OutputTokens        int `json:"output_tokens"`
	OutputTokensDetails struct {
		ReasoningTokens int `json:"reasoning_tokens"`
	} `json:"output_tokens_details"`
	TotalTokens int `json:"total_tokens"`
}

type ChunkRun

type ChunkRun[T any] struct {
	Type           T            `json:"type"`
	SequenceNumber int          `json:"sequence_number"`
	RunState       ChunkRunData `json:"run_state"`
}

type ChunkRunData

type ChunkRunData struct {
	Id               string                `json:"id"`
	Object           string                `json:"object"` // "run"
	Status           string                `json:"status"` // "created", "in_progress", "paused", "resumed", "completed", "aborted"
	PendingToolCalls []FunctionCallMessage `json:"pending_tool_calls"`
	Usage            Usage                 `json:"usage"`
	TraceID          string                `json:"traceid"`
}

type EasyInputContentUnion

type EasyInputContentUnion struct {
	OfString           *string      `json:",omitempty"`
	OfInputMessageList InputContent `json:",omitempty"`
}

func (*EasyInputContentUnion) MarshalJSON

func (u *EasyInputContentUnion) MarshalJSON() ([]byte, error)

func (*EasyInputContentUnion) UnmarshalJSON

func (u *EasyInputContentUnion) UnmarshalJSON(data []byte) error

type EasyMessage

type EasyMessage struct {
	Type    constants.MessageTypeMessage `json:"type"` // Always "message".
	ID      string                       `json:"id,omitempty"`
	Role    constants.Role               `json:"role,omitempty"`
	Content EasyInputContentUnion        `json:"content"`
}

type Error

type Error struct {
	Type    string `json:"type"`
	Message string `json:"message"`
	Param   string `json:"param"`
	Code    string `json:"code"`
}

type FunctionCallApprovalResponseMessage

type FunctionCallApprovalResponseMessage struct {
	Type            constants.MessageTypeFunctionCallApprovalResponse `json:"type"`
	ID              string                                            `json:"id"`
	ApprovedCallIds []string                                          `json:"approved_call_ids"`
	RejectedCallIds []string                                          `json:"rejected_call_ids"`
}

type FunctionCallMessage

type FunctionCallMessage struct {
	Type      constants.MessageTypeFunctionCall `json:"type"`
	ID        string                            `json:"id,omitempty"`
	CallID    string                            `json:"call_id,omitempty"`
	Name      string                            `json:"name"`
	Arguments string                            `json:"arguments"`
}

type FunctionCallOutputContentUnion

type FunctionCallOutputContentUnion struct {
	OfString *string      `json:",omitempty"`
	OfList   InputContent `json:",omitempty"`
}

func (*FunctionCallOutputContentUnion) MarshalJSON

func (u *FunctionCallOutputContentUnion) MarshalJSON() ([]byte, error)

func (*FunctionCallOutputContentUnion) UnmarshalJSON

func (u *FunctionCallOutputContentUnion) UnmarshalJSON(data []byte) error

type FunctionCallOutputMessage

type FunctionCallOutputMessage struct {
	Type   constants.MessageTypeFunctionCallOutput `json:"type"`
	ID     string                                  `json:"id,omitempty"`
	CallID string                                  `json:"call_id"`
	Output FunctionCallOutputContentUnion          `json:"output"`
}

type FunctionTool

type FunctionTool struct {
	Type        constants.ToolTypeFunction `json:"type"` // "function"
	Name        string                     `json:"name"`
	Description *string                    `json:"description,omitempty"`
	Parameters  map[string]any             `json:"parameters,omitempty"`
	Strict      *bool                      `json:"strict,omitempty"`
}

type ImageGenerationCallMessage

type ImageGenerationCallMessage struct {
	Type         constants.MessageTypeImageGenerationCall `json:"type"`
	ID           string                                   `json:"id"`            // "ig_" prefixed
	Status       string                                   `json:"status"`        // "generating"
	Background   string                                   `json:"background"`    // "opaque"
	OutputFormat string                                   `json:"output_format"` // "png"
	Quality      string                                   `json:"quality"`       // "medium"
	Size         string                                   `json:"size"`          // 100x100
	Result       string                                   `json:"result"`        // Base64 image
}

type ImageGenerationTool

type ImageGenerationTool struct {
	Type constants.ToolTypeImageGeneration `json:"type"` // image_generation
}

type Includable

type Includable string
const (
	IncludableCodeInterpreterCallOutputs       Includable = "code_interpreter_call.outputs"
	IncludableComputerCallOutputOutputImageURL Includable = "computer_call_output.output.image_url"
	IncludableFileSearchCallResults            Includable = "file_search_call.results"
	IncludableMessageInputImageImageURL        Includable = "message.input_image.image_url"
	IncludableMessageOutputTextLogprobs        Includable = "message.output_text.logprobs"
	IncludableReasoningEncryptedContent        Includable = "reasoning.encrypted_content"
)

type InputContent

type InputContent []InputContentUnion

type InputContentUnion

type InputContentUnion struct {
	OfInputText  *InputTextContent  `json:",omitempty"`
	OfOutputText *OutputTextContent `json:",omitempty"`
	OfInputImage *InputImageContent `json:",omitempty,inline"`
}

func (*InputContentUnion) MarshalJSON

func (u *InputContentUnion) MarshalJSON() ([]byte, error)

func (*InputContentUnion) UnmarshalJSON

func (u *InputContentUnion) UnmarshalJSON(data []byte) error

type InputImageContent

type InputImageContent struct {
	Type     constants.ContentTypeInputImage `json:"type"`
	ImageURL *string                         `json:"image_url,omitempty"` // A fully qualified URL or base64 encoded image in a data URL.
	FileID   *string                         `json:"file_id,omitempty"`
	Detail   string                          `json:"detail"` // "low", "high", "auto"
}

type InputMessage

type InputMessage struct {
	Type    constants.MessageTypeMessage `json:"type"` // Always "message".
	ID      string                       `json:"id,omitempty"`
	Role    constants.Role               `json:"role,omitempty"` // Any of "user", "system", "developer".
	Content InputContent                 `json:"content,omitempty"`
}

type InputMessageList

type InputMessageList []InputMessageUnion

type InputMessageUnion

type InputMessageUnion struct {
	OfEasyInput                    *EasyMessage                         `json:",omitempty"`
	OfInputMessage                 *InputMessage                        `json:",omitempty"`
	OfOutputMessage                *OutputMessage                       `json:",omitempty"`
	OfFunctionCall                 *FunctionCallMessage                 `json:",omitempty"`
	OfFunctionCallApprovalResponse *FunctionCallApprovalResponseMessage `json:",omitempty"`
	OfFunctionCallOutput           *FunctionCallOutputMessage           `json:",omitempty"`
	OfReasoning                    *ReasoningMessage                    `json:",omitempty"`
	OfImageGenerationCall          *ImageGenerationCallMessage          `json:",omitempty,inline"`
}

func UserMessage

func UserMessage(msg string) InputMessageUnion

func (*InputMessageUnion) ID

func (u *InputMessageUnion) ID() string

func (*InputMessageUnion) MarshalJSON

func (u *InputMessageUnion) MarshalJSON() ([]byte, error)

func (*InputMessageUnion) UnmarshalJSON

func (u *InputMessageUnion) UnmarshalJSON(data []byte) error

type InputTextContent

type InputTextContent struct {
	Type constants.ContentTypeInputText `json:"type"`
	Text string                         `json:"text"`
}

type InputUnion

type InputUnion struct {
	OfString           *string          `json:",omitempty,inline"`
	OfInputMessageList InputMessageList `json:",omitempty,inline"`
}

func (*InputUnion) MarshalJSON

func (u *InputUnion) MarshalJSON() ([]byte, error)

func (*InputUnion) UnmarshalJSON

func (u *InputUnion) UnmarshalJSON(data []byte) error

type OutputContent

type OutputContent []OutputContentUnion

type OutputContentUnion

type OutputContentUnion struct {
	OfOutputText *OutputTextContent `json:",omitempty,inline"`
}

func (*OutputContentUnion) MarshalJSON

func (u *OutputContentUnion) MarshalJSON() ([]byte, error)

func (*OutputContentUnion) UnmarshalJSON

func (u *OutputContentUnion) UnmarshalJSON(data []byte) error

type OutputMessage

type OutputMessage struct {
	ID      string                       `json:"id"`
	Type    constants.MessageTypeMessage `json:"type,omitempty"`          // Always "message".
	Role    constants.Role               `json:"role,omitempty,required"` // Any of "user", "system", "developer".
	Content OutputContent                `json:"content,omitempty,required"`
}

type OutputMessageUnion

type OutputMessageUnion struct {
	OfOutputMessage       *OutputMessage              `json:",omitempty"`
	OfFunctionCall        *FunctionCallMessage        `json:",omitempty"`
	OfReasoning           *ReasoningMessage           `json:",omitempty"`
	OfImageGenerationCall *ImageGenerationCallMessage `json:",omitempty"`
}

OutputMessageUnion represents all possible message outputs from the model. Model can output: "text", "function_call", "reasoning" or "image_generation_call"

func (*OutputMessageUnion) AsInput

func (u *OutputMessageUnion) AsInput() (InputMessageUnion, error)

func (*OutputMessageUnion) MarshalJSON

func (u *OutputMessageUnion) MarshalJSON() ([]byte, error)

func (*OutputMessageUnion) UnmarshalJSON

func (u *OutputMessageUnion) UnmarshalJSON(data []byte) error

type OutputTextContent

type OutputTextContent struct {
	Type        constants.ContentTypeOutputText `json:"type"`
	Text        string                          `json:"text"`
	Annotations []Annotation                    `json:"annotations"`
}

type Parameters

type Parameters struct {
	Temperature     *float64          `json:"temperature,omitempty"`
	MaxOutputTokens *int              `json:"max_output_tokens,omitempty"`
	TopP            *float64          `json:"top_p,omitempty"`
	TopLogprobs     *int64            `json:"top_logprobs,omitempty"`
	Text            *TextFormat       `json:"text,omitempty"`
	Background      *bool             `json:"background,omitempty"`
	Reasoning       *ReasoningParam   `json:"reasoning,omitempty"`
	Store           *bool             `json:"store,omitempty"`
	Include         []Includable      `json:"include,omitempty"`
	Metadata        map[string]string `json:"metadata,omitempty"`
	Stream          *bool             `json:"stream,omitempty"`

	MaxToolCalls      *int  `json:"max_tool_calls,omitempty"`
	ParallelToolCalls *bool `json:"parallel_tool_calls,omitempty"`
}

type ReasoningMessage

type ReasoningMessage struct {
	Type             constants.MessageTypeReasoning `json:"type"`
	ID               string                         `json:"id"`
	Summary          []SummaryTextContent           `json:"summary"`
	EncryptedContent *string                        `json:"encrypted_content,omitempty"`
}

type ReasoningParam

type ReasoningParam struct {
	Summary      *string `json:"summary"` // "auto", "concise", "detailed"
	Effort       *string `json:"effort"`  // "none", "minimal", "low", "medium", "high", "xhigh"
	BudgetTokens *int    `json:",omitempty"`
}

type Request

type Request struct {
	Parameters
	Model        string      `json:"model"`
	Input        InputUnion  `json:"input,omitempty,omitzero"`
	Instructions *string     `json:"instructions,omitempty"`
	Tools        []ToolUnion `json:"tools,omitempty"`
}

func (*Request) IsStreamingRequest

func (s *Request) IsStreamingRequest() bool

type Response

type Response struct {
	ID          string                 `json:"id"`
	Model       string                 `json:"model"`
	Output      []OutputMessageUnion   `json:"output"`
	Usage       *Usage                 `json:"usage"`
	Error       *Error                 `json:"error"`
	ServiceTier string                 `json:"service_tier"`
	Metadata    map[string]interface{} `json:"metadata"`
}

type ResponseChunk

type ResponseChunk struct {
	OfResponseCreated    *ChunkResponse[constants.ChunkTypeResponseCreated]    `json:",omitempty"`
	OfResponseInProgress *ChunkResponse[constants.ChunkTypeResponseInProgress] `json:",omitempty"`
	OfResponseCompleted  *ChunkResponse[constants.ChunkTypeResponseCompleted]  `json:",omitempty"`

	OfOutputItemAdded *ChunkOutputItem[constants.ChunkTypeOutputItemAdded] `json:",omitempty"`
	OfOutputItemDone  *ChunkOutputItem[constants.ChunkTypeOutputItemDone]  `json:",omitempty"`

	// For output item of type "message"
	OfContentPartAdded *ChunkContentPart[constants.ChunkTypeContentPartAdded] `json:",omitempty"`
	OfContentPartDone  *ChunkContentPart[constants.ChunkTypeContentPartDone]  `json:",omitempty"`
	OfOutputTextDelta  *ChunkOutputText[constants.ChunkTypeOutputTextDelta]   `json:",omitempty"`
	OfOutputTextDone   *ChunkOutputText[constants.ChunkTypeOutputTextDone]    `json:",omitempty"`

	// For output item of type "function_call"
	OfFunctionCallArgumentsDelta *ChunkFunctionCall[constants.ChunkTypeFunctionCallArgumentsDelta] `json:",omitempty"`
	OfFunctionCallArgumentsDone  *ChunkFunctionCall[constants.ChunkTypeFunctionCallArgumentsDone]  `json:",omitempty"`

	// For output item of type "reasoning"
	OfReasoningSummaryPartAdded *ChunkReasoningSummaryPart[constants.ChunkTypeReasoningSummaryPartAdded] `json:",omitempty"`
	OfReasoningSummaryPartDone  *ChunkReasoningSummaryPart[constants.ChunkTypeReasoningSummaryPartDone]  `json:",omitempty"`
	OfReasoningSummaryTextDelta *ChunkReasoningSummaryText[constants.ChunkTypeReasoningSummaryTextDelta] `json:",omitempty"`
	OfReasoningSummaryTextDone  *ChunkReasoningSummaryText[constants.ChunkTypeReasoningSummaryTextDone]  `json:",omitempty"`

	// For output item of type "image_generation_call"
	OfImageGenerationCallInProgress   *ChunkImageGenerationCall[constants.ChunkTypeImageGenerationCallInProgress]   `json:",omitempty"`
	OfImageGenerationCallGenerating   *ChunkImageGenerationCall[constants.ChunkTypeImageGenerationCallGenerating]   `json:",omitempty"`
	OfImageGenerationCallPartialImage *ChunkImageGenerationCall[constants.ChunkTypeImageGenerationCallPartialImage] `json:",omitempty"`

	// Custom Chunks
	OfRunCreated         *ChunkRun[constants.ChunkTypeRunCreated]    `json:",omitempty"`
	OfRunInProgress      *ChunkRun[constants.ChunkTypeRunInProgress] `json:",omitempty"`
	OfRunPaused          *ChunkRun[constants.ChunkTypeRunPaused]     `json:",omitempty"`
	OfRunCompleted       *ChunkRun[constants.ChunkTypeRunCompleted]  `json:",omitempty"`
	OfFunctionCallOutput *FunctionCallOutputMessage                  `json:",omitempty"`
}

func (*ResponseChunk) ChunkType

func (u *ResponseChunk) ChunkType() string

func (*ResponseChunk) MarshalJSON

func (u *ResponseChunk) MarshalJSON() ([]byte, error)

func (*ResponseChunk) UnmarshalJSON

func (u *ResponseChunk) UnmarshalJSON(data []byte) error

type SummaryTextContent

type SummaryTextContent struct {
	Type constants.ContentTypeSummaryText `json:"type"`
	Text string                           `json:"text"`
}

type TextFormat

type TextFormat struct {
	Format map[string]any `json:"format,omitempty"`
}

type ToolUnion

type ToolUnion struct {
	OfFunction        *FunctionTool        `json:",omitempty"`
	OfImageGeneration *ImageGenerationTool `json:",omitempty"`
}

func (*ToolUnion) MarshalJSON

func (u *ToolUnion) MarshalJSON() ([]byte, error)

func (*ToolUnion) Tool

func (u *ToolUnion) Tool(ctx context.Context) *ToolUnion

func (*ToolUnion) UnmarshalJSON

func (u *ToolUnion) UnmarshalJSON(data []byte) error

type Usage

type Usage struct {
	InputTokens        int `json:"input_tokens"`
	InputTokensDetails struct {
		CachedTokens int `json:"cached_tokens"`
	} `json:"input_tokens_details"`
	OutputTokens        int `json:"output_tokens"`
	OutputTokensDetails struct {
		ReasoningTokens int `json:"reasoning_tokens"`
	} `json:"output_tokens_details"`
	TotalTokens int `json:"total_tokens"`
}

Jump to

Keyboard shortcuts

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