How to hit the Baidu Qianfan (ERNIE) API

Baidu's Qianfan platform serves ERNIE and other models behind an OpenAI-compatible API — internationally at https://api.baiduqianfan.ai/v1, in China at https://qianfan.baidubce.com/v2. Check the model list in the console for ERNIE model ids.

Authentication

Create an API key in the Qianfan console (it looks like bce-v3/ALTAK-…) and send it as Authorization: Bearer <key>. In the examples it's written {{QIANFAN_API_KEY}}.

Full reference: https://intl.cloud.baidu.com/en/doc/qianfan/s/3m7of64lb-intl-en

Chat completion

Model from Baidu's own example.

curl -X POST https://api.baiduqianfan.ai/v1/chat/completions \
  -H "Authorization: Bearer {{QIANFAN_API_KEY}}" \
  -H "Content-Type: application/json" \
  -d '{"model": "deepseek-v3.1-250821", "messages": [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello"}]}'
Run in PostTaco