Anthropic 프로바이더

Anthropic 프로바이더

Anthropic 프로바이더는 @ai-sdk/anthropic 모듈로 제공되며 Anthropic Messages API 언어 모델을 지원합니다. 기본 인스턴스 anthropic를 import하거나 createAnthropic로 커스터마이징한 인스턴스를 생성할 수 있습니다. 일부 모델은 멀티모달 입력을 지원합니다.

출처: 공식문서

본문

설치

pnpm add @ai-sdk/anthropic

프로바이더 인스턴스

기본 인스턴스:

import { anthropic } from '@ai-sdk/anthropic';

커스텀 인스턴스:

import { createAnthropic } from '@ai-sdk/anthropic';

const anthropic = createAnthropic({
  // custom settings
});

인스턴스 커스터마이징 옵션:

  • baseURL — API 호출 URL 프리픽스(프록시용). 기본값 https://api.anthropic.com/v1.
  • apiKeyx-api-key 헤더로 전송. 기본값 ANTHROPIC_API_KEY 환경변수. apiKeyauthToken 중 하나만 필요.
  • authTokenAuthorization: Bearer 헤더로 전송되는 토큰. 기본값 ANTHROPIC_AUTH_TOKEN 환경변수.
  • headers — 요청에 포함할 커스텀 헤더.
  • fetch — 커스텀 fetch 구현(기본 전역 fetch). 요청 가로채기·테스트용.

언어 모델

프로바이더 인스턴스로 Messages API를 호출하는 모델을 만듭니다. 첫 번째 인자는 모델 ID(예: claude-3-haiku-20240307):

const model = anthropic('claude-3-haiku-20240307');

모델 생성 별칭: anthropic.languageModel('...'), anthropic.chat('...'), anthropic.messages('...')(모두 languageModel의 별칭).

generateText로 텍스트 생성:

import { anthropic } from '@ai-sdk/anthropic';
import { generateText } from 'ai';

const { text } = await generateText({
  model: anthropic('claude-3-haiku-20240307'),
  prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});

Anthropic 모델은 streamText에서도 사용 가능하며 AI SDK Core의 Output으로 구조화 데이터 생성을 지원합니다.

모델 옵션

  • disableParallelToolUse — 병렬 도구 호출 비활성화(기본 false). true면 모델이 한 번에 하나의 도구만 호출.
  • sendReasoning — 추론(reasoning) 콘텐츠 전송 옵션. true로 설정하면 모델의 추론 과정을 스트리밍으로 받을 수 있습니다.

더 알아보기