OpenAI chat completions
기준일: 2026-07-26
공식 기준: OpenAI chat completions
OpenAI chat completions 문서는 OpenClaw 공식 문서(gateway/openai-http-api)를 한국어로 정리한 가이드입니다. Expose an OpenAI-compatible /v1/chat/completions HTTP endpoint from the Gateway 명령·설정 키·코드 예시는 공식 문서를 그대로 보존하며, 해석과 절차 안내는 한국어로 제공합니다. 최종 동작은 설치된 CLI 버전과 공식 원문을 확인하세요.
핵심 요약
Expose an OpenAI-compatible /v1/chat/completions HTTP endpoint from the Gateway
한국어 가이드 범위: gateway/openai-http-api 경로의 설정·명령·제약·예시를 학습용으로 재구성합니다.
문서 구성
공식 문서의 주요 섹션은 다음과 같습니다.
- Enabling the endpoint
- Security boundary (important)
- 인증
- When to use this endpoint
- Agent-first model contract
- Session behavior
- Request limits
- Chat tool contract
- Supported request fields
- Unsupported variants
- Non-streaming tool response shape
- Streaming tool response shape
- Tool follow-up loop
- Streaming (SSE)
- Open WebUI quick setup
- 예제
- 관련 문서
상세 내용
본문
The Gateway can serve a small OpenAI-compatible Chat Completions surface. It is disabled by default.
위 내용은 공식 문서의 해당 섹션 요지입니다. 세부 플래그·기본값은 원문과
--help를 확인하세요.
| Method | Path |
|---|---|
| POST | /v1/chat/completions |
| GET | /v1/models |
| GET | /v1/models/{id} |
| POST | /v1/embeddings |
| POST | /v1/responses |
Enabling the endpoint
Set enabled: false (or omit it) to disable.
위 내용은 공식 문서의 해당 섹션 요지입니다. 세부 플래그·기본값은 원문과
--help를 확인하세요.
{
gateway: {
http: {
endpoints: {
chatCompletions: { enabled: true },
},
},
},
}
Security boundary (important)
Treat this endpoint as full operator access to the gateway instance:
위 내용은 공식 문서의 해당 섹션 요지입니다. 세부 플래그·기본값은 원문과
--help를 확인하세요.
주요 항목:
- A valid Gateway token/password for this endpoint is equivalent to an owner/operator credential, not a narrow per-user scope.
- Requests run through the same control-plane agent path as trusted operator actions, so if the target agent's policy allows sensitive tools, this endpoint can use them.
- Keep it on loopback/tailnet/private ingress only. Do not expose it to the public internet.
| Auth path | Behavior |
|---|---|
gateway.auth.mode="token" or "password" + Authorization: Bearer ... |
Proves possession of the shared gateway secret. Ignores any x-openclaw-scopes header and restores the full default operator scope set: operator.admin, operator.approvals, operator.pairing, operator.read, operator.talk.secrets, operator.write. Treats chat turns as owner-sender turns. |
Trusted identity-bearing HTTP (trusted-proxy auth, or gateway.auth.mode="none" on private ingress) |
Honors x-openclaw-scopes when present; falls back to the default operator scope set when absent. Loses owner semantics only when the caller explicitly narrows scopes and omits operator.admin. Requires operator.admin for owner-level controls such as x-openclaw-model. |
인증
Uses the Gateway auth configuration (see Trusted proxy auth for that mode's details):
위 내용은 공식 문서의 해당 섹션 요지입니다. 세부 플래그·기본값은 원문과
--help를 확인하세요.
주요 항목:
- Same-host callers that bypass the proxy on a
trusted-proxygateway can fall back togateway.auth.password/OPENCLAW_GATEWAY_PASSWORDdirectly. AnyForwarded,X-Forwarded-*, orX-Real-IPheader evidence keeps the request on the trusted-proxy path instead. - If
gateway.auth.rateLimitis configured and too many auth attempts fail, the endpoint returns429with aRetry-Afterheader.
| Mode | How to authenticate |
|---|---|
gateway.auth.mode="token" |
Authorization: Bearer <token>. Set via gateway.auth.token or OPENCLAW_GATEWAY_TOKEN. |
gateway.auth.mode="password" |
Authorization: Bearer <password>. Set via gateway.auth.password or OPENCLAW_GATEWAY_PASSWORD. |
gateway.auth.mode="trusted-proxy" |
Route through the configured identity-aware proxy; it injects the required identity headers. Same-host loopback proxies need explicit gateway.auth.trustedProxy.allowLoopback = true. |
gateway.auth.mode="none" |
No auth header required (private ingress only). |
When to use this endpoint
주요 항목:
- Prefer this over adding a new built-in channel when your integration is just another operator/client surface for the same gateway.
- For native mobile clients that connect directly to a remote gateway, prefer WebChat or the Gateway Protocol with the paired-device bootstrap/device-token flow, so the device does not need a shared HTTP token/password.
- Build a channel plugin instead when integrating an external messaging network with its own users, rooms, webhook delivery, or outbound transport. See Building plugins.
Agent-first model contract
OpenClaw treats the OpenAI model field as an agent target, not a raw provider model id.
위 내용은 공식 문서의 해당 섹션 요지입니다. 세부 플래그·기본값은 원문과
--help를 확인하세요.
model value |
Routes to |
|---|---|
openclaw |
Configured default agent |
openclaw/default |
Configured default agent (stable alias; safe to hardcode even if the real default agent id changes between environments) |
openclaw/<agentId> or openclaw:<agentId> |
Specific agent |
agent:<agentId> |
Specific agent (compatibility alias) |
| Header | Effect |
|---|---|
x-openclaw-model: <provider/model-or-bare-id> |
Overrides the backend model for the selected agent. Shared-secret bearer callers can use this directly; identity-bearing callers (trusted-proxy, or private no-auth ingress with x-openclaw-scopes) need operator.admin, otherwise 403 missing scope: operator.admin. |
x-openclaw-agent-id: <agentId> |
Compatibility override for agent selection. |
x-openclaw-session-key: <sessionKey> |
Explicit session routing. Rejected with 400 invalid_request_error if it uses a reserved internal namespace (subagent:, cron:, acp:). |
x-openclaw-message-channel: <channel> |
Sets the synthetic ingress channel context for channel-aware prompts/policies. |
Session behavior
By default the endpoint is stateless per request (a new session key is generated each call).
위 내용은 공식 문서의 해당 섹션 요지입니다. 세부 플래그·기본값은 원문과
--help를 확인하세요.
Request limits
The endpoint uses built-in limits of 20 MB per request body, 8 image_url parts from the latest user message, and 20 MB of cumulative decoded image data. Image source policy remains configurable under gateway.http.endpoints.chatCompletions.images:
위 내용은 공식 문서의 해당 섹션 요지입니다. 세부 플래그·기본값은 원문과
--help를 확인하세요.
| Key | Default |
|---|---|
images.allowUrl |
false (URL-sourced image_url parts are rejected unless enabled) |
images.maxBytes |
10MB per image |
images.maxRedirects |
3 |
images.timeoutMs |
10s |
{
gateway: {
http: {
endpoints: {
chatCompletions: {
enabled: true,
images: {
allowUrl: false,
urlAllowlist: ["cdn.example.com", "*.assets.example.com"],
allowedMimes: [
"image/jpeg",
"image/png",
"image/gif",
"image/webp",
"image/heic",
"image/heif",
],
maxBytes: 10485760,
maxRedirects: 3,
timeoutMs: 10000,
},
},
},
},
},
}
Chat tool contract
/v1/chat/completions supports a function-tool subset compatible with common OpenAI Chat clients.
위 내용은 공식 문서의 해당 섹션 요지입니다. 세부 플래그·기본값은 원문과
--help를 확인하세요.
Supported request fields
All sampling and token-cap fields ride the same agent stream-param channel and are forwarded best-effort:
위 내용은 공식 문서의 해당 섹션 요지입니다. 세부 플래그·기본값은 원문과
--help를 확인하세요.
주요 항목:
- Token cap: the wire field name is chosen by the provider transport:
max_completion_tokensfor OpenAI-family endpoints,max_tokensfor providers that only accept the legacy name (Mistral, Chutes). stopmaps to the transport's stop field:stopfor Chat Completions backends,stop_sequencesfor Anthropic. The OpenAI Responses API has no stop parameter, sostopis not applied on Responses-backed models.- The ChatGPT-based Codex Responses backend uses fixed server-side sampling and strips
temperature/top_p(along withmax_output_tokens,metadata,prompt_cache_retention,service_tier) before the request reaches that backend.
| Field | Notes |
|---|---|
tools |
Array of { "type": "function", "function": { ... } } |
tool_choice |
"auto", "none", "required", or { "type": "function", "function": { "name": "..." } } |
messages[*].role: "tool" |
Follow-up turns |
messages[*].tool_call_id |
Binds a tool result back to a prior tool call |
max_completion_tokens |
Number; per-call cap on total completion tokens (reasoning tokens included). Current field name; used when both it and max_tokens are sent. |
max_tokens |
Number; legacy alias, ignored when max_completion_tokens is also present. |
temperature |
Number 0-2; best-effort, forwarded to the upstream provider. 400 invalid_request_error if out of range. |
top_p |
Number 0-1; best-effort. 400 invalid_request_error if out of range. |
frequency_penalty |
Number -2.0 to 2.0; best-effort. 400 invalid_request_error if out of range. |
presence_penalty |
Number -2.0 to 2.0; best-effort. 400 invalid_request_error if out of range. |
seed |
Integer; best-effort. 400 invalid_request_error for non-integer values. |
stop |
String or array of up to 4 strings; best-effort. 400 invalid_request_error for more than 4 sequences or non-string/empty entries. |
Unsupported variants
For tool_choice: "required" and function-pinned tool_choice, the endpoint narrows the exposed client function-tool set, instructs the runtime to call a client tool before responding, and errors if the agent response has no matching structured client-tool call. This applies to the caller-supplied HTTP tools list, not every internal OpenClaw agent tool.
위 내용은 공식 문서의 해당 섹션 요지입니다. 세부 플래그·기본값은 원문과
--help를 확인하세요.
주요 항목:
- non-array
tools, non-function tool entries, or missingtool.function.name tool_choicevariants such asallowed_toolsandcustomtool_choice.function.namevalues that do not match a provided tool
Non-streaming tool response shape
When the agent calls tools, the response uses:
위 내용은 공식 문서의 해당 섹션 요지입니다. 세부 플래그·기본값은 원문과
--help를 확인하세요.
주요 항목:
choices[0].finish_reason = "tool_calls"choices[0].message.tool_calls[]entries withid,type: "function",function.name,function.arguments(JSON string)- Assistant commentary before the tool call, in
choices[0].message.content(possibly empty)
Streaming tool response shape
When stream: true, tool calls arrive as incremental SSE chunks: an initial assistant role delta, optional assistant commentary deltas, one or more delta.tool_calls chunks carrying tool identity and argument fragments, then a final chunk with finish_reason: "tool_calls" and data: [DONE].
위 내용은 공식 문서의 해당 섹션 요지입니다. 세부 플래그·기본값은 원문과
--help를 확인하세요.
Tool follow-up loop
After receiving tool_calls, execute the requested function(s) and send a follow-up request that includes the prior assistant tool-call message plus one or more role: "tool" messages with matching tool_call_id. This continues the same agent reasoning loop to produce the final answer.
위 내용은 공식 문서의 해당 섹션 요지입니다. 세부 플래그·기본값은 원문과
--help를 확인하세요.
Streaming (SSE)
Set stream: true to receive Server-Sent Events:
위 내용은 공식 문서의 해당 섹션 요지입니다. 세부 플래그·기본값은 원문과
--help를 확인하세요.
주요 항목:
Content-Type: text/event-stream- Each event line is
data: <json> - Stream ends with
data: [DONE]
Open WebUI quick setup
Expected behavior: GET /v1/models lists openclaw/default, and Open WebUI uses it as the chat model id. For a specific backend provider/model, set the agent's normal default model, or send x-openclaw-model (shared-secret caller, or identity-bearing caller with operator.admin).
위 내용은 공식 문서의 해당 섹션 요지입니다. 세부 플래그·기본값은 원문과
--help를 확인하세요.
주요 항목:
- Base URL:
http://127.0.0.1:18789/v1 - Docker on macOS base URL:
http://host.docker.internal:18789/v1 - API key: your Gateway bearer token
- Model:
openclaw/default
curl -sS http://127.0.0.1:18789/v1/models \
-H 'Authorization: Bearer YOUR_TOKEN'
예제
Reuse the same user value on later calls for that conversation to continue the same agent session.
위 내용은 공식 문서의 해당 섹션 요지입니다. 세부 플래그·기본값은 원문과
--help를 확인하세요.
curl -sS http://127.0.0.1:18789/v1/chat/completions \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"model": "openclaw/default",
"user": "conv:YOUR_CONVERSATION_ID",
"messages": [{"role":"user","content":"Summarize my tasks for today"}]
}'
curl -sS http://127.0.0.1:18789/v1/chat/completions \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"model": "openclaw/default",
"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-model: openai/gpt-5.4' \
-d '{
"model": "openclaw/research",
"stream": true,
"messages": [{"role":"user","content":"hi"}]
}'
curl -sS http://127.0.0.1:18789/v1/models \
-H 'Authorization: Bearer YOUR_TOKEN'
관련 문서
주요 항목:
- Configuration reference
- Operator scopes
- OpenAI
실습 체크리스트
- 공식 문서와 로컬 버전을 대조합니다:
https://docs.openclaw.ai/gateway/openai-http-api - 관련 CLI는
openclaw --help및 하위 명령--help로 옵션을 확인합니다. - 설정 변경 시
openclaw config/openclaw doctor로 유효성을 검사합니다. - Gateway·채널·플러그인 변경 후에는 필요 시 Gateway를 재시작합니다.
자주 쓰는 명령·설정 예시
{
gateway: {
http: {
endpoints: {
chatCompletions: { enabled: true },
},
},
},
}
{
gateway: {
http: {
endpoints: {
chatCompletions: {
enabled: true,
images: {
allowUrl: false,
urlAllowlist: ["cdn.example.com", "*.assets.example.com"],
allowedMimes: [
"image/jpeg",
"image/png",
"image/gif",
"image/webp",
"image/heic",
"image/heif",
],
maxBytes: 10485760,
maxRedirects: 3,
timeoutMs: 10000,
},
},
},
},
},
}
curl -sS http://127.0.0.1:18789/v1/models \
-H 'Authorization: Bearer YOUR_TOKEN'
curl -sS http://127.0.0.1:18789/v1/chat/completions \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"model": "openclaw/default",
"user": "conv:YOUR_CONVERSATION_ID",
"messages": [{"role":"user","content":"Summarize my tasks for today"}]
}'
curl -sS http://127.0.0.1:18789/v1/chat/completions \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"model": "openclaw/default",
"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-model: openai/gpt-5.4' \
-d '{
"model": "openclaw/research",
"stream": true,
"messages": [{"role":"user","content":"hi"}]
}'
관련 링크
이 가이드는 공식 문서를 한국어 학습용으로 재구성한 것입니다. 옵션 기본값·플래그 이름은 설치 버전에 따라 달라질 수 있습니다.