1
package api
1
package api
2
2
3
type ChatMessage struct {
3
type ChatMessage struct {
4
Role string `json:"role"`
4
Role string `json:"role"`
5
Content []ContentBlock `json:"content"`
5
Content []ContentBlock `json:"content"`
6
}
6
}
7
7
8
type MessagesRequest struct {
8
type MessagesRequest struct {
9
Model string `json:"model"`
9
Model string `json:"model"`
10
Messages []ChatMessage `json:"messages"`
10
Messages []ChatMessage `json:"messages"`
11
MaxTokens int `json:"max_tokens"`
11
MaxTokens int `json:"max_tokens"`
12
System string `json:"system,omitempty"`
12
System string `json:"system,omitempty"`
13
Temperature float64 `json:"temperature"`
13
Temperature float64 `json:"temperature"`
14
Tools []Tool `json:"tools,omitempty"`
14
Tools []Tool `json:"tools,omitempty"`
15
}
15
}
16
16
17
type ContentBlock struct {
17
type ContentBlock struct {
18
// Type is "text", "image", "tool_use", or "tool_result".
18
// Type is "text", "image", "tool_use", or "tool_result".
19
Type string `json:"type"`
19
Type string `json:"type"`
20
21
// Text is for Type="text"
20
Text string `json:"text"`
22
Text string `json:"text"`
23
24
// Source is for Type="image"
21
Source *ContentSource `json:"source"`
25
Source *ContentSource `json:"source"`
26
27
// Id, Name, and Input are for Type="tool_use".
28
ID string `json:"id"`
29
Name string `json:"name"`
30
Input interface{} `json:"input"`
22
}
31
}
23
32
24
type ContentSource struct {
33
type ContentSource struct {
25
// Type can only be "base64".
34
// Type can only be "base64".
26
Type string `json:"type"`
35
Type string `json:"type"`
27
36
28
// MediaType can be one of:
37
// MediaType can be one of:
29
// - "image/jpeg",
38
// - "image/jpeg",
30
// - "image/png",
39
// - "image/png",
31
// - "image/gif", or
40
// - "image/gif", or
32
// - "image/webp".
41
// - "image/webp".
33
MediaType string `json:"media_type,omitempty"`
42
MediaType string `json:"media_type,omitempty"`
34
43
35
Data string `json:"data,omitempty"`
44
Data string `json:"data,omitempty"`
36
}
45
}
37
46
38
type Usage struct {
47
type Usage struct {
39
InputTokens int `json:"input_tokens"`
48
InputTokens int `json:"input_tokens"`
40
CacheCreationInputTokens *int `json:"cache_creation_input_tokens"`
49
CacheCreationInputTokens *int `json:"cache_creation_input_tokens"`
41
CacheReadInputTokens *int `json:"cache_read_input_tokens"`
50
CacheReadInputTokens *int `json:"cache_read_input_tokens"`
42
OutputTokens int `json:"output_tokens"`
51
OutputTokens int `json:"output_tokens"`
43
}
52
}
44
53
45
type ErrorResponse struct {
54
type ErrorResponse struct {
46
Type string `json:"type"`
55
Type string `json:"type"`
47
Message string `json:"message"`
56
Message string `json:"message"`
48
}
57
}
49
58
50
type MessagesResponse struct {
59
type MessagesResponse struct {
51
Id string `json:"id"`
60
Id string `json:"id"`
52
Type string `json:"type"`
61
Type string `json:"type"`
53
Role string `json:"role"`
62
Role string `json:"role"`
54
Content []ContentBlock `json:"content"`
63
Content []ContentBlock `json:"content"`
55
Model string `json:"model"`
64
Model string `json:"model"`
56
StopReason string `json:"stop_reason"`
65
StopReason string `json:"stop_reason"`
57
StopSequence bool `json:"stop_sequence"`
66
StopSequence bool `json:"stop_sequence"`
58
Usage Usage `json:"usage"`
67
Usage Usage `json:"usage"`
59
Error *ErrorResponse `json:"error"`
68
Error *ErrorResponse `json:"error"`
60
}
69
}
61
70
62
type Tool struct {
71
type Tool struct {
63
Type string `json:"type"`
72
Type string `json:"type"`
64
Function *ToolFunction `json:"function"`
73
Function *ToolFunction `json:"function"`
65
}
74
}
66
75
67
type ToolFunction struct {
76
type ToolFunction struct {
68
Name string `json:"name"`
77
Name string `json:"name"`
69
Description string `json:"description"`
78
Description string `json:"description"`
70
InputSchema interface{} `json:"input_schema"`
79
InputSchema interface{} `json:"input_schema"`
71
}
80
}