본문으로 바로 가기
문서 · 대화 API

대화 API

요청과 응답의 모양, 스트리밍

POST https://alprouter.alpsoft.io/api/v1/chat/completions는 OpenAI의 Chat Completions와 같은 모양이에요.

요청

항목값설명
model글모델 이름. alprouter/auto를 적으면 알아서 골라요
messages목록대화. role은 system, developer, user, assistant, tool을 받아요
models목록model이 막혔을 때 차례로 쓸 모델. 5개까지
streamtrue · false만들어지는 대로 받을지
max_tokens숫자만들 수 있는 최대 길이. max_completion_tokens와 같은 뜻이에요
n1~4답을 몇 개 만들지. 받는 모델만 써요
tools · tool_choice목록 · 값모델이 부를 수 있는 도구
response_format객체JSON처럼 정해진 형식으로 받기
reasoning_effort · reasoning글 · 객체얼마나 깊이 생각할지
provider객체공급사 조건
plugins목록자동 선택의 설정(auto-router)

적지 않은 max_tokens는 32,768토큰과 남은 크레딧으로 만들 수 있는 길이 가운데 짧은 쪽이 돼요. temperature처럼 모델마다 다른 옵션은 옵션과 모델별 지원에서 볼 수 있어요.

응답

{
  "id": "gen-…",
  "object": "chat.completion",
  "model": "anthropic/claude-opus-5.5",
  "provider": "Amazon Bedrock",
  "choices": [{
    "index": 0,
    "message": { "role": "assistant", "content": "안녕하세요!" },
    "finish_reason": "stop"
  }],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 5,
    "total_tokens": 17,
    "prompt_tokens_details": { "cached_tokens": 0, "cache_write_tokens": 0 },
    "completion_tokens_details": { "reasoning_tokens": 0 },
    "cost": 0.0000037
  }
}
  • model과 provider는 실제로 답한 모델과 공급사예요. 자동 선택이나 넘기기를 쓰면 요청한 값과 다를 수 있어요.
  • usage.cost는 이 요청에 나간 요금(달러)이에요.
  • 응답 헤더 x-request-id에도 같은 id가 있어요. 문의할 때 이 값을 알려 주시면 빨리 찾을 수 있어요.

스트리밍

stream을 켜면 만들어지는 대로 받아요. stream_options.include_usage를 함께 켜면 마지막 조각에 사용량과 요금이 와요.

stream = client.chat.completions.create(
    model="anthropic/claude-opus-5.5",
    messages=[{"role": "user", "content": "안녕하세요"}],
    stream=True,
    stream_options={"include_usage": True},
)
for chunk in stream:
    if chunk.choices:
        print(chunk.choices[0].delta.content or "", end="")
    elif chunk.usage:
        print("\n요금(USD):", chunk.usage.cost)
  • 각 조각은 data: 로 시작하는 한 줄이고, 마지막은 data: [DONE]이에요.
  • 답을 받던 중 문제가 생기면 error가 담긴 조각을 보내고 끝나요. 이때는 [DONE]이 오지 않아요.
  • 받는 도중에 연결을 끊으면 요청을 멈추고 그때까지 만든 만큼만 요금이 나가요. 모델과 입력 길이에 따라서는 끝까지 만든 만큼 나가요. 자세한 것은 요금에 있어요.