v1

package module
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: May 17, 2025 License: MIT Imports: 11 Imported by: 7

README

claude-sdk-go

Go Reference Go Report Card

This is the unofficial Go SDK for the Anthropic Claude API.

It is designed with reference to the sashabaranov/go-openai.

Official Docs: https://docs.anthropic.com/claude/

Supported

  • /v1/messages
    • Text Message
    • Image Message
    • Streaming Messages
    • Thinking
    • Cache Control

Getting Started

go get github.com/potproject/claude-sdk-go

Example

Create a Message
package main

import (
	"context"
	"fmt"
	"os"

	claude "github.com/potproject/claude-sdk-go"
)

func main() {
	apiKey := os.Getenv("API_KEY")
	c := claude.NewClient(apiKey)
	m := claude.RequestBodyMessages{
		Model:     "claude-3-7-sonnet-20250219",
		MaxTokens: 1024,
		Messages: []claude.RequestBodyMessagesMessages{
			{
				Role:    claude.MessagesRoleUser,
				Content: "Hello, world!",
				// Alternatively, you can use ContentTypeText
				//
				// ContentTypeText: []claude.RequestBodyMessagesMessagesContentTypeText{
				// 	{
				// 		Text: "Hello, world!",
				// 	},
				// },
			},
		},
	}
	ctx := context.Background()
	res, err := c.CreateMessages(ctx, m)
	if err != nil {
		panic(err)
	}
	fmt.Println(res.Content[0].Text)
	// Output:
	// Hello! How can I assist you today?
}

Create a Message(Use Cache)
Create a Message(Use Cache)
	apiKey := os.Getenv("API_KEY")
	c := claude.NewClient(apiKey)
	m := claude.RequestBodyMessages{
		Model:     "claude-3-7-sonnet-20250219",
		MaxTokens: 1024,
		SystemTypeText: []claude.RequestBodySystemTypeText{
			claude.UseSystemCacheEphemeral("Please speak in Japanese."),
		},
		Messages: []claude.RequestBodyMessagesMessages{
			{
				Role: claude.MessagesRoleUser,
				ContentTypeText: []claude.RequestBodyMessagesMessagesContentTypeText{
					{
						Text:         "Hello!",
						CacheControl: claude.UseCacheEphemeral(),
					},
				},
			},
		},
	}
	ctx := context.Background()
	res, err := c.CreateMessages(ctx, m)
	if err != nil {
		panic(err)
	}
	fmt.Println(res.Content[0].Text)
	// Output:
	// こんにちは!日本語でお話しましょう。

Create a Streaming Message
Create a Streaming Message
package main

import (
	"context"
	"errors"
	"fmt"
	"io"
	"os"

	claude "github.com/potproject/claude-sdk-go"
)

func main() {
	apiKey := os.Getenv("API_KEY")
	c := claude.NewClient(apiKey)
	m := claude.RequestBodyMessages{
		Model:     "claude-3-7-sonnet-20250219",
		MaxTokens: 1024,
		Messages: []claude.RequestBodyMessagesMessages{
			{
				Role:    claude.MessagesRoleUser,
				Content: "Hello, world!",
			},
		},
	}
	ctx := context.Background()
	stream, err := c.CreateMessagesStream(ctx, m)
	if err != nil {
		panic(err)
	}
	defer stream.Close()
	for {
		res, err := stream.Recv()
		if errors.Is(err, io.EOF) {
			break
		}
		if err != nil {
			panic(err)
		}
		fmt.Printf("%s", res.Content[0].Text)
	}
	fmt.Println()
	// Output:
	// Hello! How can I assist you today?
	//
}

Create a Message with Image
Create a Message with Image
package main

import (
	"context"
	"fmt"
	"os"

	claude "github.com/potproject/claude-sdk-go"
)

func main() {
	apiKey := os.Getenv("API_KEY")
	c := claude.NewClient(apiKey)
	m := claude.RequestBodyMessages{
		Model:     "claude-3.7-sonnet-20250219",
		MaxTokens: 1024,
		Messages: []claude.RequestBodyMessagesMessages{
			{
				Role: claude.MessagesRoleUser,
				ContentTypeImage: []claude.RequestBodyMessagesMessagesContentTypeImage{
					{
						Source: claude.TypeImageSourceLoadBase64("image/png", "iVBORw0K..."), // Media Type, Base64 String
						CacheControl: claude.UseCacheEphemeral(), // Use Propmt Caching. optional
					},
				},
			},
		},
	}
	ctx := context.Background()
	res, err := c.CreateMessages(ctx, m)
	if err != nil {
		panic(err)
	}
	fmt.Println(res.Content[0].Text)
}

