const DEFAULT_TIMEOUT_NS
pub const DEFAULT_TIMEOUT_NS = 60000000000Purpose
Constant DEFAULT_TIMEOUT_NS, defining protocol or algorithm parameters.
#github.com/xulang-org/packages/anthropicExternal package `anthropic #github.com/xulang-org/packages/anthropic`, provided by github.com/xulang-org/packages.
github.com/xulang-org/packages · 1.17.2 · Install and use
const DEFAULT_TIMEOUT_NSpub const DEFAULT_TIMEOUT_NS = 60000000000Constant DEFAULT_TIMEOUT_NS, defining protocol or algorithm parameters.
const DEFAULT_VERSIONpub const DEFAULT_VERSION = "2023-06-01"Constant DEFAULT_VERSION, defining protocol or algorithm parameters.
struct Clientpub struct Client {
pub base_url string
pub api_key string
pub api_version string
pub timeout_ns int
pub max_retries int
pub extra_headers []string
}Anthropic Client session maintaining connection and operations.
base_url stringapi_key stringapi_version stringtimeout_ns intmax_retries intextra_headers []stringstruct ContentBlockpub struct ContentBlock {
pub kind string
pub text string
pub thinking string
pub id string
pub name string
pub input_json string
pub media_type string
pub data string
pub cache_control string
}Structure encapsulating kind, text, thinking, id, name.
kind stringtext stringthinking stringid stringname stringinput_json stringmedia_type stringdata stringcache_control stringstruct Messagepub struct Message {
pub role string
pub content string
pub blocks []ContentBlock
}Structure encapsulating role, content, blocks.
role stringcontent stringblocks []ContentBlockstruct Toolpub struct Tool {
pub name string
pub description string
pub input_schema_json string
}Structure encapsulating name, description, input_schema_json.
name stringdescription stringinput_schema_json stringstruct ToolUsepub struct ToolUse {
pub id string
pub name string
pub input_json string
}Structure encapsulating id, name, input_json.
id stringname stringinput_json stringstruct Usagepub struct Usage {
pub input_tokens int
pub output_tokens int
pub cache_creation_input_tokens int
pub cache_read_input_tokens int
}Structure encapsulating input_tokens, output_tokens, cache_creation_input_tokens, cache_read_input_tokens.
input_tokens intoutput_tokens intcache_creation_input_tokens intcache_read_input_tokens intstruct MessagesRequestpub struct MessagesRequest {
pub model string
pub system string
pub cache_system bool
pub messages []Message
pub tools []Tool
pub max_tokens int
pub temperature f64
pub has_temperature bool
pub top_p f64
pub has_top_p bool
pub stop_sequences []string
pub thinking_budget_tokens int
pub tool_choice_json string
pub extra_body_json string
}Structure encapsulating model, system, cache_system, messages, tools.
model stringsystem stringcache_system boolmessages []Messagetools []Toolmax_tokens inttemperature f64has_temperature booltop_p f64has_top_p boolstop_sequences []stringthinking_budget_tokens inttool_choice_json stringextra_body_json stringstruct MessagesResponsepub struct MessagesResponse {
pub id string
pub model string
pub role string
pub stop_reason string
pub content string
pub thinking string
pub tool_uses []ToolUse
pub blocks []ContentBlock
pub usage Usage
}Anthropic Server response payload containing status, headers, and body.
id stringmodel stringrole stringstop_reason stringcontent stringthinking stringtool_uses []ToolUseblocks []ContentBlockusage Usagestruct StreamEventpub struct StreamEvent {
pub event_type string
pub text_delta string
pub thinking_delta string
pub stop_reason string
pub tool_use ToolUse
pub has_tool_use bool
pub usage Usage
pub done bool
}Structure encapsulating event_type, text_delta, thinking_delta, stop_reason, tool_use.
event_type stringtext_delta stringthinking_delta stringstop_reason stringtool_use ToolUsehas_tool_use boolusage Usagedone boolnew_clientpub fn new_client(api_key string) ClientConstruct client.
api_key stringClient — a value of this type
new_client_with_basepub fn new_client_with_base(base_url string, api_key string) ClientConstruct client with base.
base_url stringapi_key stringClient — a value of this type
($&Client) set_max_retriespub fn (c $&Client) set_max_retries(n int)Operation on $&Client: set max retries.
c $&ClientClient instance used by this call (exclusive borrow).n intThis call does not return a value.
($&Client) add_headerpub fn (c $&Client) add_header(name string, value string)Operation on $&Client: add header.
c $&ClientClient instance used by this call (exclusive borrow).name stringvalue stringThis call does not return a value.
(&Client) clone_clientpub fn (c &Client) clone_client() ClientOperation on &Client: clone client.
c &ClientClient instance used by this call (borrow).Client — a value of this type
text_blockpub fn text_block(text string) ContentBlockText block.
text stringContentBlock — a value of this type
image_base64_blockpub fn image_base64_block(media_type string, b64_data string) ContentBlockImage base64 block.
media_type stringb64_data stringContentBlock — a value of this type
image_url_blockpub fn image_url_block(url string) ContentBlockImage url block.
url stringContentBlock — a value of this type
messagepub fn message(role string, content string) MessageExecute message.
role stringcontent stringMessage — a value of this type
message_blockspub fn message_blocks(role string, blocks []ContentBlock) MessageMessage blocks.
role stringblocks []ContentBlockMessage — a value of this type
tool_result_messagepub fn tool_result_message(tool_use_id string, content string, is_error bool) MessageTool result message.
tool_use_id stringcontent stringis_error boolMessage — a value of this type
toolpub fn tool(name string, description string, input_schema_json string) ToolExecute tool.
name stringdescription stringinput_schema_json stringTool — a value of this type
messages_requestpub fn messages_request(model string, messages []Message, max_tokens int) MessagesRequestMessages request.
model stringmessages []Messagemax_tokens intMessagesRequest — a value of this type
(&Client) messagespub fn (c &Client) messages(req &MessagesRequest) MessagesResponseExecute messages on &Client. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).req &MessagesRequestMessagesResponse — a value of this type
(&Client) messages_streampub fn (c &Client) messages_stream(req &MessagesRequest, on_event fn(StreamEvent) bool) MessagesResponseOperation on &Client: messages stream. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).req &MessagesRequeston_event fn(StreamEvent) boolMessagesResponse — a value of this type
(&Client) messages_stream_chanpub fn (c &Client) messages_stream_chan(req &MessagesRequest, ch chan StreamEvent) MessagesResponseOperation on &Client: messages stream chan. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).req &MessagesRequestch chan StreamEventMessagesResponse — a value of this type