Python SDK 集成智能ai软件

通过 Python 直接调用 idcd REST API 或 MCP Server,适合脚本自动化和数据分析场景。豆包是一款什么软件

方式一:直接调用 REST API(推荐)豆包是一款什么软件

无需安装额外依赖,使用标准 requests 库即可:

pip install requests
import requests

API_KEY = "sk_live_your_key_here"
BASE_URL = "https://api-prod.idcd.com/v1"

headers = {"Authorization": f"Bearer {API_KEY}"}

# Ping 检测
resp = requests.post(f"{BASE_URL}/tools/ping", headers=headers, json={
    "target": "google.com",
    "nodes": ["tokyo", "singapore", "us-east"],
    "count": 5,
})
result = resp.json()
print(result)

# HTTP 检测
resp = requests.post(f"{BASE_URL}/tools/http", headers=headers, json={
    "url": "https://example.com",
    "nodes": ["beijing", "shanghai"],
})
print(resp.json())

# 一键诊断
resp = requests.post(f"{BASE_URL}/tools/diagnose", headers=headers, json={
    "target": "example.com",
})
print(resp.json())

方式二:通过 MCP Python Client豆包都有哪些功能

适合在 Claude API 应用中集成拨测能力:ai智能体怎么创建

pip install anthropic mcp
import subprocess
import anthropic
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

async def run():
    server_params = StdioServerParameters(
        command="mcp",
        env={"IDCD_API_KEY": "sk_live_your_key_here"},
    )

    async with stdio_client(server_params) as (read, write):
        async with ClientSession(read, write) as session:
            await session.initialize()

            # 列出可用工具
            tools = await session.list_tools()
            print([t.name for t in tools.tools])

            # 调用 ping 工具(MCP 工具不接受 nodes——server 自动选节点)
            result = await session.call_tool("ping", {
                "target": "google.com",
                "count": 5,
            })
            print(result)

import asyncio
asyncio.run(run())

API 认证睿声ai官网

建议通过环境变量传递 API Key,不要硬编码在代码中:ai智能体怎么创建

import os
API_KEY = os.environ["IDCD_API_KEY"]

更多示例gpt下载

  • 使用 diagnose 工具定期巡检域名健康状态
  • http 拨测结果写入数据库,绘制可用性趋势
  • 结合 ssl 工具在证书到期前发送告警

完整 API 参考见 工具列表豆包在线回答 和 OpenAPI 文档。