cURL 및 Python 3을 사용하여 Bash(macOS, Linux 또는 WSL)에서 이를 실행합니다. your-api-key를 키로 바꿉니다.response.json을 로컬로 유지하세요.
Bash · Qwen3.8-27B · $0
export ITERACOMPUTE_API_KEY="your-api-key"
curl --fail-with-body --max-time 180 https://api.iteracompute.com/v1/chat/completions \
-H "Authorization: Bearer $ITERACOMPUTE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"qwen/qwen3.8-27b","messages":[{"role":"user","content":"Reply with exactly: Hello!"}],"max_tokens":512,"chat_template_kwargs":{"enable_thinking":false}}' \
-o response.json && python3 -c 'import json; r=json.load(open("response.json")); text=r["choices"][0]["message"]["content"]; assert text and text.strip(), "Empty model reply: activation is incomplete"; print(text)'
choices[0].message.content에 비어 있지 않은 텍스트가 있으면 성공입니다. 이 명령은 텍스트를 출력하며 빈 응답이면 실패합니다. 등록 또는 HTTP 200만으로는 활성화가 완료되지 않습니다. 예상 출력: Hello! (표현은 달라질 수 있습니다).
이 Qwen 예는 짧은 눈에 보이는 답변에 대한 생각을 비활성화합니다.401/403: 키와 모델 권한을 확인하세요.429: 콘솔에서 월간 사용량과 TPM을 확인한 후 Retry-After를 따릅니다.여유 용량이 대기열에 있을 수 있습니다.반복적인 병렬 재시도를 실행하지 마십시오.
아래 고급 예에서는 유료 DeepSeek V4.1 Flash를 사용하고 API 잔액에서 사용량을 공제합니다.모델 페이지에서 현재 입력, 캐시된 입력 및 출력 가격을 확인하세요.무료 Qwen3.8-27B는 채팅 완료, 스트리밍 및 도구 호출을 지원합니다.이 가이드에서는 Qwen Responses API 지원을 설정하지 않습니다.모델 ID와 추론 매개변수는 서로 바꿔 사용할 수 없습니다.예시를 적용하기 전에 선택한 모델이 각 엔드포인트와 옵션을 지원하는지 확인하세요.
IteraCompute API는 OpenAI와 호환됩니다. 이미 OpenAI API를 사용하는 애플리케이션은 이전 시 다음 항목을 변경하면 됩니다:
base_url 및 API 키. Chat Completions, Responses, 스트리밍 및 도구 호출은 선택한 모델이 지원하는 범위에서 호환 형식을 따릅니다.
2. 기본 URL 및 인증
API 요청 전송 대상: https://api.iteracompute.com/v1로 전송합니다. Chat Completions 및 Responses 요청은 API 키를 다음 헤더에 지정하여 인증합니다:
Authorization .
POST /v1/responses Codex와 같은 클라이언트가 사용하는 OpenAI Responses API를 지원합니다.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.iteracompute.com/v1",
api_key=os.environ["ITERACOMPUTE_API_KEY"],
)
response = client.responses.create(
model="deepseek/deepseek-v4.1-flash",
input="Reply with exactly: Hello!",
max_output_tokens=128,
)
print(response.output_text)
6. 스트리밍(SSE)
설정: "stream": true 로 SSE를 수신합니다. 청크는 생성되는 대로 도착하며, 토큰 사용량은 다음 필드가 있는 마지막 청크에 포함됩니다:
usage. 이 청크는 다음 종료 이벤트보다 먼저 도착합니다:
[DONE] . 스트림 전체를 하나의 논리적 요청으로 처리하세요. 토큰 출력이 시작된 뒤에는 요청이 투명하게 재시도되지 않습니다.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.iteracompute.com/v1",
api_key=os.environ["ITERACOMPUTE_API_KEY"],
)
stream = client.chat.completions.create(
model="deepseek/deepseek-v4.1-flash",
messages=[{"role": "user", "content": "Reply with exactly: Hello!"}],
stream=True,
stream_options={"include_usage": True},
temperature=0,
max_tokens=128,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
if chunk.usage: # final chunk: token usageprint("\n", chunk.usage)
7. 도구 호출
도구는 tools
매개변수에서 OpenAI function calling 형식에 따라 선언합니다. 모델이 도구 호출을 선택하면 응답에 다음 필드가 포함됩니다:
tool_calls. 도구 실행 결과를 반환할 때는 다음 역할을 지정하세요: "tool" . 그러면 대화를 계속할 수 있습니다.
import json
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.iteracompute.com/v1",
api_key=os.environ["ITERACOMPUTE_API_KEY"],
)
messages = [{"role": "user", "content": "What is the weather in Singapore?"}]
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}]
resp = client.chat.completions.create(
model="deepseek/deepseek-v4.1-flash",
messages=messages,
tools=tools,
tool_choice={"type": "function", "function": {"name": "get_weather"}},
max_tokens=512,
)
assistant_message = resp.choices[0].message
messages.append(assistant_message)
for call in assistant_message.tool_calls or []:
arguments = json.loads(call.function.arguments)
result = {"city": arguments["city"], "temperature_c": 29}
messages.append({
"role": "tool",
"tool_call_id": call.id,
"content": json.dumps(result),
})
final = client.chat.completions.create(
model="deepseek/deepseek-v4.1-flash",
messages=messages,
tools=tools,
max_tokens=512,
)
print(final.choices[0].message.content)
8. 오류 코드
오류는 JSON 본문과 함께 OpenAI 오류 형식을 사용합니다.
{"error": {"message", "type", "code"}}:
상태
의미
400
잘못된 요청 - 잘못된 JSON 또는 필수 매개변수 누락
401
인증 실패 - API 키가 누락되었거나 잘못되었습니다.
403
이 모델 또는 작업에는 키가 허용되지 않습니다.
404
알 수 없는 모델 또는 엔드포인트
429
속도 제한 초과 - 속도를 늦추고 Retry-After 준수
500
내부 오류 - 요청을 다시 시도해도 안전합니다.
503
모델을 일시적으로 사용할 수 없습니다. 백오프로 다시 시도하세요.
9. 사용량 제한
Qwen3.8-27B의 월간 한도와 TPM은 계정 전체에 적용됩니다. Free / Starter / Pro는 UTC 기준 월마다 30M / 100M / 300M 토큰, 160K / 300K / 600K TPM, 128K / 128K / 256K 컨텍스트를 제공합니다. 완료된 누적 순 충전액이 $10 / $50이면 Starter / Pro가 해제됩니다. GPU 용량이 혼잡하면 무료 계정은 대기열에서 대기할 수 있습니다. GPU당 대기 요청은 최대 32개, 대기 시간은 최대 120초입니다. 다른 모델에는 키별 제한이 적용됩니다. 한도 소진, 대기열 포화 또는 대기 시간 초과 시 반환되는 응답 코드는 429입니다. 재시도 전에 다음 헤더의 지침을 따르세요: Retry-After .