AI 后端 API 服务 返回产品介绍

📖 接口文档

本地部署,标准 HTTP 接口,任意语言均可调用

🚀 启动程序

PowerShell
ZhiMeiAPI.exe --port 5000 --key ABCD-EFGH-IJKL-MNOP
参数简写必填说明
--port-p是服务监听端口
--key-k是卡密
--nogpu无否加上表示禁用 GPU,仅用 CPU

启动成功后,通过 http://<机器地址>:<port>/ 访问下面的接口。

📋 接口列表

方法路径说明
GET/api/status查询服务状态
POST/api/rewrite提交文本改写
POST/api/stop停止当前生成任务
POST/api/shutdown关闭程序
POST/api/license/logout退出登录(释放卡密授权占用,不关闭程序)
POST/api/license/relogin重新登录(使用传入的卡密重新激活)

GET查询服务状态

/api/status

响应

JSON
{
  "isActivated": true,
  "maxThread": 4,
  "performanceScore": 87.5,
  "isModelLoaded": true,
  "unauthorizedReason": null
}
curl
curl http://127.0.0.1:5000/api/status
Python
import requests
print(requests.get("http://127.0.0.1:5000/api/status").json())
.NET
using var http = new HttpClient { BaseAddress = new Uri("http://127.0.0.1:5000") };
var status = await http.GetFromJsonAsync<StatusResponse>("api/status");

public record StatusResponse(bool IsActivated, int MaxThread, float PerformanceScore, bool IsModelLoaded, string? UnauthorizedReason);

POST文本改写

/api/rewrite

请求参数

字段类型必填说明
contentstring是需要改写的原文
levelint否(默认 5)改写强度,1~10
streambool否(默认 false)是否流式返回
并发限制:改写任务最大并发数由 /api/status 返回的 maxThread 决定(根据显存/性能自动评估)。超出并发上限的请求会在服务端自动排队等待空闲槽位,无需客户端自行限流,但排队期间响应会相应延迟。
错误即失败:改写过程中如果任意一段内容改写出错(非客户端取消/服务端超时),会立即中止本次改写并返回失败,success 为 false、error 携带具体原因;不会返回部分结果或占位符内容,请直接根据 error 提示重试。

非流式(stream: false)

响应:

JSON
{ "success": true, "result": "改写后的内容", "error": null }
curl
curl -X POST http://127.0.0.1:5000/api/rewrite \
  -H "Content-Type: application/json" \
  -d "{\"content\":\"这是一段需要改写的文字\",\"level\":5,\"stream\":false}"
Python
import requests

resp = requests.post(
    "http://127.0.0.1:5000/api/rewrite",
    json={"content": "这是一段需要改写的文字", "level": 5, "stream": False},
    timeout=300,
)
data = resp.json()
print(data["result"] if data["success"] else data["error"])
.NET
using var http = new HttpClient { BaseAddress = new Uri("http://127.0.0.1:5000"), Timeout = TimeSpan.FromMinutes(5) };

var response = await http.PostAsJsonAsync("api/rewrite", new { content = "这是一段需要改写的文字", level = 5, stream = false });
var result = await response.Content.ReadFromJsonAsync<RewriteResult>();
Console.WriteLine(result!.Success ? result.Result : result.Error);

public record RewriteResult(bool Success, string Result, string? Error);

流式(stream: true)

响应为 SSE,每段以 data: <内容>\n\n 推送,结束时发送 data: [DONE]\n\n。

curl
curl -N -X POST http://127.0.0.1:5000/api/rewrite \
  -H "Content-Type: application/json" \
  -d "{\"content\":\"这是一段需要改写的文字\",\"level\":5,\"stream\":true}"
Python
import requests

resp = requests.post(
    "http://127.0.0.1:5000/api/rewrite",
    json={"content": "这是一段需要改写的文字", "level": 5, "stream": True},
    stream=True,
    timeout=300,
)

