文档/入门
将您的应用程序连接到 Clydex。
连接 Responses、配置您的客户端并添加在您的应用程序中运行的工具。
开始之前
- 创建并复制密钥 API 密钥。保密。
- 选择可用型号 渠道与模型。使用其确切 ID 代替
<MODEL_ID>下面。 - 打开下面的指南。更换
<YOUR_CLYDEX_API_KEY>用您的密钥并保存文件。
https://clydex.shop/v1想要为您填写设置吗?点击 使用钥匙 在您的钥匙卡上,选择您的应用程序,然后复制或下载其配置。
选择您的应用程序
Codex CLI / App
将 Codex 与两个文件连接。
- 在文件管理器中打开 ~/.codex。如果缺少该文件夹,请创建该文件夹。
- 将设置保存为 config.toml。将顶级设置放在任何 [section] 标题之前;保留您的其他设置。
- 将 auth.json 保存在同一文件夹中,然后重新启动 Codex 或您的编辑器并开始新的聊天。
model_provider = "clydex"
model = "<MODEL_ID>"
disable_response_storage = true
cli_auth_credentials_store = "file"
web_search = "disabled"
[model_providers.clydex]
name = "Clydex"
base_url = "https://clydex.shop/v1"
wire_api = "responses"
requires_openai_auth = true
supports_websockets = false
request_max_retries = 0
stream_max_retries = 0{
"OPENAI_API_KEY": "<YOUR_CLYDEX_API_KEY>"
}在替换之前备份现有的 auth.json。这些设置也适用于 Codex IDE 扩展。
OpenCode
一个配置文件,然后在OpenCode中选择Clydex。
- 打开~/.config/opencode,如果不存在则创建opencode.json。
- 粘贴此配置。如果您已有配置,请将 Clydex 提供程序和模型设置合并到其中。
- 重新启动OpenCode。运行 /models 并选择 Clydex 下的模型。
{
"$schema": "https://opencode.ai/config.json",
"model": "clydex/<MODEL_ID>",
"small_model": "clydex/<MODEL_ID>",
"provider": {
"clydex": {
"npm": "@ai-sdk/openai",
"name": "Clydex",
"options": {
"baseURL": "https://clydex.shop/v1",
"apiKey": "<YOUR_CLYDEX_API_KEY>"
},
"models": {
"<MODEL_ID>": {
"name": "<MODEL_ID>",
"options": {
"store": false
}
}
}
}
}
}Hermes
从您的终端连接 Hermes。
- 打开~/.hermes/config.yaml。如果需要,创建文件夹和文件。
- 用这些设置替换模型部分;保留其余配置。
- 保存文件,重新启动 Hermes,并开始新的对话。
model:
provider: custom
default: "<MODEL_ID>"
base_url: "https://clydex.shop/v1"
api_mode: codex_responses
api_key: "<YOUR_CLYDEX_API_KEY>"Cherry Studio
在Cherry Studio设置中添加Clydex。
- 打开设置 → 模型提供程序并添加名为 Clydex 的提供程序。
- 选择 OpenAI Responses 作为端点类型。将 API 地址和密钥粘贴到下面。
- 添加模型 ID <MODEL_ID>,启用提供程序,然后在新聊天中选择该模型。
https://clydex.shop/v1/<YOUR_CLYDEX_API_KEY><MODEL_ID>关闭网络搜索和附件。在旧版本中,提供程序类型称为 OpenAI-Response。
API / SDKs
将您的 Clydex 密钥与 OpenAI SDK Responses API 结合使用。
- 选择 Python、JavaScript 或下面的终端示例。
- 对于 Python,运行 pip install openai,然后运行 python hello.py。对于 JavaScript,运行 npm install openai,然后运行 node hello.mjs。
https://clydex.shop/v1from openai import OpenAI
client = OpenAI(
api_key="<YOUR_CLYDEX_API_KEY>",
base_url="https://clydex.shop/v1",
max_retries=0,
)
response = client.responses.create(
model="<MODEL_ID>",
input="Say hello in one sentence.",
max_output_tokens=128,
store=False,
)
print(response.output_text)import OpenAI from "openai";
const client = new OpenAI({
apiKey: "<YOUR_CLYDEX_API_KEY>",
baseURL: "https://clydex.shop/v1",
maxRetries: 0,
});
const response = await client.responses.create({
model: "<MODEL_ID>",
input: "Say hello in one sentence.",
max_output_tokens: 128,
store: false,
});
console.log(response.output_text);curl 'https://clydex.shop/v1/responses' \
-H 'Authorization: Bearer <YOUR_CLYDEX_API_KEY>' \
-H 'Content-Type: application/json' \
-d '{
"model": "<MODEL_ID>",
"input": "Say hello in one sentence.",
"max_output_tokens": 128,
"store": false
}'将包含您的密钥的文件保密。在您的计算机或服务器上运行 SDK 示例,切勿在公共浏览器代码中运行。
功能工具
在中声明函数 tools。模型返回一个调用,您的应用程序执行它,然后您发回一个 function_call_output 与相同的 call_id。下面的示例显示了完整的往返行程。
Python 示例:使用本地函数
使用客户端 hello.py 上面,用这个例子替换它的请求。它最多可发出两个模型请求并运行本地时钟功能。
import json
import uuid
from datetime import datetime, timezone
history = [{"role": "user", "content": "What time is it in UTC?"}]
tools = [{
"type": "function",
"name": "get_utc_time",
"description": "Return the current UTC time.",
"parameters": {
"type": "object",
"properties": {},
"required": [],
"additionalProperties": False,
},
"strict": True,
}]
first = client.responses.create(
model="<MODEL_ID>", input=history, tools=tools,
tool_choice={"type": "function", "name": "get_utc_time"},
parallel_tool_calls=False,
include=["reasoning.encrypted_content"],
max_output_tokens=256, store=False,
extra_headers={"Idempotency-Key": str(uuid.uuid4())},
)
history.extend(item.model_dump(exclude_none=True) for item in first.output)
calls = [item for item in first.output if item.type == "function_call"]
if len(calls) != 1 or calls[0].name != "get_utc_time":
raise RuntimeError("Expected one get_utc_time call; check the response.")
call = calls[0]
if json.loads(call.arguments) != {}:
raise RuntimeError("Unexpected function arguments.")
history.append({
"type": "function_call_output",
"call_id": call.call_id,
"output": json.dumps({"utc": datetime.now(timezone.utc).isoformat()}),
})
final = client.responses.create(
model="<MODEL_ID>", input=history, tools=tools, tool_choice="none",
include=["reasoning.encrypted_content"],
max_output_tokens=256, store=False,
extra_headers={"Idempotency-Key": str(uuid.uuid4())},
)
print(final.output_text)在构建下一轮时保留返回的输出项,包括推理项。在执行函数之前验证应用程序中的工具名称和参数。自定义工具使用 custom_tool_call 和 custom_tool_call_output 具有相同的调用/结果模式。
更多帮助
流媒体和请求选项
套装 stream: true 用于通过 HTTP 传输响应。工具调用参数可以在多个事件中到达;在执行之前组装完整的调用。最终使用到达终端响应事件。 WebSocket 传输不可用。
套装 max_output_tokens 满足您要求的输出长度。这不是有保证的支出上限。如果所选模型支持推理选项、文本冗长和结构化文本格式,则可接受它们。保持存储关闭并每次发送完整的对话历史记录。
