파트너 플랫폼을 통해 Anthropic의 클라이언트 SDK를 사용하려면 추가 설정이 필요합니다. Amazon Bedrock을 사용하는 경우 이 가이드를 참조하시고, Google Cloud Vertex AI를 사용하는 경우 이 가이드를 참조하세요.

Python

Python 라이브러리 GitHub 저장소

예시:

Python
import anthropic

client = anthropic.Anthropic(
    # defaults to os.environ.get("ANTHROPIC_API_KEY")
    api_key="my_api_key",
)
message = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Hello, Claude"}
    ]
)
print(message.content)

TypeScript

TypeScript 라이브러리 GitHub 저장소

이 라이브러리는 TypeScript로 작성되었지만 JavaScript 라이브러리에서도 사용할 수 있습니다.

예시:

TypeScript
import Anthropic from '@anthropic-ai/sdk';

const anthropic = new Anthropic({
  apiKey: 'my_api_key', // defaults to process.env["ANTHROPIC_API_KEY"]
});

const msg = await anthropic.messages.create({
  model: "claude-3-5-sonnet-20241022",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hello, Claude" }],
});
console.log(msg);

Java

Java 라이브러리 GitHub 저장소

Anthropic Java SDK는 현재 베타 버전입니다. 문제가 발견되면 GitHub에 이슈를 제출해 주세요!

예시:

Java
import com.anthropic.models.Message;
import com.anthropic.models.MessageCreateParams;
import com.anthropic.models.Model;

MessageCreateParams params = MessageCreateParams.builder()
    .maxTokens(1024L)
    .addUserMessage("Hello, Claude")
    .model(Model.CLAUDE_3_5_SONNET_LATEST)
    .build();
Message message = client.messages().create(params);

Go

Go 라이브러리 GitHub 저장소

Anthropic Go SDK는 현재 알파 버전입니다. 문제가 발견되면 GitHub에 이슈를 제출해 주세요!

예시:

Go
package main

import (
	"context"
	"fmt"
	"github.com/anthropics/anthropic-sdk-go"
	"github.com/anthropics/anthropic-sdk-go/option"
)

func main() {
	client := anthropic.NewClient(
		option.WithAPIKey("my-anthropic-api-key"),
	)
	message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
		Model:     anthropic.F(anthropic.ModelClaude3_5SonnetLatest),
		MaxTokens: anthropic.F(int64(1024)),
		Messages: anthropic.F([]anthropic.MessageParam{
			anthropic.NewUserMessage(anthropic.NewTextBlock("What is a quaternion?")),
		}),
	})
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("%+v\n", message.Content)
}