← 返回 Skills 市场
lemonteeeeaa

baidu-aistudio-llm-api

作者 lemonteeeeaa · GitHub ↗ · v1.0.3 · MIT-0
cross-platform ⚠ suspicious
360
总下载
0
收藏
1
当前安装
4
版本数
在 OpenClaw 中安装
/install baidu-aistudio-llm-api
功能描述
百度「AI Studio 星河社区」大模型 API 调用助手,帮助开发者快速接入大模型 API 服务,调用文心(ERNIE)、DeepSeek 等大模型能力。该服务依托百度智能云千帆平台,兼容 OpenAI Python SDK,可直接使用原生 openai-python SDK 接入开发,同时支持模型调用、使用...
使用说明 (SKILL.md)

baidu-aistudio-llm-api / 百度 AI Studio 星河社区大模型API调用

Official Skill from Baidu 「AI Studio」: Baidu AI Studio LLM API Access

概述

星河大模型API是为开发者提供的一套基础大模型服务,背靠百度智能云千帆平台,提供文心(ERNIE)、DeepSeek等大模型能力。该服务完全兼容OpenAI Python SDK,开发者可直接使用原生openai-python SDK调用。

福利:注册即送100万免费Tokens额度!

The Baidu 「AI Studio」 LLM API Assistant helps developers quickly connect to large model API services and access capabilities from models such as ERNIE and DeepSeek. Powered by the Baidu Intelligent Cloud Qianfan Platform, this service is compatible with the OpenAI Python SDK, allowing developers to integrate directly using the native openai-python SDK. It also provides guidance on model invocation, integration workflows, and related usage questions.✨ Bonus: Sign up and receive 1 million free tokens!

快速开始

Step 1: 获取API Key

检查用户是否已设置环境变量 AI_STUDIO_API_KEY

# 检查环境变量
echo $AI_STUDIO_API_KEY

如果没有设置,提醒用户:

请访问 https://aistudio.baidu.com/account/accessToken 获取您的访问令牌(Access Token),然后设置环境变量:

# macOS/Linux
export AI_STUDIO_API_KEY="您的访问令牌"

# Windows PowerShell
$env:AI_STUDIO_API_KEY="您的访问令牌"

# 或使用 .env 文件
echo 'AI_STUDIO_API_KEY="您的访问令牌"' >> .env

Step 2: 安装依赖

pip install openai

Step 3: 基本调用

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ.get("AI_STUDIO_API_KEY"),
    base_url="https://aistudio.baidu.com/llm/lmapi/v3",
)

response = client.chat.completions.create(
    model="ernie-5.0-thinking-preview",
    messages=[
        {"role": "system", "content": "你是一个有帮助的AI助手。"},
        {"role": "user", "content": "你好!"}
    ]
)

print(response.choices[0].message.content)

模型选择指南

根据用户需求推荐合适的模型:

使用场景 推荐模型 说明
深度思考 ernie-5.0-thinking-preview 最新ERNIE 5.0,思维链推理
代码生成 deepseek-v3 / qwen3-coder 代码能力强
复杂推理 deepseek-r1 思维链推理,复杂问题
通用对话 kimi-k2-instruct Moonshot开源模型
长文本处理 ernie-4.5-turbo-128k-preview 128K上下文
多模态 ernie-4.5-turbo-vl 支持图像、视频理解
快速响应 ernie-speed-8k 速度快

完整模型列表请查看: references/models.md

常用功能示例

流式输出

completion = client.chat.completions.create(
    model="ernie-5.0-thinking-preview",
    messages=[{"role": "user", "content": "讲个故事"}],
    stream=True,
)

for chunk in completion:
    print(chunk.choices[0].delta.content or "", end="", flush=True)

多轮对话

messages = [
    {"role": "system", "content": "你是AI助手。"}
]

# 添加用户消息
messages.append({"role": "user", "content": "你好"})

# 获取回复
response = client.chat.completions.create(
    model="kimi-k2-instruct",
    messages=messages
)

# 保存到历史
messages.append({
    "role": "assistant",
    "content": response.choices[0].message.content
})

联网搜索(搜索增强)

completion = client.chat.completions.create(
    model="ernie-5.0-thinking-preview",
    messages=[{"role": "user", "content": "今天北京天气"}],
    extra_body={
        "web_search": {
            "enable": True,
            "enable_trace": True
        }
    }
)

支持联网搜索的模型: ernie-5.0, ernie-4.5, deepseek-r1, deepseek-v3

Function Calling

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "获取天气信息",
        "parameters": {
            "type": "object",
            "properties": {
                "city": {"type": "string", "description": "城市名"}
            },
            "required": ["city"]
        }
    }
}]

response = client.chat.completions.create(
    model="deepseek-v3",
    messages=[{"role": "user", "content": "北京今天天气"}],
    tools=tools,
    tool_choice="auto"
)

支持Function Call的模型: ernie-5.0-thinking-preview, ernie-x1-turbo, deepseek-r1, deepseek-v3

结构化输出(JSON)

response = client.chat.completions.create(
    model="ernie-4.5-turbo-128k-preview",
    messages=[{"role": "user", "content": "列出三个水果"}],
    response_format={"type": "json_object"}
)

深度思考模型(思维链)

response = client.chat.completions.create(
    model="deepseek-r1",
    messages=[{"role": "user", "content": "请解释相对论"}]
)

# 思维链内容
print(response.choices[0].message.reasoning_content)
# 最终回答
print(response.choices[0].message.content)

多模态(图像理解)

response = client.chat.completions.create(
    model="ernie-4.5-turbo-vl",
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": "描述这张图片"},
            {"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
        ]
    }]
)

