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 tok
来自百度的官方技能「AI Studio」: 百度 AI Studio 大模型API接入
星河大模型API是为开发者提供的一套基础大模型服务,背靠百度智能云千帆平台,提供文心(ERNIE)、DeepSeek等大模型能力。该服务完全兼容OpenAI Python SDK,开发者可直接使用原生openai-python SDK调用。
福利:注册即送100万免费Tokens额度!
百度「AI Studio」大模型API助手帮助开发者快速接入大模型API服务,获取文心(ERNIE)和DeepSeek等模型的能力。该服务由百度智能云千帆平台提供支持,兼容OpenAI Python SDK,开发者可直接使用原生openai-python SDK进行集成。同时还提供模型调用、集成工作流及相关使用问题的指导。✨ 福利:注册即送100万免费Tokens额度!
检查用户是否已设置环境变量 AISTUDIOAPI_KEY:
bash
如果没有设置,提醒用户:
请访问 https://aistudio.baidu.com/account/accessToken 获取您的访问令牌(Access Token),然后设置环境变量:
bash
macOS/Linux
export AISTUDIOAPI_KEY=您的访问令牌
Windows PowerShell
$env:AISTUDIOAPI_KEY=您的访问令牌
或使用 .env 文件
echo AISTUDIOAPI_KEY=您的访问令牌 >> .env步骤2: 安装依赖
bash
pip install openai
python
import os
from openai import OpenAI
client = OpenAI(
apikey=os.environ.get(AISTUDIOAPIKEY),
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,思维链推理 |
| 代码生成 |
完整模型列表请查看: references/models.md
python
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)
python
messages = [
{role: system, content: 你是AI助手。}
]
python
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
python
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
)
支持函数调用的模型: ernie-5.0-thinking-preview, ernie-x1-turbo, deepseek-r1, deepseek-v3
python
response = client.chat.completions.create(
model=ernie-4.5-turbo-128k-preview,
messages=[{role: user, content: 列出三个水果}],
responseformat={type: jsonobject}
)
python
response = client.chat.completions.create(
model=deepseek-r1,
messages=[{role: user, content: 请解释相对论}]
)
python
response = client.chat.completions.create(
model=ernie-4.5-turbo-vl,
messages=[{
role: user,
content: [
{type: text, text: 描述这张图片},
{type: imageurl, imageurl: {url: https://example.com/image.jpg}}
]
}]
)
python
images = client.images.generate(
prompt=一只可爱的白猫,戴着红帽子,
model=Stable-Diffusion-XL,
response_format=url
)
print(images.data[0].url)
python
embeddings = client.embeddings.create(
model=embedding-v1,
input=[你好世界, 机器学习]
)
print(embeddings.data[0].embedding)
详细的API参数说明和更多功能,请查看:
| 错误码 | 说明 | 解决方案 |
|---|---|---|
| 401 | 认证失败 | 检查API Key是否正确 |
| 429 |
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 baidu-aistudio-llm-api-1776101344 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 baidu-aistudio-llm-api-1776101344 技能
skillhub install baidu-aistudio-llm-api-1776101344
文件大小: 10.02 KB | 发布时间: 2026-4-15 11:50