对接RAGflow的API接口,报错:
{"status":"success","message":"API连接正常","response":{"code":109,"data":false,"message":"Authentication error: API key is invalid!"}}
可能原因:
-
未提供 API Key:请求头中缺少
Authorization
字段。 -
API Key 格式错误:未按照
Bearer <YOUR_API_KEY>
格式填写。
排查,使用脚本测试:
import httpx
import asyncio
async def test_ragflow_api():
api_key = "ragflow-JXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
base_url = "http://1.1.1.1:80"
# 测试获取数据集列表
async with httpx.AsyncClient() as client:
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
# 测试 GET /api/v1/datasets
response = await client.get(
f"{base_url}/api/v1/datasets",
headers=headers
)
print(f"状态码: {response.status_code}")
print(f"响应内容: {response.text}")
if __name__ == "__main__":
asyncio.run(test_ragflow_api())
回复响应:
状态码: 200
响应内容: {"code":0,"data":[{"avatar":"","chunk_count":23477,"chunk_method":"naive","create_date":"Wed, 05 Mar 2025 20:01:47 GMT","create_time":1741176107637,"created_by":"95ebec74f9b911efaecd0242ac130006","description":"GMP\u77e5\u8bc6\u5e93","document_count":559,"embedding_model":"BAAI/bge-large-zh-v1.5@BAAI","id":"9d600508f9b911ef94c20242ac130006","language":"Chinese","name":"GMP\u77e5\u8bc6\u5e93","pagerank":20,"parser_config":{"auto_keywords":5,"auto_questions":2,"chunk_token_num":128,"delimiter":"\\n!?;\u3002\uff1b\uff01\uff1f","graphrag":{"entity_types":["organization","person","geo","event","category"],"method":"light","use_graphrag":true},"html4excel":true,"layout_recognize":"DeepDOC","raptor":{"use_raptor":false}},"permission":"team","similarity_threshold":0.2,"status":"1","tenant_id":"95ebec74f9b911efaecd0242ac130006","token_num":1736587,"update_date":"Sat, 08 Mar 2025 22:03:32
GMT","update_time":1741442612144,"vector_similarity_weight":0.3}]}
API调用成功了:
1. 状态码是200,表示请求成功
2. 响应内容是一个JSON对象,包含了数据集列表信息:
- code: 0 (表示成功)
- data: 包含了一个数据集的详细信息
- 数据集信息包括:
- name: "知识库"
- chunk_count: 23477
- document_count: 559
- language: "Chinese"
- embedding_model: "BAAI/bge-large-zh-v1.5@BAAI"
等