클라이언트 만들기
클라이언트 만들기
Cohere SDK를 사용해 Cohere API 클라이언트를 만드는 방법을 안내하는 가이드예요. Python, TypeScript, Java, Go 이렇게 4가지 언어를 지원해요.
출처: 문서
본문
Cohere API 클라이언트 만들기
Cohere SDK에 있는 모든 기능을 사용하려면, 먼저 클라이언트를 만들어야 해요.
Python
import cohere
co = cohere.ClientV2(api_key="YOUR_API_KEY")
Cohere API 클라이언트는 다음 파라미터로 초기화돼요:
| 파라미터 | 타입 | 기본값 | 설명 |
|---|---|---|---|
api_key |
str/callable |
None |
Cohere V2 API에 요청을 인증하기 위한 API key예요. |
base_url |
str |
os.getenv("CO_API_URL") |
Cohere API의 기본 URL이에요. |
environment |
ClientEnvironment |
ClientEnvironment.PRODUCTION |
API 환경을 지정해요 (예: production, staging). |
client_name |
str |
None |
클라이언트 인스턴스의 선택적 이름으로, 로깅에 유용해요. |
timeout |
float |
None |
API 요청의 타임아웃(초)이에요. |
httpx_client |
httpx.Client |
None |
HTTP 요청을 위한 선택적 사전 구성 httpx.Client예요. |
thread_pool_executor |
ThreadPoolExecutor |
ThreadPoolExecutor(64) |
동시 작업을 위한 스레드 풀 실행기로, 기본적으로 64개 스레드를 사용해요. |
log_experimental |
bool |
True |
실험적 기능에 대한 경고를 켜거나 끄는 옵션이에요. |
TypeScript
import { CohereClientV2 } from 'cohere-ai';
const cohere = new CohereClientV2({ token: 'YOUR_API_KEY' });
Cohere API 클라이언트는 다음 파라미터로 초기화돼요:
| 파라미터 | 타입 | 기본값 | 설명 |
|---|---|---|---|
token |
string |
undefined |
필수. Cohere API에 요청을 인증하는 데 쓰는 API key예요. |
baseUrl |
string |
"https://api.cohere.ai/v1" |
Cohere API의 기본 URL 엔드포인트예요. |
clientName |
string |
undefined |
클라이언트 인스턴스의 선택적 식별자로, 로깅에 유용해요. |
timeout |
number (milliseconds) |
120000 (120 seconds) |
요청 타임아웃(밀리초)이에요. |
fetch |
typeof fetch |
Global fetch |
HTTP 요청을 위한 커스텀 fetch 구현이에요. |
Java
import com.cohere.api.Cohere;
Cohere cohere = Cohere.builder()
.token("YOUR_API_KEY")
.clientName("your-client-name")
.build();
Cohere API 클라이언트는 다음 파라미터로 초기화돼요:
| 파라미터 | 타입 | 기본값 | 설명 |
|---|---|---|---|
token |
String |
null |
필수. 요청 인증에 쓰는 Cohere API key예요. |
baseUrl |
String |
"https://api.cohere.ai/v1" |
Cohere API의 기본 URL이에요. |
clientName |
String |
null |
클라이언트 애플리케이션의 선택적 식별자예요. |
timeout |
Duration |
null |
API 요청의 타임아웃 기간이에요. |
okHttpClient |
OkHttpClient |
null |
HTTP 요청을 위한 커스텀 OkHttpClient 인스턴스예요. |
Go
import (
client "github.com/cohere-ai/cohere-go/v2/client"
)
co := client.NewClient(client.WithToken("YOUR_API_KEY"))
Cohere API 클라이언트는 다음 파라미터로 초기화돼요:
| 파라미터 | 타입 | 기본값 | 설명 |
|---|---|---|---|
token |
string |
"" (empty string) |
필수. 요청 인증에 쓰는 Cohere API key예요. |
baseURL |
string |
"https://api.cohere.ai/v1" |
Cohere API의 기본 URL이에요. |
httpClient |
*http.Client |
http.DefaultClient |
요청을 만들기 위한 커스텀 HTTP 클라이언트예요. |