Debian Codegraph @

examples/message/main.go

raw
1 package main
2
3 import (
4 "context"
5
6 "github.com/anthropics/anthropic-sdk-go"
7 )
8
9 func main() {
10 client := anthropic.NewClient()
11
12 content := "Write me a function to call the Anthropic message API in Node.js using the Anthropic Typescript SDK."
13
14 println("[user]: " + content)
15
16 message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
17 MaxTokens: 1024,
18 Messages: []anthropic.MessageParam{
19 anthropic.NewUserMessage(anthropic.NewTextBlock(content)),
20 },
21 Model: anthropic.ModelClaudeSonnet4_5_20250929,
22 StopSequences: []string{"```\n"},
23 })
24 if err != nil {
25 panic(err)
26 }
27
28 println("[assistant]: " + message.Content[0].Text + message.StopSequence)
29 }