빠른 시작
2OpenAI SDK 설치
기존에 OpenAI SDK를 사용하고 있다면 이 단계는 건너뛰세요.
Python
pip install openaiNode.js
npm install openai3API 호출
base_url을 인보이스랩으로 변경하고 API 키를 설정하세요.
from openai import OpenAI
client = OpenAI(
api_key="your-dream-api-key",
base_url="https://api.invoicedream.co.kr/v1"
)
response = client.chat.completions.create(
model="openai/gpt-4o",
messages=[
{"role": "user", "content": "안녕하세요!"}
]
)
print(response.choices[0].message.content)API 레퍼런스
Base URL
https://api.invoicedream.co.kr/v1인증
모든 API 요청에 Bearer 토큰 인증이 필요합니다.
Authorization: Bearer your-dream-api-key엔드포인트
| 메소드 | 엔드포인트 | 설명 |
|---|---|---|
| POST | /chat/completions | 채팅 완성 생성 |
| POST | /completions | 텍스트 완성 생성 |
| GET | /models | 사용 가능한 모델 목록 |
예제 코드
Python
from openai import OpenAI
client = OpenAI(
api_key="your-dream-api-key",
base_url="https://api.invoicedream.co.kr/v1"
)
# 기본 채팅
response = client.chat.completions.create(
model="openai/gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "안녕하세요!"}
],
temperature=0.7,
max_tokens=1000
)
print(response.choices[0].message.content)
# 스트리밍
stream = client.chat.completions.create(
model="anthropic/claude-3.5-sonnet",
messages=[{"role": "user", "content": "긴 글을 작성해주세요."}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
# Function Calling
response = client.chat.completions.create(
model="openai/gpt-4o",
messages=[{"role": "user", "content": "서울 날씨 알려줘"}],
tools=[{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"}
}
}
}
}]
)Node.js / TypeScript
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'your-dream-api-key',
baseURL: 'https://api.invoicedream.co.kr/v1'
});
// 기본 채팅
const response = await client.chat.completions.create({
model: 'openai/gpt-4o',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: '안녕하세요!' }
]
});
console.log(response.choices[0].message.content);
// 스트리밍
const stream = await client.chat.completions.create({
model: 'anthropic/claude-3.5-sonnet',
messages: [{ role: 'user', content: '긴 글을 작성해주세요.' }],
stream: true
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}cURL
curl https://api.invoicedream.co.kr/v1/chat/completions \
-H "Authorization: Bearer your-dream-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "안녕하세요!"}
],
"temperature": 0.7,
"max_tokens": 1000
}'모델 ID 형식
모델 ID는 provider/model-name 형식입니다.
| 제공사 | 모델 ID 예시 |
|---|---|
| OpenAI | openai/gpt-4o, openai/o1, openai/gpt-4o-mini |
| Anthropic | anthropic/claude-3.5-sonnet, anthropic/claude-3-opus |
| google/gemini-2.0-flash-exp, google/gemini-pro-1.5 | |
| DeepSeek | deepseek/deepseek-r1, deepseek/deepseek-chat |
| Meta | meta-llama/llama-3.3-70b-instruct |
에러 처리
| 상태 코드 | 설명 | 해결 방법 |
|---|---|---|
| 401 | 인증 실패 | API 키를 확인하세요 |
| 402 | 크레딧 부족 | 크레딧을 충전하세요 |
| 429 | 요청 한도 초과 | 잠시 후 다시 시도하세요 |
| 500 | 서버 오류 | 고객지원에 문의하세요 |
자주 묻는 질문
기존 OpenAI 코드를 그대로 사용할 수 있나요?
네, base_url만 변경하면 됩니다. OpenAI SDK의 모든 기능(스트리밍, Function Calling, JSON Mode 등)을 그대로 사용할 수 있습니다.
가격은 어떻게 되나요?
모델별 가격표를 참고해주세요. 부가세(10%)는 별도이며, 매입세액으로 공제받을 수 있습니다.
세금계산서는 어떻게 받나요?
결제 완료 후 1영업일 이내 자동으로 전자세금계산서가 발행됩니다. 홈택스로 자동 전송되며, 대시보드에서도 확인할 수 있습니다.