API 문서

XHuoAPI는 OpenAI와 완전히 호환되는 API를 제공하며 500개 이상의 주요 AI 모델을 지원합니다.

Base URL

https://api.xhuoapi.ai

빠른 시작

  1. 콘솔에서 계정 등록
  2. 콘솔에서 API 키 발급
  3. Base URL을 https://api.xhuoapi.ai로 변경
  4. API 호출 시작

인증

모든 요청은 HTTP 헤더에 API 키를 포함해야 합니다:

Authorization: Bearer YOUR_API_KEY

⚠️ 보안 안내: API 키를 클라이언트 코드에 노출하지 마세요. 자체 백엔드를 통해 요청을 프록시하는 것을 권장합니다.

채팅 완성

채팅 완성 요청을 생성합니다. 모든 주요 모델을 지원합니다.

POST /v1/chat/completions

요청 파라미터

파라미터 유형 필수 설명
model string 모델 이름 (예: gpt-4o)
messages array 대화 메시지 목록
temperature number 샘플링 온도 (0-2), 기본값 1
max_tokens integer 생성할 최대 토큰 수
stream boolean 스트리밍 출력 여부, 기본값 false

요청 예시

curl https://api.xhuoapi.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {
        "role": "user",
        "content": "안녕하세요, 자기소개를 해주세요"
      }
    ],
    "temperature": 0.7
  }'

응답 예시

{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "안녕하세요! 저는 AI 어시스턴트입니다..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 20,
    "total_tokens": 32
  }
}

모델 목록

사용 가능한 모든 모델 목록을 가져옵니다.

GET /v1/models

요청 예시

curl https://api.xhuoapi.ai/v1/models \
  -H "Authorization: Bearer YOUR_API_KEY"

인기 모델

gpt-4o

OpenAI의 최신 멀티모달 모델

claude-3-5-sonnet-20241022

Anthropic Claude 3.5 Sonnet

gemini-2.0-flash-exp

Google Gemini 2.0 Flash

deepseek-chat

DeepSeek V3 채팅 모델

스트리밍

stream: true를 설정하면 생성되는 내용을 실시간으로 받을 수 있습니다.

요청 예시

curl https://api.xhuoapi.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "농담 하나 해줘"}],
    "stream": true
  }'

응답 형식

스트리밍 응답은 Server-Sent Events (SSE) 형식을 사용하며, 각 행은 data:로 시작합니다:

data: {"id":"chatcmpl-123","choices":[{"delta":{"content":"안녕"}}]}

data: {"id":"chatcmpl-123","choices":[{"delta":{"content":"하세요"}}]}

data: [DONE]

오류 처리

API는 표준 HTTP 상태 코드로 요청 결과를 나타냅니다.

상태 코드 설명
200 요청 성공
400 잘못된 요청 파라미터
401 API 키가 없거나 유효하지 않음
429 요청 빈도 초과
500 서버 내부 오류

오류 응답 예시

{
  "error": {
    "message": "Invalid API key",
    "type": "invalid_request_error",
    "code": "invalid_api_key"
  }
}

코드 예제

Python

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://api.xhuoapi.ai/v1"
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "user", "content": "안녕하세요"}
    ]
)

print(response.choices[0].message.content)

Node.js

import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: 'YOUR_API_KEY',
  baseURL: 'https://api.xhuoapi.ai/v1'
});

const response = await client.chat.completions.create({
  model: 'gpt-4o',
  messages: [{ role: 'user', content: '안녕하세요' }]
});

console.log(response.choices[0].message.content);

cURL

curl https://api.xhuoapi.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "안녕하세요"}]
  }'

도움이 필요하신가요? 콘솔 또는 Telegram으로 문의하세요

© 2024 XHuoAPI. All rights reserved.