API로 Standard Vault 호출하기

API로 Standard Vault 호출하기

Cohere SDK, raw HTTP, 또는 OpenAI 호환 클라이언트로 요청을 볼트 엔드포인트 URL로 보내서 Standard Vault를 호출해요.

출처: 문서

본문

Model Vault 앱에서 Standard Vault를 설정한 후, 모델 카드에 표시된 Vault 엔드포인트 URL과 모델 이름을( Managing Vaults 참조) API 호출에 사용해요. Cohere API 키로 인증해요.

Standard Vault를 호출하는 방법은 세 가지예요: Cohere SDK, raw HTTP, OpenAI 호환 클라이언트. 어느 경우든 기본 Cohere API base URL 대신 요청을 볼트 엔드포인트로 직접 보내요.

Note

이 페이지는 클라이언트가 볼트 엔드포인트에 직접 연결하는 Standard Vaults를 다룬답니다. Encrypted Vault는 동일한 요청·응답 형태를 사용하지만, 트래픽은 증명을 검증하는 클라이언트나 프록시를 통과해야 해요. Calling an Encrypted Vault over the API를 참조하세요.

Cohere SDK

base_url로 Cohere SDK를 볼트 엔드포인트에 지정해요:

PYTHON

import cohere

co = cohere.ClientV2(
    api_key="<COHERE_API_KEY>",
    base_url="<YOUR_VAULT_ENDPOINT_URL>",
)

response = co.chat(
    model="<YOUR_VAULT_MODEL_NAME>",
    messages=[{"role": "user", "content": "Hello from Model Vault!"}],
)

print(response.message.content[0].text)

Raw HTTP

SDK를 사용하지 않는다면 HTTP로 볼트 엔드포인트를 직접 호출해요. API 키를 bearer 토큰으로 보내고 Cohere API와 동일한 요청 본문을 사용해요:

cURL

curl "<YOUR_VAULT_ENDPOINT_URL>/v2/chat" \
  -H "Authorization: bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<YOUR_VAULT_MODEL_NAME>",
    "messages": [{"role": "user", "content": "Hello from Model Vault!"}]
  }'

OpenAI 호환 API

기존 OpenAI 통합을 위해, 볼트의 호환성 base URL(<YOUR_VAULT_ENDPOINT_URL>/compatibility/v1)로 OpenAI 호환 클라이언트를 지정하고 Cohere API 키를 사용해요:

PYTHON

from openai import OpenAI

client = OpenAI(
    api_key="<COHERE_API_KEY>",
    base_url="<YOUR_VAULT_ENDPOINT_URL>/compatibility/v1",
)

response = client.chat.completions.create(
    model="<YOUR_VAULT_MODEL_NAME>",
    messages=[{"role": "user", "content": "Hello from Model Vault!"}],
)

print(response.choices[0].message.content)

Chat, Embed, Rerank

위의 chat 예제는 SDK를 볼트로 지정해요. Embed와 Rerank 요청도 동일하게 동작해요: base_url을 볼트 엔드포인트로 유지한 채 볼트의 모델 이름으로 co.embed(...) 또는 co.rerank(...)를 호출하면 돼요.

다음 단계

더 알아보기 (Learn more)