From 72a059ff2b4026c08c39a7171a030d2a5d0be34b Mon Sep 17 00:00:00 2001 From: codergma Date: Thu, 2 Apr 2026 10:16:58 +0800 Subject: [PATCH] docs: document configurable pinme api base url --- skills/pinme-api/SKILL.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/skills/pinme-api/SKILL.md b/skills/pinme-api/SKILL.md index ff2b46c..dad99d9 100644 --- a/skills/pinme-api/SKILL.md +++ b/skills/pinme-api/SKILL.md @@ -16,16 +16,17 @@ Worker 创建时自动注入以下环境变量,无需手动配置: export interface Env { DB: D1Database; API_KEY: string; // 项目 API Key — 用于 send_email 和 chat/completions 认证 + BASE_URL?: string; // 可选覆盖 PinMe API 基础地址,默认 https://pinme.dev } ``` -> `API_KEY` 是 Worker 调用 PinMe 平台 API 的唯一凭证。 +> `API_KEY` 是 Worker 调用 PinMe 平台 API 的唯一凭证。`BASE_URL` 未设置时默认使用 `https://pinme.dev`。 --- ## API 1:发送邮件 -**端点:** `POST https://pinme.dev/api/v4/send_email` +**端点:** `POST {BASE_URL}/api/v4/send_email` **认证:** `X-API-Key` header(使用 `env.API_KEY`) **发件人:** 自动为 `{project_name}@pinme.dev` @@ -64,7 +65,8 @@ export interface Env { ```typescript async function sendEmail(env: Env, to: string, subject: string, html: string): Promise<{ ok: boolean; error?: string }> { - const resp = await fetch('https://pinme.dev/api/v4/send_email', { + const baseUrl = env.BASE_URL ?? 'https://pinme.dev'; + const resp = await fetch(`${baseUrl}/api/v4/send_email`, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -100,7 +102,7 @@ async function handleSendVerification(request: Request, env: Env): Promise, model = 'openai/gpt-4o-mini', ): Promise<{ content: string; error?: string }> { + const baseUrl = env.BASE_URL ?? 'https://pinme.dev'; const resp = await fetch( - `https://pinme.dev/api/v1/chat/completions?project_name=${projectName}`, + `${baseUrl}/api/v1/chat/completions?project_name=${projectName}`, { method: 'POST', headers: { @@ -206,13 +209,14 @@ async function handleChat(request: Request, env: Env): Promise { async function handleChatStream(request: Request, env: Env): Promise { const body = await request.text(); const projectName = getProjectName(request); + const baseUrl = env.BASE_URL ?? 'https://pinme.dev'; // 确保请求中 stream=true let parsed = JSON.parse(body); parsed.stream = true; const resp = await fetch( - `https://pinme.dev/api/v1/chat/completions?project_name=${projectName}`, + `${baseUrl}/api/v1/chat/completions?project_name=${projectName}`, { method: 'POST', headers: { @@ -329,16 +333,18 @@ async function callPinmeAPI(url: string, apiKey: string, body: unknown): Prom ### 使用示例 ```typescript +const baseUrl = env.BASE_URL ?? 'https://pinme.dev'; + // 发邮件 const emailResult = await callPinmeAPI<{ ok: boolean }>( - 'https://pinme.dev/api/v4/send_email', env.API_KEY, + `${baseUrl}/api/v4/send_email`, env.API_KEY, { to: 'user@example.com', subject: 'Hello', html: '

Hi

' }, ); if (emailResult.error) return json({ error: emailResult.error }, 500); // 调 LLM(非流式) const llmResult = await callPinmeAPI<{ choices: Array<{ message: { content: string } }> }>( - `https://pinme.dev/api/v1/chat/completions?project_name=${projectName}`, env.API_KEY, + `${baseUrl}/api/v1/chat/completions?project_name=${projectName}`, env.API_KEY, { model: 'openai/gpt-4o-mini', messages: [{ role: 'user', content: 'Hi' }] }, ); if (llmResult.error) return json({ error: llmResult.error }, 502);