Create a Message with Image(Load File)
Create a Message with Image(Load File)
package main

import (
	"context"
	"fmt"
	"os"

	claude "github.com/potproject/claude-sdk-go"
)

func main() {
	apiKey := os.Getenv("API_KEY")
	c := claude.NewClient(apiKey)
	source, err := claude.TypeImageSourceLoadFile("image.png")
	if err != nil {
		panic(err)
	}
	m := claude.RequestBodyMessages{
		Model:     "claude-3-7-sonnet-20250219",
		MaxTokens: 1024,
		Messages: []claude.RequestBodyMessagesMessages{
			{
				Role: claude.MessagesRoleUser,
				ContentTypeImage: []claude.RequestBodyMessagesMessagesContentTypeImage{
					{
						Source: source,
					},
				},
			},
		},
	}
	ctx := context.Background()
	res, err := c.CreateMessages(ctx, m)
	if err != nil {
		panic(err)
	}
	fmt.Println(res.Content[0].Text)
}

Create a Message with Image(Load URL)
Create a Message with Image(Load URL)
package main

import (
	"context"
	"fmt"
	"os"

	claude "github.com/potproject/claude-sdk-go"
)

func main() {
	apiKey := os.Getenv("API_KEY")
	c := claude.NewClient(apiKey)
	m := claude.RequestBodyMessages{
		Model:     "claude-3-7-sonnet-20250219",
		MaxTokens: 1024,
		Messages: []claude.RequestBodyMessagesMessages{
			{
				Role: claude.MessagesRoleUser,
				ContentTypeImage: []claude.RequestBodyMessagesMessagesContentTypeImage{
					{
						Source: claude.TypeImageSourceLoadUrl("https://github.com/potproject/claude-sdk-go/blob/main/example/messages_image_file/image.png?raw=true"),
					},
				},
			},
		},
	}
	ctx := context.Background()
	res, err := c.CreateMessages(ctx, m)
	if err != nil {
		panic(err)
	}
	fmt.Println(res.Content[0].Text)
}

Create a Message (Use Thinking)
Create a Message (Use Thinking)
package main

import (
	"context"
	"fmt"
	"os"

	claude "github.com/potproject/claude-sdk-go"
)

func main() {
	apiKey := os.Getenv("API_KEY")
	c := claude.NewClient(apiKey)
	m := claude.RequestBodyMessages{
		Model:     "claude-3-7-sonnet-20250219",
		MaxTokens: 8192,
		Thinking:  claude.UseThinking(4096),
		Messages: []claude.RequestBodyMessagesMessages{
			{
				Role:    claude.MessagesRoleUser,
				Content: "Hello, world!",
			},
		},
	}
	ctx := context.Background()
	res, err := c.CreateMessages(ctx, m)
	if err != nil {
		panic(err)
	}

	// Output:
	// [thinking] This is a simple "Hello, world!" greeting from the user. It's a common first phrase in programming and also a standard greeting in conversations with AI assistants. I should respond in a friendly and welcoming manner.
	// [text] Hi there! It's nice to meet you. "Hello, world!" is such a classic greeting - it brings back memories of first programming lessons for many! How are you doing today? Is there something specific I can help you with?
	for _, v := range res.Content {
		if v.Type == claude.ResponseBodyMessagesContentTypeThinking {
			fmt.Println("[thinking]", v.Thinking)
		}
		if v.Type == claude.ResponseBodyMessagesContentTypeText {
			fmt.Println("[text]", v.Text)
		}
	}
}

Create a Streaming Message (Use Thinking)
Create a Streaming Message (Use Thinking)
package main

import (
	"context"
	"errors"
	"fmt"
	"io"
	"os"

	claude "github.com/potproject/claude-sdk-go"
)

