Claude 모델을 사용하여 예측 요청

Anthropic SDK 또는 curl 명령어를 사용하여 다음 모델 이름으로 Gemini Enterprise Agent Platform 엔드포인트에 요청을 보낼 수 있습니다.

  • Google Cloud의 Claude Sonnet 5.5의 경우 claude-sonnet-5-5 사용
  • Google Cloud의 Claude Fable 5.1의 경우 claude-fable-5-1 사용
  • Google Cloud의 Claude Sonnet 5의 경우 claude-sonnet-5 사용
  • Google Cloud의 Claude Opus 5.5의 경우 claude-opus-5-5 사용
  • Google Cloud의 Claude Opus 5의 경우 claude-opus-5 사용
  • Google Cloud의 Claude Fable 5의 경우 claude-fable-5 사용
  • Google Cloud의 Claude Opus 4.8의 경우 claude-opus-4-8 사용
  • Google Cloud 기반 Claude Opus 4.7의 경우 claude-opus-4-7 사용
  • Google Cloud 기반 Claude Opus 4.6의 경우 claude-opus-4-6 사용
  • Google Cloud의 Claude Sonnet 4.6의 경우 claude-sonnet-4-6 사용
  • Google Cloud의 Claude Opus 4.5의 경우 claude-opus-4-5 사용
  • Google Cloud의 Claude Opus 4.1의 경우 claude-opus-4-1 사용
  • Google Cloud의 Claude Opus 4의 경우 claude-opus-4 사용
  • Google Cloud의 Claude Sonnet 4.5의 경우 claude-sonnet-4-5 사용
  • Google Cloud의 Claude Sonnet 4의 경우 claude-sonnet-4 사용
  • Google Cloud의 Claude 3.7 Sonnet의 경우 claude-3-7-sonnet 사용
  • Google Cloud의 Claude 3.5 Sonnet v2의 경우 claude-3-5-sonnet-v2 사용
  • Google Cloud의 Claude Haiku 5.5의 경우 claude-haiku-5-5 사용
  • Google Cloud의 Claude Haiku 4.5의 경우 claude-haiku-4-5 사용
  • Google Cloud의 Claude 3.5 Haiku의 경우 claude-3-5-haiku 사용
  • Google Cloud의 Claude 3.5 Sonnet의 경우 claude-3-5-sonnet 사용
  • Google Cloud의 Claude 3 Opus의 경우 claude-3-opus 사용
  • Google Cloud의 Claude 3 Haiku의 경우 claude-3-haiku 사용

시작하기 전에

Anthropic은 특정 리셀러가 제품을 재판매하는 것을 금지하는 정책을 시행합니다. 금지된 리셀러가 Cloud de Confiance by S3NS 결제 계정을 관리하는 경우 서비스 약관에 동의하거나 Claude 모델을 사용 설정할 수 없습니다. 이 경우 리셀러에게 직접 문의하세요.

Gemini Enterprise Agent Platform에서 Anthropic Claude 모델을 사용하려면 다음 단계를 실행해야 합니다. Gemini Enterprise Agent Platform을 사용하려면 Agent Platform API (aiplatform.googleapis.com)를 사용 설정해야 합니다. Agent Platform API가 사용 설정된 기존 프로젝트가 이미 있는 경우 새 프로젝트를 만드는 대신 해당 프로젝트를 사용할 수 있습니다.

파트너 모델을 사용 설정하고 사용하는 데 필요한 권한이 있는지 확인합니다. 자세한 내용은 필수 권한 부여를 참고하세요.

  1. In the Cloud de Confiance console, on the project selector page, select or create a Cloud de Confiance project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  2. Verify that billing is enabled for your Cloud de Confiance project.

  3. Enable the Gemini Enterprise Agent Platform API, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

  4. 다음 Model Garden 모델 카드 중 하나로 이동한 다음 사용 설정을 클릭합니다.

