🔐

AI Gateway 管理

請輸入 Admin Token 以存取管理面板

🤖 AI Gateway 管理

運行中 Keys: — 佇列: —
最近 Sessions
SessionAppUser狀態耗時時間
API Key 池
ID標籤KeyBase URL模型速率調用狀態操作
已註冊應用 已選 0 項
App ID名稱用戶數創建操作
用戶列表 已選 0 項
AppUser IDLocal Path最後活躍操作
Session 歷史 已選 0 項
Session IDAppUser狀態查詢耗時時間操作
用戶彙整 已選 0 項
AppUser週區間摘要時間操作
📐 客戶端接入協議

客戶端透過 HTTPS POST 發送 JSON 封裝的請求,取得 AI 回覆。所有通信均使用 TLS 加密(Let's Encrypt 證書)。

⚠️ 中國大陸網路備用入口 主入口: https://www.herelai.fun/ws/05-ai-gateway/api/query 備用入口: https://43-135-184-31.sslip.io/ws/05-ai-gateway/api/query 若中國大陸未開 VPN 時 herelai.fun 域名 HTTPS 被中斷,請將客戶端 endpoint 臨時切換到備用入口。備用入口同樣使用 Let's Encrypt 正式 HTTPS 憑證,可直接用於 iOS/Android/Web 客戶端。

1️⃣ 請求格式 (Client → Server)

POST https://www.herelai.fun/ws/05-ai-gateway/api/query Content-Type: application/json Protocol: HTTPS (TLS 1.2+, Let's Encrypt 證書) { "app_id": "your_app_identifier", "user_id": "user_unique_id", "query_data": "用戶的問題或輸入內容", "messages": [ {"role": "user", "content": "之前的對話"}, {"role": "assistant", "content": "AI 之前的回覆"}, {"role": "user", "content": "用戶的問題或輸入內容"} ], "options": { "temperature": 0.7, "max_tokens": 2000 } }

💡 messages 陣列支持多輪對話上下文(原生 OpenAI 格式),AI 能準確理解歷史對話。若同時提供 query_data 和 messages,優先使用 messages。

2️⃣ 成功回覆 (Server → Client)

{ "success": true, "session_id": "sess_app1_user1_1746123456789", "response": "AI 生成的回覆內容...", "local_path": "/data/app1/user1", "duration_ms": 2340, "context_used": true, "model": "meta/llama-3.1-8b-instruct" }

3️⃣ 錯誤回覆

{ "success": false, "session_id": "sess_xxx", "error": "錯誤描述(Queue full / API timeout 等)" }

4️⃣ JavaScript / React Native 範例

async function queryAI(appId, userId, question) { const res = await fetch( 'https://www.herelai.fun/ws/05-ai-gateway/api/query', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ app_id: appId, user_id: userId, query_data: question, }), } ); const result = await res.json(); return result.success ? result.response : null; } // 使用 const answer = await queryAI('my_app', 'user123', '你好');

5️⃣ Swift / iOS 範例

func queryAI(appId: String, userId: String, question: String) async -> String? { var req = URLRequest(url: URL(string: "https://www.herelai.fun/ws/05-ai-gateway/api/query")!) req.httpMethod = "POST" req.setValue("application/json", forHTTPHeaderField: "Content-Type") req.httpBody = try? JSONSerialization.data(withJSONObject: [ "app_id": appId, "user_id": userId, "query_data": question ]) let (data, _) = try? await URLSession.shared.data(for: req) let r = try? JSONSerialization.jsonObject(with: data!) as? [String: Any] return r?["success"] as? Bool == true ? r?["response"] as? String : nil }

6️⃣ Kotlin / Android 範例

suspend fun queryAI(appId: String, userId: String, q: String): String? { val json = JSONObject().apply { put("app_id", appId); put("user_id", userId); put("query_data", q) } val body = json.toString().toRequestBody("application/json".toMediaType()) val req = Request.Builder() .url("https://www.herelai.fun/ws/05-ai-gateway/api/query") .post(body).build() return OkHttpClient().newCall(req).execute().use { resp -> val r = JSONObject(resp.body!!.string()) if (r.getBoolean("success")) r.getString("response") else null } }

7️⃣ 文字生成圖片 — 請求格式 (Client → Server)

POST https://www.herelai.fun/ws/05-ai-gateway/api/image/generate Content-Type: application/json { "app_id": "your_app_identifier", "user_id": "user_unique_id", "prompt": "想要生成的圖片描述(中英文皆可,最長 1000 字)", "options": { "size": "1024x1024", "n": 1 } }

💡 options 可省略(預設 1024x1024、1 張)。生成約需 5–15 秒,請將客戶端逾時設為 30 秒以上。

8️⃣ 文字生成圖片 — 成功回覆 (Server → Client)

{ "success": true, "session_id": "img_app1_user1_1792583649662", "images": [ { "url": "https://www.herelai.fun/ws/05-ai-gateway/files/data/app1/user1/images/img_xxx.png", "remote_url": "https://...(供應商原始連結,有時效性)", "b64_json": null } ], "model": "cogview-3-flash", "local_path": "data/app1/user1", "duration_ms": 8500 }

💡 url 為本站永久連結(圖片已存於本機 data/ 目錄),可直接用 <img> / AsyncImage 顯示;remote_url 為供應商臨時連結,僅作備用,請優先使用 url。

9️⃣ 文字生成圖片 — JavaScript / React Native 範例

async function genImage(appId, userId, prompt) { const res = await fetch( 'https://www.herelai.fun/ws/05-ai-gateway/api/image/generate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ app_id: appId, user_id: userId, prompt: prompt, }), } ); const r = await res.json(); return r.success ? r.images[0].url : null; } // 使用: const imgUrl = await genImage('my_app', 'user123', '一隻戴眼鏡的橘貓在看書'); // <img src={imgUrl} /> 或 Image組件直接顯示

🔟 文字生成圖片 — Swift / iOS 範例

func genImage(appId: String, userId: String, prompt: String) async -> URL? { var req = URLRequest(url: URL(string: "https://www.herelai.fun/ws/05-ai-gateway/api/image/generate")!) req.httpMethod = "POST" req.setValue("application/json", forHTTPHeaderField: "Content-Type") req.httpBody = try? JSONSerialization.data(withJSONObject: [ "app_id": appId, "user_id": userId, "prompt": prompt ]) struct ImgRsp: Decodable { struct Img: Decodable { let url: String? } let images: [Img] } guard let (data, _) = try? await URLSession.shared.data(for: req), let r = try? JSONDecoder().decode(ImgRsp.self, from: data), let s = r.images.first?.url else { return nil } return URL(string: s) } // 使用: // if let url = await genImage(appId: "my_app", userId: "user123", prompt: "一隻戴眼鏡的橘貓") { // AsyncImage(url: url) // SwiftUI 直接顯示 // }