연동

채팅 완성

POST /v1/chat/completions는 메시지 목록을 전송하고 모델의 답변을 반환합니다. 카탈로그의 모든 채팅 모델이 이 엔드포인트를 사용합니다.

curl https://api.link-io.cloud/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4.1-mini",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

멀티턴 대화와 시스템 메시지

API는 상태를 저장하지 않습니다. 매 요청마다 전체 대화 내역을 전송하세요. 역할과 규칙은 맨 앞에 배치한 system 메시지로 지정합니다.

resp = client.chat.completions.create(
    model="gpt-4.1-mini",
    messages=[
        {"role": "system", "content": "You are a concise assistant."},
        {"role": "user", "content": "What is a vector database?"},
        {"role": "assistant", "content": "A database optimized for similarity search over embeddings."},
        {"role": "user", "content": "Give me two use cases."},
    ],
    temperature=0.3,
    max_tokens=800,
)
print(resp.choices[0].message.content)
print(resp.usage)

주요 파라미터

파라미터설명
model필수. 카탈로그의 모델 ID(대소문자 구분)
messages필수. role이 system / user / assistant / tool인 메시지 배열
max_tokens / max_completion_tokens출력 토큰 상한. 추론 모델은 max_completion_tokens를 사용합니다
temperature / top_p샘플링 무작위성. 추론 모델은 대개 지원하지 않습니다
stop중지 시퀀스
streamtrue이면 SSE로 스트리밍합니다. 스트리밍 참고
tools / tool_choice함수 호출. 도구 호출 참고
response_formatJSON 출력. 구조화된 출력 참고
reasoning_effort추론 깊이. 추론 참고
파라미터는 모델에 그대로 전달됩니다. 지원되지 않는 파라미터는 모델에 따라 무시되거나 400 오류로 거부될 수 있습니다.

응답

{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "model": "gpt-4.1-mini",
  "choices": [{
    "index": 0,
    "message": { "role": "assistant", "content": "Hello! How can I help you today?" },
    "finish_reason": "stop"
  }],
  "usage": { "prompt_tokens": 9, "completion_tokens": 10, "total_tokens": 19 }
}
finish_reason의미
stop정상적으로 완료됨
lengthmax_tokens에 도달하여 출력이 잘림
tool_calls모델이 도구를 호출하려 함
content_filter안전 정책에 의해 차단됨

usage는 입력 및 출력 토큰을 보고하며, 비용은 모델 가격을 따릅니다.