Skip to main content
POST
Chat Completion

채팅 완료

선택적 RAG(지식 기반 검색), 모델 중복성/장애 조치, 호출별 보안 정책 및 스트리밍을 갖춘 AI 채팅 완료를 위한 기본 엔드포인트입니다.

엔드포인트

설명

선택적 RAG(지식 기반 검색)를 사용하여 AI 채팅 완료를 위한 기본 엔드포인트입니다. 다음을 지원합니다:
  • 두 가지 입력 형식 — 단일 prompt 문자열(레거시) 또는 OpenAI 스타일 messages 배열.
  • 모델 중복성 — 호출자가 정의한 장애 조치 체인(기본 + 최대 2개의 대체) 이중화 및 장애 조치를 참조하세요.
  • 호출별 보안 — SMLTP 정책 선택 및 인라인 Prompt Shield 재정의.
  • 스트리밍 — 서버에서 보낸 이벤트(SSE).
  • 서명된 영수증 — 게이트웨이를 통해 라우팅된 응답에 대한 SMLTP 준수 영수증 참조입니다.
OpenAI SDK 호환성코드 변경 없음으로 기존 OpenAI 통합에 SecureAI를 추가하려면 /api/external/v1/chat/completions에서 OpenAI 호환 엔드포인트를 대신 사용하세요. 이 클래식 엔드포인트는 RAG를 지원하는 유일한 엔드포인트입니다.

인증

필수: API 키

헤더

요청 본문

입력 매개변수

**prompt 또는 messages 중 하나를 제공하세요. 둘 다 제공할 수는 없습니다.

모델 및 중복성 매개변수

검색 및 생성 매개변수

요청 예시

응답

성공 응답 (200)

메타데이터 개체

스트리밍

서버에서 보낸 이벤트를 수신하려면 "stream": true를 설정하세요. 각 SSE 라인은 data: <json>이고 스트림은 data: [DONE]로 끝납니다. 프레임은 type 필드를 통해 입력됩니다.

오류 응답

400 잘못된 요청

401 승인되지 않음

403 금지됨

429 / 502 — 중복 체인이 소진되었습니다.

중복 체인의 모든 모델이 실패하면 응답은 각 시도를 보고합니다. 모든 실패가 비율 제한인 경우 상태는 429이고, 그렇지 않은 경우 502입니다.

500 내부 서버 오류

사용 예

자바스크립트/Node.js

파이썬

메모

  • index이 필요합니다. RAG 없이 직접 AI 응답을 위해 index: "Zero-Knowledge"를 보냅니다.
  • user_id 매개변수는 요청을 다른 사용자 계정(관리자 관리)으로 청구합니다.
  • 온도는 0~2로 고정됩니다. max_tokens는 4000으로 제한됩니다.
  • 모델 호출이나 포인트 지출 없이**모든 정책에 대해 요청을 검증하려면 정책 확인을 사용하세요.
  • 장애 조치 체인 의미(트리거, 시간 초과, 스트리밍 동작, 소진 상태 코드)는 Redundancy & Failover를 참조하세요.

인증

Authorization
string
header
필수

API key authentication using Bearer token format. Example: Authorization: Bearer sk-your-api-key-here

본문

application/json
prompt
string
필수

The user's message/prompt

예시:

"What is the company's policy on remote work?"

model
string

The AI model to use for completion

예시:

"openai/gpt-4.1-mini"

index
string

Knowledge base to search for context (use 'Zero-Knowledge' for direct AI responses)

예시:

"my-knowledge-base"

smltp_policy
string

Security policy to apply

예시:

"internal"

temperature
number<float>
기본값:0.7

Controls randomness in the response (0 = deterministic, 2 = very random)

필수 범위: 0 <= x <= 2
예시:

0.7

max_tokens
integer
기본값:1000

Maximum number of tokens in the response

필수 범위: 1 <= x <= 4000
예시:

1000

stream
boolean
기본값:false

Whether to stream the response

예시:

false

conversation_id
string

Optional conversation ID for tracking

예시:

"conv-123"

system_message
string

Optional custom system message

예시:

"You are a helpful assistant."

use_rag
boolean
기본값:true

Whether to use RAG (knowledge base retrieval)

예시:

true

user_id
string

MongoDB ObjectId of the user to bill for this request. If not provided, the API key owner will be billed

예시:

"60a7c8f5e8b4f5001f7a8c23"

응답

Successful chat completion

success
boolean
예시:

true

id
string
예시:

"req-abc123"

object
string
예시:

"chat.completion"

created
integer
예시:

1705312200

model
string
예시:

"openai/gpt-4.1-mini"

choices
object[]
usage
object
metadata
object