OpenAI Chat Completions (HTTP)
OpenClaw의 Gateway는 작은 OpenAI 호환 Chat Completions 엔드포인트를 제공할 수 있습니다.
이 엔드포인트는 기본적으로 비활성화되어 있습니다. 먼저 설정에서 활성화하세요.
- POST /v1/chat/completions
- Gateway와 동일한 포트 (WS + HTTP 멀티플렉스): http://<gateway-host>:<port>/v1/chat/completions
내부적으로 요청은 일반 Gateway 에이전트 실행으로 실행됩니다 (openclaw agent와 동일한 코드 경로), 따라서 라우팅/권한/설정이 Gateway와 일치합니다.
인증
Gateway 인증 설정을 사용합니다. bearer 토큰 전송:
- Authorization: Bearer <token>
참고사항:
- gateway.auth.mode="token"일 때, gateway.auth.token (또는 OPENCLAW_GATEWAY_TOKEN) 사용.
- gateway.auth.mode="password"일 때, gateway.auth.password (또는 OPENCLAW_GATEWAY_PASSWORD) 사용.
에이전트 선택
커스텀 헤더가 필요 없습니다: OpenAI model 필드에 에이전트 id를 인코딩하세요:
- model: "openclaw:<agentId>" (예: "openclaw:main", "openclaw:beta")
- model: "agent:<agentId>" (별칭)
또는 헤더로 특정 OpenClaw 에이전트를 타겟팅:
- x-openclaw-agent-id: <agentId> (기본값: main)
고급:
- x-openclaw-session-key: <sessionKey> 세션 라우팅을 완전히 제어합니다.
엔드포인트 활성화
gateway.http.endpoints.chatCompletions.enabled를 true로 설정:
{
gateway: {
http: {
endpoints: {
chatCompletions: { enabled: true }
}
}
}
}
엔드포인트 비활성화
gateway.http.endpoints.chatCompletions.enabled를 false로 설정:
{
gateway: {
http: {
endpoints: {
chatCompletions: { enabled: false }
}
}
}
}
세션 동작
기본적으로 엔드포인트는 요청당 상태 비저장입니다 (각 호출마다 새 세션 키가 생성됨).
요청에 OpenAI user 문자열이 포함되어 있으면 Gateway는 이로부터 안정적인 세션 키를 파생하여 반복 호출이 에이전트 세션을 공유할 수 있습니다.
스트리밍 (SSE)
Server-Sent Events (SSE)를 수신하려면 stream: true를 설정하세요:
- Content-Type: text/event-stream
- 각 이벤트 줄은 data: <json>
- 스트림은 data: [DONE]으로 종료
예제
비스트리밍:
curl -sS http://127.0.0.1:18789/v1/chat/completions \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-H 'x-openclaw-agent-id: main' \
-d '{
"model": "openclaw",
"messages": [{"role":"user","content":"hi"}]
}'
스트리밍:
curl -N http://127.0.0.1:18789/v1/chat/completions \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-H 'x-openclaw-agent-id: main' \
-d '{
"model": "openclaw",
"stream": true,
"messages": [{"role":"user","content":"hi"}]
}'