For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Copy to LLMGithubGo to App
DocumentationIntegrationsBuilding Self-Improving AgentsSelf-hosting OpikSDK & API reference
DocumentationIntegrationsBuilding Self-Improving AgentsSelf-hosting OpikSDK & API reference
    • Overview
  • TypeScript
    • Opik TypeScript SDK
  • Python
      • Anthropic
      • Bedrock
      • BytePlus
      • Cohere
      • DeepSeek
      • Fireworks AI
      • Gemini
      • Groq
      • Mistral AI
      • Novita AI
      • Ollama
      • OpenAI
      • Qianfan
      • Predibase
      • Together AI
      • WatsonX
      • xAI Grok
    • Opik Python SDK
    • OpenTelemetry Python SDK
  • Java
    • Spring AI
    • Quarkus LangChain4j
  • .NET
  • Ruby
    • OpenTelemetry Ruby SDK
  • No-Code
    • Cursor
    • Dify
    • Flowise
    • Langflow
    • n8n
    • OpenClaw
    • OpenAI Codex
    • OpenWebUI
    • Prompt Flow
  • Multi-Language
    • OpenTelemetry
LogoLogo
Copy to LLMGithubGo to App
On this page
  • Getting started
  • Tracking Qianfan API calls
  • Advanced Usage
  • Using with @track decorator
  • Troubleshooting
  • Common Issues
  • Getting Help
  • Next Steps
PythonModel Providers

Observability for Qianfan with Opik

Was this page helpful?
Previous

Observability for Predibase with Opik

Next
Built with

Baidu Qianfan provides OpenAI-compatible API endpoints for hosted model access. This guide shows how to use the OpenAI SDK with Opik to trace and evaluate Qianfan calls.

Getting started

First, ensure you have both opik and openai packages installed:

$pip install opik openai

You will need a Qianfan API key and an OpenAI-compatible base URL. The Qianfan OpenAI-compatible base URL is:

https://api.baiduqianfan.ai/v1

Refer to the Qianfan documentation for the latest setup steps and model list.

Tracking Qianfan API calls

1from opik.integrations.openai import track_openai
2from openai import OpenAI
3
4# Initialize the OpenAI client with your Qianfan base URL
5client = OpenAI(
6 base_url="https://api.baiduqianfan.ai/v1",
7 api_key="bce-v3/ALTAK-XXXXXXXX/XXXXXXXXXXXXXXXX", # Qianfan bearer token
8 default_headers={"appid": "app-xxxxxx"} # Optional Qianfan appid
9)
10client = track_openai(client)
11
12response = client.chat.completions.create(
13 model="ernie-4.0-turbo-8k", # Use a model name from Qianfan
14 messages=[
15 {"role": "user", "content": "Hello, world!"}
16 ],
17 temperature=0.7,
18 max_tokens=100
19)
20
21print(response.choices[0].message.content)

Advanced Usage

Using with @track decorator

You can combine the tracked client with Opik’s @track decorator for end-to-end tracing:

1from opik import track
2from opik.integrations.openai import track_openai
3from openai import OpenAI
4
5client = OpenAI(
6 base_url="https://api.baiduqianfan.ai/v1",
7 api_key="bce-v3/ALTAK-XXXXXXXX/XXXXXXXXXXXXXXXX", # Qianfan bearer token
8 default_headers={"appid": "app-xxxxxx"} # Optional Qianfan appid
9)
10client = track_openai(client)
11
12@track
13def summarize_report(text: str) -> str:
14 response = client.chat.completions.create(
15 model="ernie-4.0-turbo-8k",
16 messages=[
17 {"role": "user", "content": text}
18 ]
19 )
20
21 return response.choices[0].message.content
22
23summary = summarize_report("Summarize this report in 3 bullets.")
24print(summary)

Troubleshooting

Common Issues

  1. Authentication Errors: Confirm your API key is valid and has access to Qianfan
  2. Model Not Found: Verify the model name matches one available in Qianfan
  3. Base URL Issues: Ensure you are using the OpenAI-compatible endpoint from Qianfan

Getting Help

  • Review the Qianfan documentation
  • Check Opik tracing docs for setup details: /tracing/advanced/sdk_configuration

Next Steps

Once you have Qianfan integrated with Opik, you can:

  • Evaluate your LLM applications
  • Create datasets
  • Collect feedback
  • Monitor traces

For more information about OpenAI-compatible APIs, see the OpenAI integration guide.