You need to enable JavaScript to run this app.
文档中心
向量数据库VikingDB

向量数据库VikingDB

复制全文
下载 pdf
API 文档
API 鉴权说明
复制全文
下载 pdf
API 鉴权说明

OpenViking 支持通过 API 接口进行操作,调用 API 接口的前提条件是获取 API Key 并完成鉴权配置。本文介绍 API Key 的获取方法并提供完整调用示例。

获取 API Key

在调用 OpenViking 的各项能力之前,请确保您已获取 API Key。
请按照以下步骤获取您的 API Key:

  1. 登录 OpenViking 控制台。
  2. 在左侧导航栏下方进入【用户管理】。
  3. 复制您的 API Key,妥善保存备用。

个人版用户在注册后系统会自动为其创建一个默认管理员账户,并生成对应的 API Key,可直接在控制台查看和使用。
Image

鉴权方式

每次调用 API 时,需在 HTTP 请求头中携带以下鉴权参数:

Header

是否必选

示例

说明

Authorization

Authorization: Bearer {api_key}

API Key 鉴权

X-OpenViking-Agent

X-OpenViking-Agent: {agent_id}

Agent ID,用于指定本次请求操作的 Agent

Content-Type

Content-Type: application/json

请求体类型。JSON 接口使用 application/json;文件上传接口使用 multipart/form-data

使用 curl -F 或 SDK 的文件上传能力时,通常无需手动设置 multipart/form-data 的 boundary,由客户端自动生成即可。

API 调用示例

以下为调用 /api/v1/resources 接口的多语言示例代码。请将示例中的占位符替换为您在控制台获取的实际值。

Python

import json
import requests

BASE_URL = "https://api.vikingdb.cn-beijing.volces.com/openviking"
API_KEY  = "your-api-key"         # 替换为您的 API Key
AGENT_ID = "your-agent-id"        # 替换为您的 Agent ID

headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {API_KEY}",
    "X-OpenViking-Agent": AGENT_ID,
}

result = requests.post(
    f"{BASE_URL}/api/v1/resources",
    headers=headers,
    json={
        "path": "http://example.com",
        "to": "viking://resources",
        "reason": "导入外部文档",
    },
    timeout=120.0,
)
result.raise_for_status()
print(json.dumps(result.json(), ensure_ascii=False, indent=2))

curl

curl -X POST https://xxx/api/v1/resources \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {api_key}" \
  -H "X-OpenViking-Agent: {agent_id}" \
  -d '{"path": "http://example.com", "to": "viking://resources", "reason": "导入外部文档"}'

Node.js

import fetch from "node-fetch";

const BASE_URL  = "https://api.vikingdb.cn-beijing.volces.com/openviking";        // 替换为实际服务地址
const API_KEY   = "your-api-key";       // 替换为您的 API Key
const AGENT_ID  = "your-agent-id";      // 替换为您的 Agent ID

const resp = await fetch(`${BASE_URL}/api/v1/resources`, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": `Bearer ${API_KEY}`,
    "X-OpenViking-Agent": AGENT_ID,
  },
  body: JSON.stringify({
    path: "http://example.com",
    to: "viking://resources",
    reason: "导入外部文档",
  }),
});
console.log(await resp.json());

Go

package main

import (
   "bytes"
   "encoding/json"
   "fmt"
   "net/http"
)

const (
   baseURL = "https://xxx"       // 替换为实际服务地址
   apiKey  = "your-api-key"      // 替换为您的 API Key
   agentID = "your-agent-id"     // 替换为您的 Agent ID
)

func main() {
   body, _ := json.Marshal(map[string]string{
      "path":   "http://example.com",
      "to":     "viking://resources",
      "reason": "导入外部文档",
   })
   req, _ := http.NewRequest("POST", baseURL+"/api/v1/resources", bytes.NewReader(body))
   req.Header.Set("Content-Type", "application/json")
   req.Header.Set("Authorization", "Bearer "+apiKey)
   req.Header.Set("X-OpenViking-Agent", agentID)

   resp, _ := http.DefaultClient.Do(req)
   defer resp.Body.Close()
   var result map[string]interface{}
   json.NewDecoder(resp.Body).Decode(&result)
   fmt.Println(result)
}

鉴权相关错误码

HTTP 状态码

error.code

描述

401

AuthenticationError / UNAUTHENTICATED

缺少 API Key、API Key 无效,或请求中的鉴权格式不正确

403

PERMISSION_DENIED

API Key 权限不足

最近更新时间:2026.05.26 11:52:49
这个页面对您有帮助吗?
有用
有用
无用
无用