func main() {
	apiKey := os.Getenv("API_KEY")
	c := claude.NewClient(apiKey)
	m := claude.RequestBodyMessages{
		Model:     "claude-3-7-sonnet-20250219",
		MaxTokens: 8192,
		Thinking:  claude.UseThinking(4096),
		Messages: []claude.RequestBodyMessagesMessages{
			{
				Role:    claude.MessagesRoleUser,
				Content: "Guess the Earth's population in 2100",
			},
		},
	}
	ctx := context.Background()
	stream, err := c.CreateMessagesStream(ctx, m)
	if err != nil {
		panic(err)
	}
	defer stream.Close()
	streamType := ""
	for {
		res, err := stream.Recv()
		if errors.Is(err, io.EOF) {
			break
		}
		if err != nil {
			panic(err)
		}
		if res.Content[0].Type == claude.ResponseBodyMessagesContentTypeThinking && streamType != claude.ResponseBodyMessagesContentTypeThinking {
			fmt.Println("[thinking]")
			streamType = claude.ResponseBodyMessagesContentTypeThinking
		}
		if res.Content[0].Type == claude.ResponseBodyMessagesContentTypeText && streamType != claude.ResponseBodyMessagesContentTypeText {
			fmt.Println()
			fmt.Println("[text]")
			streamType = claude.ResponseBodyMessagesContentTypeText
		}

		fmt.Printf("%s", res.Content[0].Thinking)
		fmt.Printf("%s", res.Content[0].Text)
	}
	fmt.Println()
}


LICENSE

MIT

Documentation

Overview

Example
package main

import (
	"context"
	"fmt"
	"os"

	claude "github.com/potproject/claude-sdk-go"
)

func main() {
	apiKey := os.Getenv("API_KEY")
	c := claude.NewClient(apiKey)
	m := claude.RequestBodyMessages{
		Model:     "claude-3-7-sonnet-20250219",
		MaxTokens: 1024,
		Messages: []claude.RequestBodyMessagesMessages{
			{
				Role:    claude.MessagesRoleUser,
				Content: "Hello, world!",
			},
		},
	}
	ctx := context.Background()
	res, err := c.CreateMessages(ctx, m)
	if err != nil {
		panic(err)
	}
	fmt.Println(res.Content[0].Text)
}
Output:

Hello! How can I assist you today?
Example (Cache)
package main

import (
	"context"
	"fmt"
	"os"

	claude "github.com/potproject/claude-sdk-go"
)

func main() {
	apiKey := os.Getenv("API_KEY")
	c := claude.NewClient(apiKey)
	m := claude.RequestBodyMessages{
		Model:     "claude-3-7-sonnet-20250219",
		MaxTokens: 1024,
		SystemTypeText: []claude.RequestBodySystemTypeText{
			claude.UseSystemCacheEphemeral("Please speak in Japanese."),
		},
		Messages: []claude.RequestBodyMessagesMessages{
			{
				Role: claude.MessagesRoleUser,
				ContentTypeText: []claude.RequestBodyMessagesMessagesContentTypeText{
					{
						Text:         "Hello!",
						CacheControl: claude.UseCacheEphemeral(),
					},
				},
			},
		},
	}
	ctx := context.Background()
	res, err := c.CreateMessages(ctx, m)
	if err != nil {
		panic(err)
	}
	fmt.Println(res.Content[0].Text)
}
Output:

こんにちは!日本語でお話しましょう。
Example (Stream)
package main

import (
	"context"
	"errors"
	"fmt"
	"io"
	"os"

	claude "github.com/potproject/claude-sdk-go"
)

func main() {
	apiKey := os.Getenv("API_KEY")
	c := claude.NewClient(apiKey)
	m := claude.RequestBodyMessages{
		Model:     "claude-3-7-sonnet-20250219",
		MaxTokens: 1024,
		Messages: []claude.RequestBodyMessagesMessages{
			{
				Role:    claude.MessagesRoleUser,
				Content: "Hello, world!",
			},
		},
	}
	ctx := context.Background()
	stream, err := c.CreateMessagesStream(ctx, m)
	if err != nil {
		panic(err)
	}
	defer stream.Close()
	for {
		res, err := stream.Recv()
		if errors.Is(err, io.EOF) {
			break
		}
		if err != nil {
			panic(err)
		}
		fmt.Printf("%s", res.Content[0].Text)
	}
	fmt.Println()
}
Output:

Hello! How can I assist you today?
Example (Thinking)
package main

import (
	"context"
	"fmt"
	"os"

	claude "github.com/potproject/claude-sdk-go"
)

func main() {
	apiKey := os.Getenv("API_KEY")
	c := claude.NewClient(apiKey)
	m := claude.RequestBodyMessages{
		Model:     "claude-3-7-sonnet-20250219",
		MaxTokens: 8192,
		Thinking:  claude.UseThinking(4096),
		Messages: []claude.RequestBodyMessagesMessages{
			{
				Role:    claude.MessagesRoleUser,
				Content: "Hello, world!",
			},
		},
	}
	ctx := context.Background()
	res, err := c.CreateMessages(ctx, m)
	if err != nil {
		panic(err)
	}

	for _, v := range res.Content {
		if v.Type == claude.ResponseBodyMessagesContentTypeThinking {
			fmt.Println("[thinking]", v.Thinking)
		}
		if v.Type == claude.ResponseBodyMessagesContentTypeText {
			fmt.Println("[text]", v.Text)
		}
	}
}
Output:

