Back to Blog
AI Technology

AI检测API怎么接?3行代码搞定

AI检测API怎么接?3行代码搞定!手把手教你用Python接入UnFox AI API,企业必备。

Unfox AI

Unfox AI

Content Team

5 min read
AI检测api接入教程开发文档

「AI检测API怎么用?」

「代码怎么写?」

「企业怎么批量检测?」

你是不是也想把AI检测接入自己的系统?

今天这篇文章,我用最简单的方式,3行代码教你接入UnFox AI API。


一、API是什么?(1分钟理解)

1.1 通俗解释

API = 告诉别人「我想干什么,别人帮你干」

就像点外卖:

  • 你 = 你的程序
  • 外卖平台 = API
  • 餐厅 = UnFox AI服务器

你告诉平台要什么,平台帮你搞定。

1.2 AI检测API的作用

不用API 用API
手动复制粘贴 程序自动调用
一次检测1篇 一次检测100篇
每天100次 每天无限次

二、快速开始(3行代码)

2.1 Python示例

import requests

# 1行:调用API
result = requests.post("https://api.unfox.cn/v1/detect", 
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json={"text": "要检测的文本内容"}
).json()

# 2行:获取结果
print(f"AI率: {result['ai_percentage']}%")
print(f"可能来源: {result.get('source_model', '未知')}")

2.2 Node.js示例

const axios = require('axios');

axios.post('https://api.unfox.cn/v1/detect', {
    text: '要检测的文本内容'
}, {
    headers: { 'Authorization': 'Bearer YOUR_API_KEY' }
}).then(res => {
    console.log(`AI率: ${res.data.ai_percentage}%`);
    console.log(`可能来源: ${res.data.source_model || '未知'}`);
});

三、批量检测

3.1 Python批量检测

import requests

def batch_detect(texts):
    url = "https://api.unfox.cn/v1/detect/batch"
    headers = {"Authorization": "Bearer YOUR_API_KEY"}

    items = [{"id": f"item_{i}", "text": text} for i, text in enumerate(texts)]

    response = requests.post(url, json={"items": items}, headers=headers)
    return response.json()

# 使用示例
texts = ["文本1", "文本2", "文本3"]
results = batch_detect(texts)
print(results)

3.2 返回结果格式

{
    "results": [
        {"id": "item_0", "ai_percentage": 85, "source_model": "ChatGPT"},
        {"id": "item_1", "ai_percentage": 12, "source_model": null},
        {"id": "item_2", "ai_percentage": 92, "source_model": "文心一言"}
    ],
    "total": 3,
    "success": true
}

四、完整企业级示例

4.1 内容审核系统

import requests
from datetime import datetime

class ContentModerator:
    def __init__(self, api_key):
        self.api_key = api_key
        self.url = "https://api.unfox.cn/v1/detect"

    def check_content(self, content_id, text, threshold=50):
        """检测内容"""
        headers = {"Authorization": f"Bearer {self.api_key}"}
        data = {"text": text}

        response = requests.post(self.url, json=data, headers=headers)
        result = response.json()

        return {
            "content_id": content_id,
            "ai_percentage": result["ai_percentage"],
            "source_model": result.get("source_model"),
            "need_review": result["ai_percentage"] > threshold,
            "checked_at": datetime.now().isoformat()
        }

    def batch_check(self, contents, threshold=50):
        """批量检测"""
        results = []
        for content_id, text in contents:
            result = self.check_content(content_id, text, threshold)
            results.append(result)

        return {
            "total": len(results),
            "need_review": sum(1 for r in results if r["need_review"]),
            "results": results
        }

# 使用示例
moderator = ContentModerator("YOUR_API_KEY")
results = moderator.batch_check([
    ("article_1", "文本内容1..."),
    ("article_2", "文本内容2..."),
    ("article_3", "文本内容3...")
])
print(results)

4.2 监控系统

import requests
import time

def monitor_and_alert(content_queue, webhook_url, threshold=70):
    """监控内容并告警"""
    while True:
        if content_queue.empty():
            time.sleep(1)
            continue

        content = content_queue.get()
        result = check_ai_content(content["text"])

        if result["ai_percentage"] > threshold:
            send_alert(webhook_url, {
                "content_id": content["id"],
                "ai_percentage": result["ai_percentage"],
                "action": "需要人工审核"
            })

        time.sleep(0.1)

五、API文档速查

5.1 接口地址

环境 地址
正式环境 https://api.unfox.cn/v1/detect
测试环境 https://test-api.unfox.cn/v1/detect

5.2 请求方式

方法 端点 说明
POST /v1/detect 单条检测
POST /v1/detect/batch 批量检测
GET /v1/balance 查询余额

5.3 请求参数

单条检测:

参数 类型 必填 说明
text string 要检测的文本(最大5000字)
language string 语言代码(zh/en/ja等)

批量检测:

参数 类型 必填 说明
items array 最多100条/批次
items[].id string 内容ID
items[].text string 内容文本

六、错误处理

6.1 常见错误码

错误码 说明 处理方法
200 成功 -
400 参数错误 检查参数
401 认证失败 检查API Key
429 请求过多 降低频率
500 服务器错误 重试

6.2 重试机制

import time
from requests.exceptions import RequestException

def retry_request(func, max_retries=3):
    """带重试的请求"""
    for i in range(max_retries):
        try:
            return func()
        except RequestException as e:
            if i == max_retries - 1:
                raise e
            time.sleep(2 ** i)  # 指数退避

七、总结

3行代码接入:

import requests
result = requests.post("https://api.unfox.cn/v1/detect", 
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json={"text": "要检测的文本"}
).json()

核心要点:

  1. API让批量检测成为可能
  2. Python/Node.js都可以轻松接入
  3. 批量检测提升效率100倍
  4. 企业级应用需要错误处理

立即获取API Key:unfox.cn

3行代码,让你的系统具备AI检测能力。

Unfox AI

Written by Unfox AI

Content Team

Passionate about creating exceptional content and sharing knowledge with the community.

Related Articles

Ready to start your next project?

Join thousands of developers who are already building amazing applications with our platform.

AI检测API怎么接?3行代码搞定