文生图

images = client.images.generate(
    prompt="一只可爱的白猫,戴着红帽子",
    model="Stable-Diffusion-XL",
    response_format="url"
)
print(images.data[0].url)

文本向量化

embeddings = client.embeddings.create(
    model="embedding-v1",
    input=["你好世界", "机器学习"]
)
print(embeddings.data[0].embedding)

高级功能

详细的API参数说明和更多功能,请查看:

常见错误处理

错误码 说明 解决方案
401 认证失败 检查API Key是否正确
429 请求限流 降低请求频率或等待
400 参数错误 检查messages格式和参数
403 内容安全 修改输入内容

官方资源

  • 安装教程:《在OpenClaw中安装星河社区 Skills》
  • API文档:https://ai.baidu.com/ai-doc/AISTUDIO/rm344erns
  • 获取Token:https://aistudio.baidu.com/account/accessToken
  • 使用明细:登录星河社区后查看

Resources

scripts/

  • test_connection.py - 测试API连接
  • list_models.py - 查询可用模型列表

references/

  • models.md - 完整模型列表和能力说明
  • api_params.md - API参数详细说明
安全使用建议
This skill appears to do what it claims (help call Baidu AI Studio), but the package metadata failed to declare the required API token (AI_STUDIO_API_KEY). Before installing or using it: 1) confirm you are comfortable providing your Baidu AI Studio Access Token to the example code; 2) prefer setting the token in a secure secrets store or environment variable (not checked into code); 3) be aware that the instructions ask you to pip install the 'openai' package (third‑party code from PyPI); and 4) ask the publisher to update the registry metadata to list AI_STUDIO_API_KEY as a required credential so the skill's manifest matches its runtime behavior. If the publisher cannot justify the missing metadata, treat the omission as a higher-risk signal.
功能分析
Type: OpenClaw Skill Name: baidu-aistudio-llm-api Version: 1.0.3 The skill bundle is a legitimate integration for the Baidu AI Studio LLM API. It contains documentation and utility scripts (scripts/list_models.py, scripts/test_connection.py) that use the official OpenAI Python SDK to interact with Baidu's API endpoints. The instructions in SKILL.md are helpful and transparent, focusing on environment variable setup and basic usage examples without any signs of malicious intent, data exfiltration, or prompt injection.
能力评估
Purpose & Capability
Name, description, SKILL.md, example scripts, and reference docs all consistently describe a Baidu AI Studio (星河) LLM API helper. The code files (test_connection.py, list_models.py) and examples use the OpenAI-compatible OpenAI client pointed at aistudio.baidu.com, which aligns with the declared purpose.
Instruction Scope
Runtime instructions and example scripts are narrowly scoped to: check/set AI_STUDIO_API_KEY, pip install openai, instantiate an OpenAI client with aistudio base_url, and call model endpoints. They do not instruct reading unrelated files, other env vars, or exfiltrating data to unknown endpoints.
Install Mechanism
There is no formal install spec (instruction-only). SKILL.md instructs users to run 'pip install openai' which will install a third-party package from PyPI. That is typical for this kind of skill but means the installer will pull external code; the skill itself does not include any obscure downloads or installers.
Credentials
The documentation and scripts clearly require the environment variable AI_STUDIO_API_KEY, but the registry metadata lists 'Required env vars: none' and 'Primary credential: none'. This metadata omission is an inconsistency: the skill does request a sensitive credential (an API token) for its stated purpose, and that should be declared explicitly. No other unrelated credentials are requested.
Persistence & Privilege
The skill does not request persistent system privileges, does not set 'always: true', and contains no installation steps that modify other skills or system-wide agent settings. Autonomous invocation is allowed (platform default) but not combined with other red flags.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install baidu-aistudio-llm-api
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /baidu-aistudio-llm-api 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.3
- Updated English description for improved clarity and detail in SKILL.md. - Added an official-skill introduction and summary in both English and Chinese at the top of the documentation. - No code or example changes; core usage and API details remain consistent.
v1.0.2
更新Skill简介
v1.0.1
- 更新模型推荐与示例为最新的ERNIE 5.0及kimi/k2、qwen3-coder等新模型,调整模型推荐表内容。 - 部分代码示例采用更先进模型(如"ernie-5.0-thinking-preview" 和 "kimi-k2-instruct")。 - 扩展Function Call和联网搜索功能的支持模型。 - 增加了官方安装教程链接,便于用户上手。 - 说明和资源部分同步完善,提供更直观的模型选择建议和资源路径。
v1.0.0
fisrt publish
元数据
Slug baidu-aistudio-llm-api
版本 1.0.3
许可证 MIT-0
累计安装 1
当前安装数 1
历史版本数 4
常见问题

baidu-aistudio-llm-api 是什么?

百度「AI Studio 星河社区」大模型 API 调用助手,帮助开发者快速接入大模型 API 服务,调用文心(ERNIE)、DeepSeek 等大模型能力。该服务依托百度智能云千帆平台,兼容 OpenAI Python SDK,可直接使用原生 openai-python SDK 接入开发,同时支持模型调用、使用... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 360 次。

如何安装 baidu-aistudio-llm-api?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install baidu-aistudio-llm-api」即可一键安装,无需额外配置。

baidu-aistudio-llm-api 是免费的吗?

是的,baidu-aistudio-llm-api 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

baidu-aistudio-llm-api 支持哪些平台?

baidu-aistudio-llm-api 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 baidu-aistudio-llm-api?

由 lemonteeeeaa(@lemonteeeeaa)开发并维护,当前版本 v1.0.3。

💬 留言讨论