Anthropic에서는 모델 오용이 기록되도록 프롬프트 및 완료 활동 30일 로깅을 사용 설정하는 것이 좋습니다. 로깅을 사용 설정하려면 요청 및 응답 로깅을 참고하세요.

Anthropic SDK 사용

Anthropic Claude SDK를 사용하여 Anthropic Claude 모델에 API를 요청할 수 있습니다. 자세한 내용은 다음을 참고하세요.

Anthropic Vertex SDK를 사용하여 Claude 모델에 스트리밍 호출 수행

다음 코드 샘플에서는 Anthropic Vertex SDK를 사용하여 Claude 모델에 스트리밍 호출을 수행합니다.

Python

Vertex AI SDK for Python을 설치하거나 업데이트하는 방법은 Vertex AI SDK for Python 설치를 참고하세요. 자세한 내용은 Python API 참고 문서를 참조하세요.

다음 샘플에서는 리전 엔드포인트를 사용합니다. 멀티 리전 또는 전역 엔드포인트를 사용하려면 멀티 리전 엔드포인트 지정 또는 전역 엔드포인트 지정을 참고하세요.
# TODO(developer): Vertex AI SDK - uncomment below & run
# pip3 install --upgrade --user google-cloud-aiplatform
# gcloud auth application-default login
# pip3 install -U 'anthropic[vertex]'

# TODO(developer): Update and un-comment below line
# PROJECT_ID = "your-project-id"

from anthropic import AnthropicVertex

client = AnthropicVertex(project_id=PROJECT_ID, region="us-east5")
result = []

with client.messages.stream(
    model="claude-3-5-sonnet-v2@20241022",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": "Send me a recipe for banana bread.",
        }
    ],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
        result.append(text)

# Example response:
# Here's a simple recipe for delicious banana bread:
# Ingredients:
# - 2-3 ripe bananas, mashed
# - 1/3 cup melted butter
# ...
# ...
# 8. Bake for 50-60 minutes, or until a toothpick inserted into the center comes out clean.
# 9. Let cool in the pan for a few minutes, then remove and cool completely on a wire rack.

Anthropic Vertex SDK를 사용하여 Claude 모델에 단항 호출 수행

다음 코드 샘플에서는 Anthropic Vertex SDK를 사용하여 Claude 모델에 단항 호출을 수행합니다.

Python

Vertex AI SDK for Python을 설치하거나 업데이트하는 방법은 Vertex AI SDK for Python 설치를 참고하세요. 자세한 내용은 Python API 참고 문서를 참조하세요.

다음 샘플에서는 리전 엔드포인트를 사용합니다. 멀티 리전 또는 전역 엔드포인트를 사용하려면 멀티 리전 엔드포인트 지정 또는 전역 엔드포인트 지정을 참고하세요.
# TODO(developer): Vertex AI SDK - uncomment below & run
# pip3 install --upgrade --user google-cloud-aiplatform
# gcloud auth application-default login
# pip3 install -U 'anthropic[vertex]'

# TODO(developer): Update and un-comment below line
# PROJECT_ID = "your-project-id"

from anthropic import AnthropicVertex

client = AnthropicVertex(project_id=PROJECT_ID, region="us-east5")
message = client.messages.create(
    model="claude-3-5-sonnet-v2@20241022",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": "Send me a recipe for banana bread.",
        }
    ],
)
print(message.model_dump_json(indent=2))
# Example response:
# {
#   "id": "msg_vrtx_0162rhgehxa9rvJM5BSVLZ9j",
#   "content": [
#     {
#       "text": "Here's a simple recipe for delicious banana bread:\n\nIngredients:\n- 2-3 ripe bananas...
#   ...

curl 명령어 사용

curl 명령어를 사용하여 Gemini Enterprise Agent Platform 엔드포인트에 요청할 수 있습니다. curl 명령어는 사용할 지원되는 Claude 모델을 지정합니다.

다음 주제에서는 curl 명령어를 만드는 방법과 샘플 curl 명령어에 대해 소개합니다.

REST

Agent Platform API를 사용하여 텍스트 프롬프트를 테스트하려면 POST 요청을 게시자 모델 엔드포인트로 전송합니다.