[thinking] This is a simple "Hello, world!" greeting from the user. It's a common first phrase in programming and also a standard greeting in conversations with AI assistants. I should respond in a friendly and welcoming manner.
[text] Hi there! It's nice to meet you. "Hello, world!" is such a classic greeting - it brings back memories of first programming lessons for many! How are you doing today? Is there something specific I can help you with?
Example (Thinking_stream)
package main

import (
	"context"
	"errors"
	"fmt"
	"io"
	"os"

	claude "github.com/potproject/claude-sdk-go"
)

func main() {
	apiKey := os.Getenv("API_KEY")
	c := claude.NewClient(apiKey)
	m := claude.RequestBodyMessages{
		Model:     "claude-3-7-sonnet-20250219",
		MaxTokens: 8192,
		Thinking:  claude.UseThinking(4096),
		Messages: []claude.RequestBodyMessagesMessages{
			{
				Role:    claude.MessagesRoleUser,
				Content: "Guess the Earth's population in 2100",
			},
		},
	}
	ctx := context.Background()
	stream, err := c.CreateMessagesStream(ctx, m)
	if err != nil {
		panic(err)
	}
	defer stream.Close()
	streamType := ""
	for {
		res, err := stream.Recv()
		if errors.Is(err, io.EOF) {
			break
		}
		if err != nil {
			panic(err)
		}
		if res.Content[0].Type == claude.ResponseBodyMessagesContentTypeThinking && streamType != claude.ResponseBodyMessagesContentTypeThinking {
			fmt.Println("[thinking]")
			streamType = claude.ResponseBodyMessagesContentTypeThinking
		}
		if res.Content[0].Type == claude.ResponseBodyMessagesContentTypeText && streamType != claude.ResponseBodyMessagesContentTypeText {
			fmt.Println()
			fmt.Println("[text]")
			streamType = claude.ResponseBodyMessagesContentTypeText
		}

		fmt.Printf("%s", res.Content[0].Thinking)
		fmt.Printf("%s", res.Content[0].Text)
	}
	fmt.Println()
	
Example (TypeImage)
package main

import (
	"context"
	"fmt"
	"os"

	claude "github.com/potproject/claude-sdk-go"
)

func main() {
	apiKey := os.Getenv("API_KEY")
	c := claude.NewClient(apiKey)
	m := claude.RequestBodyMessages{
		Model:     "claude-3-7-sonnet-20250219",
		MaxTokens: 1024,
		Messages: []claude.RequestBodyMessagesMessages{
			{
				Role: claude.MessagesRoleUser,
				ContentTypeImage: []claude.RequestBodyMessagesMessagesContentTypeImage{
					{
						Source: claude.TypeImageSourceLoadBase64("image/png", "iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAIAAADTED8xAAADMElEQVR4nOzVwQnAIBQFQYXff81RUkQCOyDj1YOPnbXWPmeTRef+/3O/OyBjzh3CD95BfqICMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMO0TAAD//2Anhf4QtqobAAAAAElFTkSuQmCC"),
					},
				},
			},
		},
	}
	ctx := context.Background()
	res, err := c.CreateMessages(ctx, m)
	if err != nil {
		panic(err)
	}
	fmt.Println(res.Content[0].Text)
}
Output:

The image shows a smooth gradient transitioning from a bright, vibrant orange at the bottom to a light blue at the top. The colors blend seamlessly into each other, creating a visually striking and aesthetically pleasing effect. The simplicity of the gradient allows the colors to be the main focus, showcasing their luminosity and the way they interact with one another. This type of gradient is often used as a background or design element to add depth, warmth, and visual interest to various digital or print media projects.

Index

Examples

Constants

View Source
const (
	RequestBodyMessagesMessagesContentTypeTextType  = "text"
	RequestBodyMessagesMessagesContentTypeImageType = "image"
)
View Source
const (
	RequestBodyMessagesMessagesContentTypeImageSourceTypeBase64 = "base64"
	RequestBodyMessagesMessagesContentTypeImageSourceTypeUrl    = "url"
)
View Source
const (
	MessagesRoleUser      = "user"
	MessagesRoleAssistant = "assistant"
)
View Source
const (
	ResponseBodyMessagesContentTypeMessage  = "message"
	ResponseBodyMessagesContentTypeText     = "text"
	ResponseBodyMessagesContentTypeThinking = "thinking"
)
View Source
const (
	MessagesStreamResponseTypeMessageStart      = "message_start"
	MessagesStreamResponseTypeContentBlockStart = "content_block_start"
	MessagesStreamResponseTypePing              = "ping"
	MessagesStreamResponseTypeContentBlockDelta = "content_block_delta"
	MessagesStreamResponseTypeContentBlockStop  = "content_block_stop"
	MessagesStreamResponseTypeMessageDelta      = "message_delta"
	MessagesStreamResponseTypeMessageStop       = "message_stop"
	MessagesStreamResponseTypeError             = "error"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(apiKey string) *Client

func NewClientWithConfig

func NewClientWithConfig(config ClientConfig) *Client

func (*Client) CreateMessages

func (c *Client) CreateMessages(ctx context.Context, body RequestBodyMessages) (*ResponseBodyMessages, error)

func (*Client) CreateMessagesStream added in v1.1.0

func (c *Client) CreateMessagesStream(ctx context.Context, body RequestBodyMessages) (*CreateMessagesStream, error)

func (*Client) SetVersion

func (c *Client) SetVersion(version string)

type ClientConfig

type ClientConfig struct {
	ApiKey string

	Version string
	Beta    string // Using Beta API : anthropic-beta Header

	BaseURL    string
	Endpoint   string
	HTTPClient *http.Client
}

type CreateMessagesStream added in v1.1.0

type CreateMessagesStream struct {
	Connection                 *sse.Connection
	Unsubscribe                func()
	Event                      chan sse.Event
	Error                      chan error
	ResponseBodyMessagesStream ResponseBodyMessagesStream
}

func (*CreateMessagesStream) Close added in v1.1.0

func (c *CreateMessagesStream) Close()

func (*CreateMessagesStream) Recv added in v1.1.0

type RequestBodyMessages

type RequestBodyMessages struct {
	Model          string                        `json:"model"`
	Messages       []RequestBodyMessagesMessages `json:"messages"`
	System         string                        `json:"-"`
	SystemTypeText []RequestBodySystemTypeText   `json:"-"`
	SystemRaw      interface{}                   `json:"system,omitempty"` // optional
	MaxTokens      int                           `json:"max_tokens"`
	Thinking       *RequestBodyMessagesThinking  `json:"thinking,omitempty"`    // optional
	MetaData       map[string]interface{}        `json:"metadata"`              // optional
	StopSequences  []string                      `json:"stop_sequences"`        // optional
	Stream         bool                          `json:"stream"`                // optional
	Temperature    float64                       `json:"temperature,omitempty"` // optional
	TopP           float64                       `json:"top_p,omitempty"`       // optional
	TopK           float64                       `json:"top_k,omitempty"`       // optional
}

type RequestBodyMessagesMessages

type RequestBodyMessagesMessages struct {
	Role             string                                        `json:"role"`
	ContentRaw       interface{}                                   `json:"content"`
	Content          string                                        `json:"-"`
	ContentTypeText  []RequestBodyMessagesMessagesContentTypeText  `json:"-"`
	ContentTypeImage []RequestBodyMessagesMessagesContentTypeImage `json:"-"`
}

type RequestBodyMessagesMessagesContentTypeImage

type RequestBodyMessagesMessagesContentTypeImage struct {
	Type         string                                            `json:"type"` // always "image"
	Source       RequestBodyMessagesMessagesContentTypeImageSource `json:"source"`
	CacheControl *RequestCacheControl                              `json:"cache_control"` // optional
}

type RequestBodyMessagesMessagesContentTypeImageSource

type RequestBodyMessagesMessagesContentTypeImageSource struct {
	Type      string `json:"type"`                 // "base64" or "url"
	MediaType string `json:"media_type,omitempty"` // base64 type required
	Data      string `json:"data,omitempty"`       // base64 type required
	Url       string `json:"url,omitempty"`        // url type required
}

func TypeImageSourceLoadBase64 added in v1.3.2

func TypeImageSourceLoadBase64(mediaType string, data string) RequestBodyMessagesMessagesContentTypeImageSource

func TypeImageSourceLoadFile added in v1.1.3

func TypeImageSourceLoadFile(filePath string) (RequestBodyMessagesMessagesContentTypeImageSource, error)

func TypeImageSourceLoadUrl added in v1.3.1

type RequestBodyMessagesMessagesContentTypeText

type RequestBodyMessagesMessagesContentTypeText struct {
	Type         string               `json:"type"` // always "text"
	Text         string               `json:"text"`
	CacheControl *RequestCacheControl `json:"cache_control"` // optional
}

type RequestBodyMessagesThinking added in v1.3.0

type RequestBodyMessagesThinking struct {
	Type         string `json:"type"`
	BudgetTokens int    `json:"budget_tokens"`
}

func UseThinking added in v1.3.0

func UseThinking(budgetTokens int) *RequestBodyMessagesThinking

type RequestBodySystemTypeText added in v1.3.0

type RequestBodySystemTypeText struct {
	Type         string               `json:"type"` // always "text"
	Text         string               `json:"text"`
	CacheControl *RequestCacheControl `json:"cache_control"`
}

func UseSystemCacheEphemeral added in v1.3.0

func UseSystemCacheEphemeral(text string) RequestBodySystemTypeText

func UseSystemNoCache added in v1.3.0

func UseSystemNoCache(text string) RequestBodySystemTypeText

type RequestCacheControl added in v1.3.0

type RequestCacheControl struct {
	Type string `json:"type"` // always "ephemeral"
}

func UseCacheEphemeral added in v1.3.0

func UseCacheEphemeral() *RequestCacheControl

func UseNoCache added in v1.3.0

func UseNoCache() *RequestCacheControl

type ResponseBodyMessages

type ResponseBodyMessages struct {
	Id           string                        `json:"id"`
	Type         string                        `json:"type"` // always "message"
	Role         string                        `json:"role"` // always "assistant"
	Content      []ResponseBodyMessagesContent `json:"content"`
	Model        string                        `json:"model"`
	StopReason   string                        `json:"stop_reason"` // "end_turn" or "max_tokens", "stop_sequence", null
	StopSequence string                        `json:"stop_sequence"`
	Usage        struct {
		InputTokens  int64 `json:"input_tokens"`
		OutputTokens int64 `json:"output_tokens"`
	} `json:"usage"`
}

type ResponseBodyMessagesContent

type ResponseBodyMessagesContent struct {
	Type     string `json:"type"`
	Text     string `json:"text"`
	Thinking string `json:"thinking"`
}

type ResponseBodyMessagesContentStream added in v1.1.0

type ResponseBodyMessagesContentStream struct {
	Type     string `json:"type"`
	Text     string `json:"text"`
	Thinking string `json:"thinking"`
}

type ResponseBodyMessagesStream added in v1.1.0

type ResponseBodyMessagesStream struct {
	Id           string                              `json:"id"`
	Type         string                              `json:"type"` // always "message"
	Role         string                              `json:"role"` // always "assistant"
	Content      []ResponseBodyMessagesContentStream `json:"content"`
	Model        string                              `json:"model"`
	StopReason   string                              `json:"stop_reason"` // "end_turn" or "max_tokens", "stop_sequence", null
	StopSequence string                              `json:"stop_sequence"`
	Usage        struct {
		InputTokens  int64 `json:"input_tokens"`
		OutputTokens int64 `json:"output_tokens"`
	} `json:"usage"`
}

type ResponseContentBlockDeltaStream added in v1.1.0

type ResponseContentBlockDeltaStream struct {
	Type  string `json:"type"`
	Index int64  `json:"index"`
	Delta struct {
		Type     string `json:"type"`
		Text     string `json:"text"`
		Thinking string `json:"thinking"`
	} `json:"delta"`
}

type ResponseContentMessageStartStream added in v1.1.0

type ResponseContentMessageStartStream struct {
	Type    string                     `json:"type"`
	Message ResponseBodyMessagesStream `json:"message"`
}

type ResponseError

type ResponseError struct {
	Error struct {
		Message string `json:"message"`
	} `json:"error"`
}

type ResponseMessageDeltaStream added in v1.1.0

type ResponseMessageDeltaStream struct {
	Type  string `json:"type"`
	Delta struct {
		StopReason   string `json:"stop_reason"`
		StopSequence string `json:"stop_sequence"`
	} `json:"delta"`
	Usage struct {
		OutputTokens int64 `json:"output_tokens"`
	} `json:"usage"`
}

Directories

Path Synopsis
example
messages Module

Jump to

Keyboard shortcuts

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