튜토리얼
hiapi API로 glm-5.3 사용하는 방법: curl, Python 그리고 실행 가능한 요청
빌드하게 될 내용
hiapi의 OpenAI 호환 Chat Completions API를 통해 glm-5.3을 호출하는 실행 가능한 통합입니다. 단일 요청으로 실제 완성 결과를 반환하며, 이 모델을 사용할 때 실제로 가장 쉽게 빠지는 함정을 설명합니다. 바로 추론 토큰이 max_tokens 예산을 잡아먹는다는 점입니다.
전제 조건: hiapi API key 하나. dashboard에서 발급받으세요. sk-... 문자열일 뿐이며, 같은 key를 계정에서 활성화된 모든 모델에 사용할 수 있습니다. 이 모델에만 국한되지 않습니다.
아래의 모든 요청과 응답은 작성 시점에 실제 운영 중인 API로 직접 실행한 결과입니다.
최소 실행 예제
glm-5.3은 표준 Chat Completions 엔드포인트의 텍스트 모델입니다. hiapi가 이미지/비디오/오디오 모델에 사용하는 비동기 /v1/tasks 흐름이 아닙니다. 요청 한 번, 응답 한 번, 폴링 없음.
curl https://api.hiapi.ai/v1/chat/completions \
-H "Authorization: Bearer sk-<your-api-key>" \
-H "Content-Type: application/json" \
-d '{
"model": "glm-5.3",
"messages": [
{"role": "user", "content": "Reply with exactly: OK"}
],
"max_tokens": 200
}'
응답(일부 생략):
{
"id": "8be5f07603f0407c90734e8b4c2f02f0",
"object": "chat.completion",
"model": "glm-5.3",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "OK",
"reasoning_content": "The user wants me to reply with exactly \"OK\" ..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 17,
"completion_tokens": 35,
"total_tokens": 52,
"completion_tokens_details": { "reasoning_tokens": 32 }
}
}
requests만 사용해 Python으로 동일한 호출을 수행합니다:
import requests
resp = requests.post(
"https://api.hiapi.ai/v1/chat/completions",
headers={"Authorization": "Bearer sk-<your-api-key>"},
json={
"model": "glm-5.3",
"messages": [
{"role": "user", "content": "Reply with exactly: OK"}
],
"max_tokens": 200,
},
timeout=60,
)
resp.raise_for_status()
data = resp.json()
print(data["choices"][0]["message"]["content"])
print(data["usage"])
OpenAI와 구조가 호환되므로 이 코드는 공식 openai Python/JS SDK와도 수정 없이 동작합니다. base_url을 https://api.hiapi.ai/v1로 지정하고 hiapi key를 전달하기만 하면 됩니다.
프로덕션 환경 패턴
추론 토큰이 낮은 max_tokens 예산을 잡아먹습니다
glm-5.3은 답변 전에 항상 먼저 사고합니다. 모든 응답이 content 옆에 reasoning_content 필드를 동반하며, 이를 끄는 요청 플래그는 없습니다. 이 추론 내용은 눈에 보이는 답변보다 먼저 max_tokens에 계산됩니다. 예산을 너무 낮게 잡으면 content: null과 finish_reason: "length"를 받게 됩니다. 모델이 할당량을 전부 사고에 써버려 답변 작성 단계에 이르지 못하기 때문입니다:
{
"choices": [{
"message": { "content": null, "reasoning_content": "The user has given a very simple instruction: \"" },
"finish_reason": "length"
}],
"usage": { "completion_tokens": 10, "completion_tokens_details": { "reasoning_tokens": 9 } }
}
프롬프트가 단순하더라도 여유를 두세요(200+ 토큰이 안전한 하한). 그리고 content를 신뢰하기 전에 항상 finish_reason을 확인하세요. "length"는 답변이 잘렸음을, 심지어 시작조차 못 했을 수 있음을 뜻합니다.
스트리밍 출력
"stream": true를 설정하고 Server-Sent Events를 읽으세요. 추론 내용과 답변 텍스트는 별개의 delta 필드로 도착합니다. 먼저 delta.reasoning_content 블록이, 모델이 실제로 답변을 시작하면 delta.content가 옵니다. 스트림은 마지막 블록에서 finish_reason: "stop"으로 끝납니다:
curl https://api.hiapi.ai/v1/chat/completions \
-H "Authorization: Bearer sk-<your-api-key>" \
-H "Content-Type: application/json" \
-d '{
"model": "glm-5.3",
"messages": [{"role": "user", "content": "Count to 3."}],
"max_tokens": 200,
"stream": true
}'
data: {"choices":[{"delta":{"role":"assistant","content":"","reasoning_content":null},"finish_reason":null}]}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"The"},"finish_reason":null}]}
data: {"choices":[{"delta":{"content":"1, ","reasoning_content":null},"finish_reason":null}]}
data: {"choices":[{"delta":{"content":"2, 3.","reasoning_content":null},"finish_reason":null}]}
data: {"choices":[{"delta":{},"finish_reason":"stop"}]}
UI로 스트리밍하는 경우 reasoning_content와 content를 이어 붙이지 말고 서로 다른 패널로 라우팅하세요. 둘은 같은 텍스트 흐름이 아닙니다.
도구 호출
함수 호출은 표준 OpenAI 구조를 따릅니다. tools를 선언하면 모델이 도구 호출을 결정할 때 finish_reason이 "tool_calls"와 채워진 tool_calls 배열로 반환됩니다(이때도 먼저 추론하므로 reasoning_content가 함께 나타납니다):
{
"message": {
"role": "assistant",
"content": null,
"reasoning_content": "The user wants to know the weather in Paris. I have a tool available for that. Let me call it.",
"tool_calls": [{
"id": "call_12e21fe488f046bc9edb4488",
"type": "function",
"function": { "name": "get_weather", "arguments": "{\"city\": \"Paris\"}" }
}]
},
"finish_reason": "tool_calls"
}
다음 턴에서 어시스턴트의 tool_calls 메시지와 role: "tool" 결과 메시지를 재생합니다. 다른 OpenAI 호환 통합과 동일합니다.
오류 처리
유효하지 않거나 누락된 key는 일관된 오류 구조와 함께 HTTP 401을 반환합니다. choices를 파싱하기 전에 상태 코드를 먼저 확인하세요:
{
"error": {
"code": "permission_denied",
"message": "This API key is invalid. Check that it is correct or use another API key and try again.",
"type": "hiapi_error"
}
}
관련 리소스
- glm-5.3 모델 페이지 — 기능 및 현재 사용 가능 여부
- hiapi 가격 — 현재 토큰당 요율
- API keys 대시보드 — key 생성 및 관리
- hiapi API로 kimi-k3 사용하는 방법 — hiapi의 또 다른 Chat Completions 텍스트 모델
- hiapi API로 deepseek-v4.1-flash 사용하는 방법 — 동일한 통합 패턴, 다른 모델
자주 묻는 질문
glm-5.3은 스트리밍 출력을 지원하나요?
지원합니다. "stream": true를 설정하고 SSE 블록을 읽으세요. 추론 내용과 답변 내용이 별개의 delta 필드로 스트리밍됩니다.
왜 응답의 content가 null인가요?
거의 항상 max_tokens 예산이 추론과 답변을 모두 커버하기에 너무 작기 때문입니다. finish_reason을 확인하세요. "length"는 응답이 실제 답변 이전(또는 도중)에 잘렸음을 뜻합니다. max_tokens를 늘리세요.
추론 단계를 비활성화할 수 있나요?
요청 매개변수로는 비활성화할 수 없습니다. glm-5.3은 매 응답 전에 추론하며 reasoning_content는 항상 채워집니다. 끄려 하지 말고 예산을 확보하세요.
glm-5.3은 함수/도구 호출을 지원하나요?
지원합니다. 표준 OpenAI tools / tool_calls 구조를 사용하며, 운영 중인 엔드포인트에서 검증되었습니다.
원시 HTTP 대신 공식 OpenAI SDK를 사용할 수 있나요?
가능합니다. SDK의 base_url을 https://api.hiapi.ai/v1로 지정하고 hiapi sk-... key를 API key로 사용하세요. 다른 변경은 필요 없습니다.
glm-5.3은 어떻게 과금되나요? 다른 hiapi 텍스트 모델과 마찬가지로 토큰 단위로 과금됩니다. 이 글의 특정 숫자에 의존하지 말고 가격을 확인해 현재 요율을 확인하세요.
관련 글
모든 아티클 보기 →-
튜토리얼
HiAPI API로 hailuo-2.3-fast/image-to-video 호출하는 방법: curl과 Python 실전
빠르고 저렴한 이미지-투-비디오 등급의 첫 실행 요청 — 모델 ID부터 MP4 다운로드까지
-
튜토리얼
HiAPI API로 hailuo-2.3/text-to-video를 호출하는 방법: curl, Python 및 실행 가능한 요청 예시
-
튜토리얼
HiAPI에서 Kandinsky 6.0 Pro 텍스트-투-비디오 사용하기: curl 및 Python 튜토리얼
요청 우선 실전 데모: 프롬프트에서 비디오 클립까지의 호출 구성, 요청 제출, 완료 상태 폴링 및 결과 다운로드