다음 샘플에서는 리전 엔드포인트를 사용합니다. 멀티 리전 또는 전역 엔드포인트를 사용하려면 멀티 리전 엔드포인트 지정 또는 전역 엔드포인트 지정을 참고하세요.

요청 데이터를 사용하기 전에 다음을 바꿉니다.

  • LOCATION: Anthropic Claude 모델을 지원하는 리전. 전역 엔드포인트를 사용하려면 전역 엔드포인트 지정을 참고하세요.
  • MODEL: 사용할 모델 이름.
  • ROLE: 메시지와 연결된 역할. user 또는 assistant를 지정할 수 있습니다. 첫 번째 메시지는 user 역할을 사용해야 합니다. Claude 모델이 user와 assistant의 턴을 번갈아가며 작동합니다. 최종 메시지에서 assistant 역할을 사용하는 경우 이 메시지의 콘텐츠에서 곧바로 응답 콘텐츠가 계속됩니다. 이를 사용하여 모델 응답의 일부를 제한할 수 있습니다.
  • STREAM: 응답 스트리밍 여부를 지정하는 불리언. 응답을 스트리밍하여 최종 사용자 지연 시간 인식을 줄입니다. 응답을 스트리밍하려면 true로 설정하고 응답을 한 번에 반환하려면 false로 설정합니다.
  • CONTENT: user 또는 assistant 메시지의 콘텐츠(예: 텍스트)
  • MAX_TOKENS: 응답에서 생성될 수 있는 토큰의 최대 개수. 토큰은 약 3.5자(영문 기준)입니다. 토큰 100개는 단어 약 60~80개에 해당합니다.

    응답이 짧을수록 낮은 값을 지정하고 잠재적으로 응답이 길면 높은 값을 지정합니다.

  • TOP_P: (선택사항) Top-P는 모델이 출력용 토큰을 선택하는 방식을 변경합니다. 토큰은 확률의 합이 Top-P 값과 같아질 때까지 확률이 가장 높은 것부터 가장 낮은 것까지 선택됩니다. 예를 들어 토큰 A, B, C의 확률이 0.3, 0.2, 0.1이고 Top-P 값이 0.5이면 모델이 온도를 사용하여 다음 토큰으로 A 또는 B를 선택하고 C를 후보에서 제외합니다.

    임의성이 낮은 응답에 낮은 값을 지정하고 임의성이 높은 응답에 높은 값을 지정합니다.

  • TOP_K: (선택사항) Top-K는 모델이 출력용 토큰을 선택하는 방식을 변경합니다. Top-K가 1이면 선택된 토큰이 모델의 어휘에 포함된 모든 토큰 중에서 가장 확률이 높다는 의미입니다(그리디 디코딩이라고도 함). 반면에 Top-K가 3이면 강도를 사용하여 가장 확률이 높은 3개 토큰 중에서 다음 토큰이 선택된다는 의미입니다.

    각 토큰 선택 단계에서 확률이 가장 높은 Top-K 토큰이 샘플링됩니다. 그런 다음 Top-P를 기준으로 토큰을 추가로 필터링하고 온도 샘플링을 사용하여 최종 토큰을 선택합니다.

    임의성이 낮은 응답에 낮은 값을 지정하고 임의성이 높은 응답에 높은 값을 지정합니다.

  • TYPE: Google Cloud의 Claude 3.7 Sonnet 및 이후 Claude 모델의 경우 확장된 사고 모드를 사용 설정하려면 enabled을 지정합니다.
  • BUDGET_TOKENS: 확장된 사고를 사용 설정하는 경우 모델이 내부 추론에 사용할 수 있는 토큰 수를 출력의 일부로 지정해야 합니다. 예산이 많을수록 복잡한 문제를 더 철저하게 분석하고 응답 품질을 향상시킬 수 있습니다. 1024 이상의 MAX_TOKENS 이하인 값을 지정해야 합니다.

HTTP 메서드 및 URL:

POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/anthropic/models/MODEL:streamRawPredict

JSON 요청 본문:

{
  "anthropic_version": "vertex-2023-10-16",
  "messages": [
   {
    "role": "ROLE",
    "content": "CONTENT"
   }],
  "max_tokens": MAX_TOKENS,
  "stream": STREAM,
  "thinking": {
    "type": "TYPE",
    "budget_tokens": BUDGET_TOKENS
  }
}

요청을 보내려면 다음 옵션 중 하나를 선택합니다.

curl

요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/anthropic/models/MODEL:streamRawPredict"

PowerShell

요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/anthropic/models/MODEL:streamRawPredict" | Select-Object -Expand Content

다음과 비슷한 JSON 응답이 수신됩니다.

curl 명령어 예시

MODEL_ID="MODEL"
LOCATION="us-central1"
PROJECT_ID="PROJECT_ID"

curl \
-X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://${LOCATION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${LOCATION}/publishers/anthropic/models/${MODEL_ID}:streamRawPredict -d \
'{
  "anthropic_version": "vertex-2023-10-16",
  "messages": [{
    "role": "user",
    "content": "Hello!"
  }],
  "max_tokens": 50,
  "stream": true}'

도구 사용(함수 호출)

Anthropic Claude 모델은 모델의 기능을 향상시키기 위한 도구와 함수 호출을 지원합니다. 자세한 내용은 Anthropic 문서의 도구 사용 개요를 참고하세요. Gemini Enterprise Agent Platform의 Claude 모델은 클라이언트 도구를 지원하지만 서버 도구는 지원하지 않습니다.

다음 샘플에서는 SDK 또는 curl 명령어를 사용하여 도구를 사용하는 방법을 보여줍니다. 샘플에서는 영업 중인 샌프란시스코 인근 레스토랑을 검색합니다.

Python

Vertex AI SDK for Python을 설치하거나 업데이트하는 방법은 Vertex AI SDK for Python 설치를 참고하세요. 자세한 내용은 Python API 참고 문서를 참조하세요.

다음 샘플에서는 리전 엔드포인트를 사용합니다. 멀티 리전 또는 전역 엔드포인트를 사용하려면 멀티 리전 엔드포인트 지정 또는 전역 엔드포인트 지정을 참고하세요.
# TODO(developer): Vertex AI SDK - uncomment below & run
# pip3 install --upgrade --user google-cloud-aiplatform
# gcloud auth application-default login
# pip3 install -U 'anthropic[vertex]'
from anthropic import AnthropicVertex

# TODO(developer): Update and un-comment below line
# PROJECT_ID = "your-project-id"

client = AnthropicVertex(project_id=PROJECT_ID, region="us-east5")
message = client.messages.create(
    model="claude-3-5-sonnet-v2@20241022",
    max_tokens=1024,
    tools=[
        {
            "name": "text_search_places_api",
            "description": "returns information about a set of places based on a string",
            "input_schema": {
                "type": "object",
                "properties": {
                    "textQuery": {
                        "type": "string",
                        "description": "The text string on which to search",
                    },
                    "priceLevels": {
                        "type": "array",
                        "description": "Price levels to query places, value can be one of [PRICE_LEVEL_INEXPENSIVE, PRICE_LEVEL_MODERATE, PRICE_LEVEL_EXPENSIVE, PRICE_LEVEL_VERY_EXPENSIVE]",
                    },
                    "openNow": {
                        "type": "boolean",
                        "description": "whether those places are open for business.",
                    },
                },
                "required": ["textQuery"],
            },
        }
    ],
    messages=[
        {
            "role": "user",
            "content": "What are some affordable and good Italian restaurants open now in San Francisco??",
        }
    ],
)
print(message.model_dump_json(indent=2))
# Example response:
# {
#   "id": "msg_vrtx_018pk1ykbbxAYhyWUdP1bJoQ",
#   "content": [
#     {
#       "text": "To answer your question about affordable and good Italian restaurants
#       that are currently open in San Francisco....
# ...

