OpenClaw人人养虾:OpenAI Chat Completions API
Gateway 提供与 OpenAI Chat Completions API 兼容的 HTTP 端点。任何支持 OpenAI API 的客户端库都可以直接连接 Gateway。端点POST /v1/chat/completions完整 URLhttp://127.0.0.1:18789/v1/chat/completions (本地) https://gateway.example.com/v1/chat/completions (远程)认证通过Authorization头传递 Gateway Tokencurl -X POST http://127.0.0.1:18789/v1/chat/completions \ -H Authorization: Bearer $OPENCLAW_GATEWAY_TOKEN \ -H Content-Type: application/json \ -d {model:gpt-4o,messages:[{role:user,content:Hello}]}兼容性使用 Gateway Token 替代 OpenAI API Key。Gateway 会自动路由到正确的 Channel 和模型。请求格式{ model: gpt-4o, messages: [ { role: system, content: You are a helpful assistant. }, { role: user, content: What is the capital of France? } ], temperature: 0.7, max_tokens: 1024, stream: false, tools: [] }请求参数参数类型必填说明modelstring✅模型标识由 Gateway 路由到对应 Channelmessagesarray✅对话消息数组temperaturenumber❌温度参数0~2默认 1max_tokensnumber❌最大生成 Token 数streamboolean❌是否启用流式响应默认falsetoolsarray❌可用工具定义tool_choicestring/object❌工具选择策略top_pnumber❌核采样参数frequency_penaltynumber❌频率惩罚presence_penaltynumber❌存在惩罚响应格式非流式响应{ id: chatcmpl-abc123, object: chat.completion, created: 1705312200, model: gpt-4o, choices: [ { index: 0, message: { role: assistant, content: The capital of France is Paris. }, finish_reason: stop } ], usage: { prompt_tokens: 25, completion_tokens: 8, total_tokens: 33 } }流式响应设置stream: true启用 Server-Sent EventsSSE服务端推送事件流式响应curl -X POST http://127.0.0.1:18789/v1/chat/completions \ -H Authorization: Bearer $OPENCLAW_GATEWAY_TOKEN \ -H Content-Type: application/json \ -d {model:gpt-4o,messages:[{role:user,content:Hello}],stream:true}响应流data: {id:chatcmpl-abc,choices:[{delta:{role:assistant},index:0}]} data: {id:chatcmpl-abc,choices:[{delta:{content:The},index:0}]} data: {id:chatcmpl-abc,choices:[{delta:{content: capital},index:0}]} data: {id:chatcmpl-abc,choices:[{delta:{content: is},index:0}]} data: [DONE]工具调用定义工具{ model: gpt-4o, messages: [ {role: user, content: Whats the weather in Beijing?} ], tools: [ { type: function, function: { name: get_weather, description: Get current weather for a location, parameters: { type: object, properties: { location: { type: string, description: City name } }, required: [location] } } } ] }工具调用响应{ choices: [ { message: { role: assistant, tool_calls: [ { id: call_abc123, type: function, function: { name: get_weather, arguments: {\location\: \Beijing\} } } ] }, finish_reason: tool_calls } ] }多模型路由Gateway 根据model字段自动路由到对应的 Channel# 路由到 OpenAI Channel curl -d {model:gpt-4o,messages:[...]} # 路由到 Anthropic Channel curl -d {model:claude-sonnet-4-20250514,messages:[...]} # 路由到本地 Ollama curl -d {model:llama3,messages:[...]}统一入口不同提供商的模型通过同一个端点访问。Gateway 自动处理 API 格式差异。客户端库集成Python (openai)Node.js (openai)from openai import OpenAI client OpenAI( base_urlhttp://127.0.0.1:18789/v1, api_keyyour-gateway-token ) response client.chat.completions.create( modelgpt-4o, messages[{role: user, content: Hello}] ) print(response.choices[0].message.content)《DeepSeek高效数据分析从数据清洗到行业案例》聚焦DeepSeek在数据分析领域的高效应用是系统讲解其从数据处理到可视化全流程的实用指南。作者结合多年职场实战经验不仅深入拆解DeepSeek数据分析的核心功能——涵盖数据采集、清洗、预处理、探索分析、建模回归、聚类、时间序列等及模型评估更通过金融量化数据分析、电商平台数据分析等真实行业案例搭配报告撰写技巧提供独到见解与落地建议。助力职场人在激烈竞争中凭借先进技能突破瓶颈实现职业进阶开启发展新篇。