Source: https://aiprimetech.io/ko/learn/use-claude-api-with-vercel-ai-sdk/ [홈](/ko/) / [학습](/ko/learn/) / Vercel AI SDK로 Claude 사용하기: createAnthropic baseURL, 스트리밍 및 문제 해결 # Vercel AI SDK로 Claude 사용하기: createAnthropic baseURL, 스트리밍 및 문제 해결 AI SDK의 Anthropic 제공업체인 @ai-sdk/anthropic는 Messages API와 통신합니다. 이 제공업체의 baseURL 기본값은 https://api.anthropic.com/v1이므로 게이트웨이를 사용할 때는 다음을 포함한 전체 접두사를 교체해야 합니다: /v1. OpenCode, Kilo Code 및 여러 에이전트 프레임워크도 내부적으로 같은 제공업체를 사용하므로 해당 구성에도 같은 규칙이 적용됩니다. ## 설치 터미널복사 ``` npm i ai @ai-sdk/anthropic ``` ## 제공업체 생성 lib/anthropic.ts복사 ``` import { createAnthropic } from '@ai-sdk/anthropic'; export const anthropic = createAnthropic({ baseURL: 'https://aiprimetech.io/v1', // replaces https://api.anthropic.com/v1 apiKey: process.env.AIPRIME_API_KEY, // sent as x-api-key; defaults to ANTHROPIC_API_KEY }); ``` 다음에는 기본 URL용 환경 변수가 없습니다: @ai-sdk/anthropic. 다음을 전달하세요: baseURL 코드에서 전달해야 합니다. 일반적인 anthropic 가져오기는 항상 Anthropic 자체 엔드포인트를 대상으로 합니다. ## generateText 및 streamText generate.ts복사 ``` import { generateText } from 'ai'; import { anthropic } from './lib/anthropic'; const { text, usage } = await generateText({ model: anthropic('claude-sonnet-5'), prompt: 'Explain idempotency keys in two sentences.', }); console.log(text, usage); ``` stream.ts복사 ``` import { streamText } from 'ai'; import { anthropic } from './lib/anthropic'; const result = streamText({ model: anthropic('claude-sonnet-5'), prompt: 'Write a haiku about load balancers.', }); for await (const chunk of result.textStream) process.stdout.write(chunk); ``` 두 호출 모두 다음을 지원합니다: maxRetries (2이 기본값)이며, 429 및 5xx 같은 일시적인 오류에 사용됩니다. ## 사고 및 프롬프트 캐싱 Anthropic 전용 옵션은 다음에 지정합니다: providerOptions.anthropic. 최신 모델은 적응형 사고를 사용합니다: thinking.ts복사 ``` const { text } = await generateText({ model: anthropic('claude-sonnet-5'), providerOptions: { anthropic: { thinking: { type: 'adaptive' } } }, prompt: 'Plan a zero-downtime database migration in five steps.', }); ``` 길고 내용이 잘 바뀌지 않는 시스템 프롬프트는 다음으로 캐시하세요: cacheControl; 이후 캐시 읽기는 다음에 표시됩니다: usage.inputTokenDetails.cacheReadTokens. 모델의 최소 길이보다 짧은 프롬프트는 캐시되지 않습니다. cache.ts복사 ``` const result = await generateText({ model: anthropic('claude-sonnet-5'), messages: [ { role: 'system', content: longStableInstructions, providerOptions: { anthropic: { cacheControl: { type: 'ephemeral' } } }, }, { role: 'user', content: question }, ], }); ``` ## OpenAI 호환 대안 게이트웨이는 OpenAI Chat Completions 형식도 제공하므로 @ai-sdk/openai-compatible 도 동일한 /v1 기본 URL에서 작동합니다. 이는 같은 키로 GPT 모델을 사용하는 경로입니다. Claude의 경우 위의 네이티브 제공업체를 사용하면 사고 및 캐시 제어 기능을 유지할 수 있습니다. lib/gateway.ts복사 ``` import { createOpenAICompatible } from '@ai-sdk/openai-compatible'; const gateway = createOpenAICompatible({ name: 'aiprime', baseURL: 'https://aiprimetech.io/v1', apiKey: process.env.AIPRIME_API_KEY, }); // gateway('claude-sonnet-5') or a GPT model ID ``` ## 문제 해결 | 표시되는 내용 | 원인 | 해결 방법 | JSON 파싱 오류, 응답이 다음으로 시작함: < | baseURL 없이 /v1: 요청이 웹사이트에 도달했습니다 | baseURL: 'https://aiprimetech.io/v1' | 404 page not found | /v1 두 번 | 정확히 하나의 /v1 | Invalid API key | process.env 값이 해당 런타임에서 정의되지 않아(서버리스 및 에지 함수에는 자체 환경이 있습니다) SDK가 다음을 기본값으로 사용했습니다: ANTHROPIC_API_KEY | 배포 환경에 변수를 설정하세요 | 지원되지 않는 모델 | 오래되었거나 철자가 틀린 모델 ID | 아래 표의 ID를 사용하세요. | Concurrency limit exceeded for user | Promise.all 큰 배열 전체에 대해 | 예를 들어 다음을 사용하여 병렬 호출 수를 제한하세요: p-limit | No available accounts / 503 | 일시적인 업스트림 용량 문제 | 자동으로 재시도됩니다. 다음 값을 높이세요: maxRetries | 모델 ID | 권장 용도 | claude-sonnet-5 | 코딩과 에이전트 작업의 기본 선택: 빠르고 성능이 뛰어나며 가격은 중간 수준입니다. | claude-opus-5-5 | 더 어려운 추론, 대규모 리팩터링, 장시간 에이전트 실행. | claude-fable-5-1 | 성능이 가장 뛰어나고 가격도 가장 높습니다. 가장 어려운 작업에 사용하세요. | claude-haiku-4-5 | 저렴하고 빠름: 제목, 요약, 분류, 간단한 단계. ## 자주 묻는 질문 @ai-sdk/anthropic의 기본 baseURL은 무엇인가요? https://api.anthropic.com/v1. 게이트웨이는 전체 접두사를 교체하므로 /v1로 끝나야 합니다. 예: https://aiprimetech.io/v1. AI SDK Anthropic 기본 URL용 환경 변수가 있나요? 아니요. 제공업체는 환경에서 ANTHROPIC_API_KEY(또는 ANTHROPIC_AUTH_TOKEN)을 읽지만, 기본 URL은 createAnthropic({ baseURL })로 설정합니다. AI SDK로 Claude를 호출할 때 파싱 오류가 발생하는 이유는 무엇인가요? 보통 baseURL에 /v1이 빠져 있어 요청이 웹사이트에 도달하고 JSON 대신 HTML을 반환받기 때문입니다. Claude에는 @ai-sdk/anthropic과 @ai-sdk/openai-compatible 중 어느 것을 사용해야 하나요? @ai-sdk/anthropic을 사용하세요. 네이티브 Messages API로 통신하므로 사고 및 프롬프트 캐싱이 작동합니다. GPT 모델에는 OpenAI 호환 제공업체를 사용하세요. 몇 분 만에 Claude 사용 시작하기 API 키를 발급받으세요 — Anthropic 계정이나 대기자 명단 등록이 필요하지 않습니다.[API 키 발급받기](/register) AI Prime Tech는 독립적인 API 게이트웨이입니다. Anthropic과 제휴 관계가 없으며, Anthropic의 보증을 받거나 Anthropic의 리셀러로 활동하지 않습니다. Claude 및 관련 모델 이름은 각 소유자의 상표입니다. ## 더 많은 Claude API 가이드 [Claude API 키 발급 방법](/ko/learn/how-to-get-a-claude-api-key/)[Claude API 요금 해설](/ko/learn/claude-api-pricing-explained/)[Claude API를 가장 저렴하게 사용하는 방법](/ko/learn/cheapest-way-to-use-claude-api/)[Claude API로 Cursor 무제한 사용](/learn/use-claude-api-with-cursor/)[Claude Code 무제한 이용](/ko/learn/use-claude-api-with-claude-code/)[Claude API 게이트웨이와 Anthropic 직접 이용 비교](/ko/learn/claude-api-vs-anthropic-direct/)[OpenAI 호환 API를 통해 Claude 사용하기](/ko/learn/openai-compatible-claude-api/)[Claude 모델 해설: Claude Opus, Sonnet, Haiku, Fable 비교 — 모든 Claude API 모델, Anthropic 모델 이름 및 가격 (2026)](/ko/learn/claude-api-models-compared/)[암호화폐로 Claude API 요금 결제하기](/ko/learn/claude-api-with-crypto-payment/)[대기 명단 없이 Claude API 이용하기](/ko/learn/claude-api-without-waitlist/)[Claude 토큰 사용량을 줄이는 방법](/ko/learn/how-to-reduce-claude-token-usage/)[Claude API로 Cline 무제한 사용](/ko/learn/use-claude-api-with-cline/)[Claude API로 Roo Code 무제한 사용](/ko/learn/use-claude-api-with-roo-code/)[JetBrains IDE에서 Claude 무제한 사용](/ko/learn/use-claude-api-with-jetbrains/)[Claude API로 Aider 무제한 사용하기](/ko/learn/use-claude-api-with-aider/)[VS Code에서 Claude 무제한 사용](/ko/learn/use-claude-api-with-vscode/)[Claude용 OpenCode 구성: opencode.json 설정, 모델 및 일반적인 오류](/ko/learn/use-claude-api-with-opencode/)[Claude에서 Hermes 에이전트 무제한 실행하기](/ko/learn/run-hermes-agent-with-claude-api/)[Claude에서 OpenClaw 무제한 실행하기](/ko/learn/run-openclaw-with-claude-api/)[Anthropic 호환 API의 의미](/ko/learn/anthropic-compatible-api/)[Claude Code API 키 — ANTHROPIC_API_KEY: 발급 및 설정 방법과 대신 claude setup-token을 사용해야 하는 경우](/ko/learn/claude-code-api-key-setup/)[Claude Code API 비용 — 요금과 절감 방법](/ko/learn/claude-code-api-costs/)[Claude API 오류 설명: 서버 오류 500, 과부하 529, 사용량 제한 429, 잘못된 요청 400 — 각 오류의 해결 방법](/ko/learn/claude-api-errors-troubleshooting/)[Claude API 크레딧 구매 방법 — 그리고 Claude 크레딧이 어떤 "Claude 계정 구매" 상품보다 나은 이유](/ko/learn/buy-claude-api-credits/)[Claude 무료 API: 무료 Claude API 키가 있나요? 2026년에 실제로 무료인 것은 무엇인가요?](/ko/learn/claude-api-free-trial/)[Claude API와 Claude Pro/Max 구독 — 어떤 것을 선택할까요](/ko/learn/claude-api-vs-subscription/)[Claude에서 Codex CLI 실행하기](/ko/learn/use-claude-api-with-codex/)[Claude를 n8n에 연결하기](/ko/learn/use-claude-api-with-n8n/)[LiteLLM을 Claude로 라우팅하기](/ko/learn/use-claude-api-with-litellm/)[Kilo Code에서 Claude 사용하기](/ko/learn/use-claude-api-with-kilo-code/)[GitHub Copilot에 Claude 연결하기](/ko/learn/use-claude-api-with-github-copilot/)[게이트웨이를 통해 Zed를 Claude에 연결하기](/ko/learn/use-claude-api-with-zed/)[Cherry Studio를 Claude에 연결하기](/ko/learn/use-claude-api-with-cherry-studio/)[LangChain의 ChatAnthropic: 가져오기, base_url, 스트리밍, 도구 및 오류](/ko/learn/use-claude-api-with-langchain/)[Anthropic Python SDK: 설치, base_url 설정, 스트리밍 및 오류 처리](/ko/learn/anthropic-python-sdk/)[Claude로 Factory Droid 실행하기](/ko/learn/use-claude-api-with-factory-droid/)[Claude Code API 이해하기](/ko/learn/claude-code-api/)[애플리케이션에 Claude API 통합하기](/ko/learn/claude-api-integration/)[Claude를 무제한으로 사용하는 방법 — 그리고 "Claude Code 크랙 버전"이 없는 이유](/ko/learn/get-unlimited-claude-usage/)