for line in resp.iter_lines(decode_unicode=True):
    if not line or not line.startswith("data: "):
        continue
    payload = line[len("data: "):]
    if payload == "[DONE]":
        break
    print(payload, end="", flush=True)
.NET
using var http = new HttpClient { BaseAddress = new Uri("http://127.0.0.1:5000") };

var request = new HttpRequestMessage(HttpMethod.Post, "api/rewrite")
{
    Content = JsonContent.Create(new { content = "这是一段需要改写的文字", level = 5, stream = true })
};

using var response = await http.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
await using var stream = await response.Content.ReadAsStreamAsync();
using var reader = new StreamReader(stream);

string? line;
while ((line = await reader.ReadLineAsync()) is not null)
{
    if (!line.StartsWith("data: ")) continue;
    var payload = line["data: ".Length..];
    if (payload == "[DONE]") break;
    Console.Write(payload);
}

常见错误码

状态码说明
403服务未授权
400content 为空或 level 不在 1~10
499客户端主动断开连接
504改写超时
500内部异常

POST停止生成任务

/api/stop

curl
curl -X POST http://127.0.0.1:5000/api/stop
Python
import requests
print(requests.post("http://127.0.0.1:5000/api/stop").json())
.NET
var resp = await http.PostAsync("api/stop", null);
Console.WriteLine(await resp.Content.ReadAsStringAsync());

POST关闭程序

/api/shutdown

curl
curl -X POST http://127.0.0.1:5000/api/shutdown
Python
import requests
print(requests.post("http://127.0.0.1:5000/api/shutdown").json())
.NET
var resp = await http.PostAsync("api/shutdown", null);
Console.WriteLine(await resp.Content.ReadAsStringAsync());

POST退出登录

/api/license/logout

仅释放当前卡密占用的授权 Session(例如准备更换设备时使用),不会关闭程序。调用成功后本进程会转为未授权状态,/api/rewrite 会返回 403,直到重新调用 /api/license/relogin 或程序重新自动激活成功。

请求参数

字段类型必填说明
keystring是需要释放授权占用的卡密

响应

JSON
{ "message": "退出登录成功,已释放授权占用" }
curl
curl -X POST http://127.0.0.1:5000/api/license/logout \
  -H "Content-Type: application/json" \
  -d "{\"key\":\"ABCD-EFGH-IJKL-MNOP\"}"
Python
import requests
resp = requests.post("http://127.0.0.1:5000/api/license/logout", json={"key": "ABCD-EFGH-IJKL-MNOP"})
print(resp.json())
.NET
var resp = await http.PostAsJsonAsync("api/license/logout", new { key = "ABCD-EFGH-IJKL-MNOP" });
Console.WriteLine(await resp.Content.ReadAsStringAsync());

POST重新登录

/api/license/relogin

使用传入的卡密重新调用授权服务器激活。可以是当前卡密(重新激活/续期失败后手动恢复),也可以是另一个卡密(切换授权)。激活成功后该卡密会成为程序当前生效的卡密,后续自动续租、退出登录都会使用它。

请求参数

字段类型必填说明
keystring是用于重新登录的卡密

响应

JSON
{ "message": "重新登录成功" }

失败时 message 会携带具体原因,例如:

JSON
{ "message": "重新登录失败: 该卡密正在被其他客户端使用" }
curl
curl -X POST http://127.0.0.1:5000/api/license/relogin \
  -H "Content-Type: application/json" \
  -d "{\"key\":\"ABCD-EFGH-IJKL-MNOP\"}"
Python
import requests
resp = requests.post("http://127.0.0.1:5000/api/license/relogin", json={"key": "ABCD-EFGH-IJKL-MNOP"})
print(resp.json())
.NET
var resp = await http.PostAsJsonAsync("api/license/relogin", new { key = "ABCD-EFGH-IJKL-MNOP" });
Console.WriteLine(await resp.Content.ReadAsStringAsync());
有其他集成需求?微信咨询:sjt2345