REST

다음 샘플에서는 리전 엔드포인트를 사용합니다. 멀티 리전 또는 전역 엔드포인트를 사용하려면 멀티 리전 엔드포인트 지정 또는 전역 엔드포인트 지정을 참고하세요.

요청 데이터를 사용하기 전에 다음을 바꿉니다.

  • LOCATION: Anthropic Claude 모델을 지원하는 리전. 전역 엔드포인트를 사용하려면 전역 엔드포인트 지정을 참고하세요.
  • MODEL: 사용할 모델 이름
  • ROLE: 메시지와 연결된 역할. user 또는 assistant를 지정할 수 있습니다. 첫 번째 메시지는 user 역할을 사용해야 합니다. Claude 모델이 user와 assistant의 턴을 번갈아가며 작동합니다. 최종 메시지에서 assistant 역할을 사용하는 경우 이 메시지의 콘텐츠에서 곧바로 응답 콘텐츠가 계속됩니다. 이를 사용하여 모델 응답의 일부를 제한할 수 있습니다.
  • STREAM: 응답 스트리밍 여부를 지정하는 불리언. 응답을 스트리밍하여 최종 사용자 지연 시간 인식을 줄입니다. 응답을 스트리밍하려면 true로 설정하고 응답을 한 번에 반환하려면 false로 설정합니다.
  • CONTENT: user 또는 assistant 메시지의 콘텐츠(예: 텍스트).
  • MAX_TOKENS: 응답에서 생성될 수 있는 토큰의 최대 개수. 토큰은 약 3.5자(영문 기준)입니다. 토큰 100개는 단어 약 60~80개에 해당합니다.

    응답이 짧을수록 낮은 값을 지정하고 잠재적으로 응답이 길면 높은 값을 지정합니다.

HTTP 메서드 및 URL:

POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/anthropic/models/MODEL:rawPredict

JSON 요청 본문:


{
  "anthropic_version": "vertex-2023-10-16",
  "max_tokens": MAX_TOKENS,
  "stream": STREAM,
  "tools": [
    {
      "name": "text_search_places_api",
      "description": "Returns information about a set of places based on a string",
      "input_schema": {
        "type": "object",
        "properties": {
          "textQuery": {
            "type": "string",
            "description": "The text string on which to search"
          },
          "priceLevels": {
            "type": "array",
            "description": "Price levels to query places, value can be one of [PRICE_LEVEL_INEXPENSIVE, PRICE_LEVEL_MODERATE, PRICE_LEVEL_EXPENSIVE, PRICE_LEVEL_VERY_EXPENSIVE]",
          },
          "openNow": {
            "type": "boolean",
            "description": "Describes whether a place is open for business at
            the time of the query."
          },
        },
        "required": ["textQuery"]
      }
    }
  ],
  "messages": [
    {
      "role": "user",
      "content": "What are some affordable and good Italian restaurants that are open now in San Francisco??"
    }
  ]
}

요청을 보내려면 다음 옵션 중 하나를 선택합니다.

curl

요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/anthropic/models/MODEL:rawPredict"

PowerShell

요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/anthropic/models/MODEL:rawPredict" | Select-Object -Expand Content

다음과 비슷한 JSON 응답이 수신됩니다.

Gemini Enterprise Agent Platform에서 Agent Studio 사용

일부 Anthropic Claude 모델의 경우 Gemini Enterprise 에이전트 플랫폼의 Agent Studio를 사용하여 Cloud de Confiance 콘솔에서 생성형 AI 모델을 빠르게 프로토타입하고 테스트할 수 있습니다. 예를 들어 Gemini Enterprise Agent Platform의 Agent Studio를 사용하여 Claude 모델 응답을 Google Gemini와 같은 지원되는 다른 모델과 비교할 수 있습니다.

자세한 내용은 빠른 시작: Gemini Enterprise Agent Platform의 Agent Studio를 사용하여 Gemini에 텍스트 프롬프트 보내기를 참고하세요.