### Install OpenAI SDK Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/Wm95lyynv-intl-en Install the required OpenAI Python library. ```bash 1pip3 install-U openai ``` -------------------------------- ### Token Calculation Output Example Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/ymh4sv71t-intl-en Example output showing token IDs and the total count. ```text 1ids: [83649, 8842, 33912, 4339, 6977] 2token count: 5 ``` -------------------------------- ### cURL Request Example for PurchaseTeamSeat Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/Cmtaz189j A cURL command example to execute the PurchaseTeamSeat request. ```bash curl -X POST 'https://api.baiduqianfan.ai/v2/overseas/team/tokenplan?Action=PurchaseTeamSeat' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer ' \ -d '{ "seatPlan": "lite", "quantity": 1, "duration": 1, "durationUnit": "month", "autoRenew": false }' ``` -------------------------------- ### cURL Request for DescribeSupportModels Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/tmt6xp4tx Example command to query supported models using cURL. ```bash curl -X POST 'https://api.baiduqianfan.ai/v2/overseas/team/tokenplan?Action=DescribeSupportModels' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer ' \ -d '{}' ``` -------------------------------- ### Install PaddleFormers Dependencies Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/ymh4sv71t-intl-en Install required packages for ERNIE model token calculation tools. ```bash 1pip install -r requirements.txt ``` -------------------------------- ### Response Example for DescribeSupportModels Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/tmt6xp4tx A sample JSON response containing the list of supported model names. ```json { "requestId": "ca8ae258-3da6-4fd4-ba3c-a13e04d4f2cc", "result": { "items": [ "glm-5", "glm-5.1", "glm-5.2", "deepseek-v3.2", "deepseek-v4-flash-0731", "deepseek-v4-flash", "deepseek-v4-pro" ] } } ``` -------------------------------- ### RenewTeamSeat cURL Request Example Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/cmtaz1q5u A cURL command example to perform the renewal request. ```bash curl -X POST 'https://api.baiduqianfan.ai/v2/overseas/team/tokenplan?Action=RenewTeamSeat' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer ' \ -d '{ "resourceId": "tps-mTGl6tfp", "duration": 1, "durationUnit": "month" }' ``` -------------------------------- ### Create Member and Bind Seat cURL Example Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/Lmt6u8kfb A cURL command to execute the CreateMemberAndBindSeat request. ```bash curl -X POST 'https://api.baiduqianfan.ai/v2/overseas/team/tokenplan?Action=CreateMemberAndBindSeat' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer ' \ -d '{ "userName": "user01" }' ``` -------------------------------- ### SDK Response Content Example Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/6m8r1x5hz-intl-en The parsed JSON content returned by the SDK request. ```json { "question": "Which is the longest river in the world?", "answer": "The Nile River" } ``` -------------------------------- ### ChatFilePlus plugin usage example Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/km96ryv9w-intl-en Displays the usage object structure when the ChatFilePlus plugin is triggered. ```json 1 "usage": { 2 "prompt_tokens": 15918, 3 "completion_tokens": 109, 4 "total_tokens": 16027, 5 "prompt_tokens_details": { 6 "plugin_tokens": { 7 "ChatFilePlus": 15871 8 }, 9 "cache_tokens": xxx 10 "search_tokens":xxxx 11 } 12 } ``` -------------------------------- ### Describe Member API Key cURL Example Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/Smt6wvybq A cURL command example to perform the DescribeMemberApiKey request. ```bash curl -X POST 'https://api.baiduqianfan.ai/v2/overseas/team/tokenplan?Action=DescribeMemberApiKey' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer ' \ -d '{ "cloudId": "703b418a4fb3422f86b5b872c0a724b9" }' ``` -------------------------------- ### Cache tokens usage example Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/km96ryv9w-intl-en Displays the usage object structure when prompt caching is triggered. ```json 1 "usage": { 2 "prompt_tokens": 159, 3 "completion_tokens": 89, 4 "total_tokens": 248, 5 "prompt_tokens_details": { 6 "cached_tokens": 128 7 } 8 } ``` -------------------------------- ### Search tokens usage example Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/km96ryv9w-intl-en Displays the usage object structure when search functionality is triggered. ```json 1 "usage": { 2 "prompt_tokens": 4149, 3 "completion_tokens": 287, 4 "total_tokens": 4436, 5 "prompt_tokens_details": { 6 "search_tokens": 4146 7 } 8 } ``` -------------------------------- ### DescribeSeats Request Example Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/fmt6xifyu Use this cURL command to query seat information by sending a POST request to the DescribeSeats endpoint. ```bash curl -X POST 'https://api.baiduqianfan.ai/v2/overseas/team/tokenplan?Action=DescribeSeats' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer ' \ -d '{ "cloudIds": [], "pageNo": 1, "pageSize": 10 }' ``` -------------------------------- ### Define Model Input with Tools Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/ymh4sv71t-intl-en Example JSON structure for a model input containing user messages and tool definitions. ```json { "model": "qwen3-8b", "messages": [ { "role": "user", "content": "Check the current weather in Shanghai and Beijing" } ], "tools": [{ "type": "function", "function": { "name": "get_current_weather", "description": "Weather query tool", "parameters": { "properties": { "location": { "description": "Geographic location, accurate to the district/county level", "type": "string" }, "time": { "description": "Time, in YYYY-MM-DD format", "type": "string" } }, "type": "object" } } }], "stream": false, "enable_thinking":false, "tool_choice" : "auto", "tool_options" : {"thoughts_output" : true} } ``` -------------------------------- ### JSON Schema Response Example Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/6m8r1x5hz-intl-en Example of the structured JSON response returned by the API. ```json { "id": "as-xa6w2285g9", "object": "chat.completion", "created": 1751005990, "model": "deepseek-v3", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "{\n \"final_answer\": \"x = -15/4\",\n \"steps\": [\n {\n \"explanation\": \"To solve the equation 8x + 7 = -23, we first need to isolate the term with the variable x. We can do this by subtracting 7 from both sides of the equation.\",\n \"output\": \"8x + 7 - 7 = -23 - 7\"\n },\n {\n \"explanation\": \"After subtracting 7 from both sides, the equation simplifies to 8x = -30.\",\n \"output\": \"8x = -30\"\n },\n {\n \"explanation\": \"Next, we solve for x by dividing both sides of the equation by 8 to isolate x.\",\n \"output\": \"x = -30 / 8\"\n },\n {\n \"explanation\": \"The fraction -30/8 can be simplified by dividing both the numerator and the denominator by 2.\",\n \"output\": \"x = -15/4\"\n }\n ]\n}" }, "finish_reason": "stop", "flag": 0 } ], "usage": { "prompt_tokens": 302, "completion_tokens": 220, "total_tokens": 522, "prompt_tokens_details": { "cached_tokens": 5 } } } ``` -------------------------------- ### DescribeSeats Request Structure Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/fmt6xifyu Example of a POST request to the DescribeSeats endpoint, including the required Authorization header and JSON body. ```http POST /v2/overseas/team/tokenplan?Action=DescribeSeats HTTP/1.1 Host: api.baiduqianfan.ai Authorization: Bearer Content-Type: application/json { "cloudIds": [], "pageNo": 1, "pageSize": 10 } ``` -------------------------------- ### Tool Call JSON Structure Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/xm95lyys5-intl-en Example of a tool call response including reasoning and function arguments. ```json 12 "reasoning_content": "Okay, the user wants me to check the current weather in Shanghai and Beijing. But I need to first check the available tools. According to the provided tool list, there is currently only one tool called query_train_info, which is used to query train schedule information with parameters including date, departure, and destination.\n\nThe user's question is about weather, but the existing tools don't support weather queries. This means I need to call the correct tool to answer the question, but clearly the tools don't match. Therefore, according to the rules, I must use the given tools to respond, so I may need to inform the user that I cannot handle the weather request, or try to handle it with the existing tools.\n\nHowever, the user mentioned \"current\" weather, and the tool requires date, departure, and destination. Assuming the user might want to query today's train schedule, the departure could be Shanghai and destination Beijing, with today's date. Or the user might have confused train schedule queries with weather queries.\n\nAccording to the rules, I must call the given tool in any case, even if it's irrelevant. Therefore, I need to extract possible parameters. The user mentioned Shanghai and Beijing, which could be the departure and destination. The date needs to be the current date. Assuming today is October 5, 2023, but in actual applications, I may need to dynamically obtain the date. However, the user didn't provide a specific date, so I may need to prompt the user to provide additional information, or use a default value.\n\nBut according to the tool's parameter requirements, date, departure, and destination must be included. The user didn't provide a date, so I may need to fill it in. For example, assuming the user wants to query today's train from Shanghai to Beijing, or vice versa. Therefore, I may need to generate two calls, one from Shanghai to Beijing, another from Beijing to Shanghai, or ask for the date.\n\nBut according to the output format, I must call the tool, so I need to construct parameters. For example, set date to today's date, departure to Shanghai, destination to Beijing. But the user's question is about weather, so calling the train schedule query tool may not meet the needs, but according to the rules, I must call the tool, so I can only generate such a call, but the result may not be relevant.\n\nThis may mean there are limitations in the system, but as an assistant, I must follow the rules. Therefore, I need to construct a call, for example, with departure Shanghai, destination Beijing, date today, calling query_train_info. But the user actually needs weather information, so the correct approach would be to inform that it cannot be handled, but according to the given rules, I must call the tool, so I can only generate such a call, even if it's not relevant.\n\nHowever, this may not be the best approach. But according to the user's instructions, regardless of whether the user input is relevant, the tool must be called. Therefore, I need to generate corresponding JSON parameters, even if the parameters are incomplete. For example, the user didn't provide a date, but the tool requires it, so I may need to assume a date, such as today, or prompt the user to provide more information, but according to the rules, the tool must be called, so all required parameters must be included.\n\nSo, I need to construct the date parameter as today's date, such as \"2023-10-05\", departure as Shanghai, destination as Beijing. But the user's question is about weather, so calling the train schedule query tool may not provide useful information, but according to the rules, I must call it. Therefore, generate the corresponding tool call.\n\nIn summary, I must call query_train_info with parameters: date (assuming today), departure (Shanghai), destination (Beijing), even if the user's question is irrelevant. Therefore, output the corresponding JSON call.\",\n13 \"tool_calls\": [\n14 {\n15 \"id\": \"2ee8479cbd6c40cab0bf2ea45e3c53a0\",\n16 \"type\": \"function\",\n17 \"function\": {\n18 \"name\": \"query_train_info\",\n19 \"arguments\": \"{ \"date\": \"2023-10-05\", \"departure\": \"Shanghai\", \"destination\": \"Beijing\"}\"\n20 }\n21 }\n22 ]\n23 },\n24 \"finish_reason\": \"tool_calls\",\n25 \"flag\": 0\n26 }\n27 ],\n28 \"usage\": {\n29 \"prompt_tokens\": 475,\n30 \"completion_tokens\": 677,\n31 \"total_tokens\": 1152,\n32 \"prompt_tokens_details\": {\n33 \"cached_tokens\": 2\n34 },\n35 \"completion_tokens_details\": {\n36 \"reasoning_tokens\": 609\n37 }\n38 }\n39} ``` -------------------------------- ### PurchaseTeamSeat Response Example Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/Cmtaz189j A sample JSON response returned by the PurchaseTeamSeat API upon a successful request. ```json { "requestId": "3f0c1d8e-9b47-4f6a-8f1e-2c5d7a90b431", "result": { "orderId": "e4f9b2c1a7d84e5f", "seatPlan": "lite", "quantity": 1, "duration": 1, "durationUnit": "month" } } ``` -------------------------------- ### RenewTeamSeat Response Example Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/cmtaz1q5u A sample JSON response returned upon a successful renewal request. ```json { "requestId": "a71b5cd2-6e38-4c0b-9d52-71f4ab83c60d", "result": { "orderId": "b27d5ea9c1f34a08", "duration": 1, "durationUnit": "month" } } ``` -------------------------------- ### Reasoning tokens usage example Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/km96ryv9w-intl-en Displays the usage object structure when a deep thinking model returns reasoning tokens. ```json 1 "usage": { 2 "prompt_tokens": 2, 3 "completion_tokens": 274, 4 "total_tokens": 276, 5 "completion_tokens_details": { 6 "reasoning_tokens": 242 7 } 8 } ``` -------------------------------- ### DescribeSeats Response Example Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/fmt6xifyu The API returns a JSON object containing the request ID and a list of seat objects with their respective states and metadata. ```json { "requestId": "98186cde-f322-4022-be90-0d944555bcee", "result": { "total": 2, "items": [ { "seatId": "tpst-w25ysj7mghkt", "planType": "lite", "seatState": 1, "memberName": "fluxa_f1_e2e_user" }, { "seatId": "tpst-f77gwdgksmri", "planType": "lite", "seatState": 0, "memberName": "" } ] } } ``` -------------------------------- ### Initiate Chat Completion Request Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/3m7of64lb-intl-en Example of a POST request to the chat completions endpoint using an API Key for authentication. ```http 1POST /v1/chat/completions HTTP/1.1 2Host: api.baiduqianfan.ai 3Authorization: Bearer 4Content-Type: application/json 5 6{ 7 "model": "deepseek-v3.1-250821", 8 "messages": [ 9 { 10 "role": "system", 11 "content": "You are a helpful assistant." 12 }, 13 { 14 "role": "user", 15 "content": "Hello" 16 } 17 ] 18} ``` -------------------------------- ### Describe Team Seat List cURL Request Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/amtaz2wj2 Example cURL command to invoke the DescribeTeamSeatList API. ```bash curl -X POST 'https://api.baiduqianfan.ai/v2/overseas/team/tokenplan?Action=DescribeTeamSeatList' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer ' \ -d '{ "orderId": "4fc2b212faa64cdeb39c0c23f88a3f92" }' ``` -------------------------------- ### Specify Thinking Strategy Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/Wm95lyynv-intl-en Example of using the thinking_strategy parameter to control the model's reasoning process. ```Bash curl --location 'https://api.baiduqianfan.ai/v1/chat/completions' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer your-api-key' \ --data '{ "model": "qwen3-14b", "stream": false, "stream_options": { "include_usage": true, "chunk_include_usage": true }, "thinking_strategy": "chain_of_draft", "enable_thinking": true, "max_tokens": 8192, "messages": [ { "role": "user", "content": "which one is lareger? 10.11 or 10.9" } ] }' ``` -------------------------------- ### Describe Team Seat List Response Example Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/amtaz2wj2 A sample JSON response containing the request ID and the list of seat instance IDs. ```json { "requestId": "b686c35c-f872-4545-911c-e9486c067343", "result": { "total": 1, "seatIds": [ "tpst-bx2206c6ruth" ] } } ``` -------------------------------- ### Handle Multiple Tool Call Response Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/xm95lyys5-intl-en Example JSON response containing multiple tool call requests generated by the model. ```json { "id": "as-iyiscjp3qj", "object": "chat.completion", "created": 1746955406, "model": "deepseek-r1", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "", "reasoning_content": "Okay, the user asked me to check the weather in Shanghai and Beijing now. I need to use the weather query tool. First, I'll confirm the tool's parameter requirements - it needs geographic location and time. The user mentioned \"now\", so the time should be today's date. The geographic location should be precise to the district level, but the user only provided the city names, so I'll need to use the default administrative districts, such as Shanghai City and Beijing City. Then I'll generate two tool calls to handle Shanghai and Beijing separately. I need to check if the parameters are correct, ensuring the date format is YYYY-MM-DD, for example today's date 2023-10-10. Then I'll make two function calls according to the output format, passing location as Shanghai and Beijing respectively, both with today's time. Finally, I'll combine them into the correct response format.\n", "tool_calls": [ { "id": "5acc5ea7a2584225b2eee9cf45390ffa", "type": "function", "function": { "name": "get_current_weather", "arguments": "{\"location\": \"Shanghai\", \"time\": \"2023-10-10\"}" } }, { "id": "9a3208f72b124140b862adc6adb240bd", "type": "function", "function": { "name": "get_current_weather", "arguments": "{\"location\": \"Beijing\", \"time\": \"2023-10-10\"}" } } ] }, "finish_reason": "tool_calls", "flag": 0 } ], "usage": { "prompt_tokens": 370, "completion_tokens": 347, "total_tokens": 717, "completion_tokens_details": { "reasoning_tokens": 123 } } } ``` -------------------------------- ### Upgrade Team Seat Plan cURL Request Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/Pmtaz26vk Example cURL command to perform the seat plan upgrade operation. ```bash curl -X POST 'https://api.baiduqianfan.ai/v2/overseas/team/tokenplan?Action=UpgradeTeamSeatPlan' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer ' \ -d '{ "resourceId": "tps-mTGl6tfp", "seatId": "tpst-w25ysj7mghkt", "oldSeatPlan": "lite", "newSeatPlan": "pro" }' ``` -------------------------------- ### Upgrade Team Seat Plan Response Example Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/Pmtaz26vk A successful response returns the order ID, seat ID, and the updated seat plan details. ```json { "requestId": "5c8de41f-2a63-47b9-b0d1-9e6f3c72a845", "result": { "orderId": "d93f18ba62c74e15", "seatId": "tpst-w25ysj7mghkt", "seatPlan": "pro", "previousSeatPlan": "lite" } } ``` -------------------------------- ### Call Visual Understanding API with Base64 Encoding Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/fm8r1ndsm-intl-en Convert local images to Base64 strings for API input. This example uses the OpenAI-compatible Python client. ```python import base64 from openai import OpenAI client = OpenAI( api_key="your-api_key", base_url="https://api.baiduqianfan.ai/v1" ) # Function to encode the image def encode_image(image_path): with open(image_path, "rb") as image_file: return base64.b64encode(image_file.read()).decode("utf-8") # Path to your image image_path = "path_to_your_image.jpg" # Getting the Base64 string base64_image = encode_image(image_path) response = client.chat.completions.create( model="deepseek-vl2", messages=[ { "role": "user", "content": [ { "type": "text", "text": "What is in this image?", }, { "type": "image_url", "image_url": { "url": f"data:image/jpeg;base64,{base64_image}" }, }, ], } ], ) print(response.choices[0]) ``` -------------------------------- ### Bind Seat Request Example Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/Tmt6vcdx5 Use this cURL command to bind a member to a specific seat. Ensure the Authorization header contains a valid API Key. ```bash curl -X POST 'https://api.baiduqianfan.ai/v2/overseas/team/tokenplan?Action=BindSeat' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer ' \ -d '{ "memberSeatBindInfo": [ { "seatId": "tpst-w25ysj7mghkt", "cloudId": "a60ba3c706214bf4bbe95ad0dd9768e7" } ] }' ``` -------------------------------- ### Invoke Function Calling with Python SDK Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/xm95lyys5-intl-en Demonstrates configuring the OpenAI client to point to the Qianfan API and defining a tool schema for weather lookups. ```python 1from openai import OpenAI 2 3client = OpenAI( 4 api_key=api_key ## 5 base_url="https://api.baiduqianfan.ai/v1", ## 6) 7 8tools = [ 9 { 10 "type": "function", 11 "function": { 12 "name": "get_current_weather", 13 "description": "Get the current weather in a given location", 14 "parameters": { 15 "type": "object", 16 "properties": { 17 "location": { 18 "type": "string", 19 "description": "The city and state, e.g. San Francisco, CA", 20 }, 21 "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, 22 }, 23 "required": ["location"], 24 }, 25 } 26 } 27] 28messages = [{"role": "user", "content": "What's the weather like in Boston today?"}] 29completion = client.chat.completions.create( 30 model="deepseek-v3", 31 messages=messages, 32 tools=tools, 33 tool_choice="auto" 34) 35 36print(completion) ``` -------------------------------- ### Tool Call Response Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/xm95lyys5-intl-en Example JSON response structure returned by the API after a chat completion request. ```json { "id": "as-vzy3tpikdm", "object": "chat.completion", "created": 1755191184, "model": "deepseek-r1", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "" ``` -------------------------------- ### POST /v2/overseas/team/tokenplan?Action=DescribeSupportModels Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/tmt6xp4tx Queries the list of model names currently supported by TokenPlan. ```APIDOC ## POST /v2/overseas/team/tokenplan?Action=DescribeSupportModels ### Description Call this API to query the list of model names currently supported by TokenPlan. The returned values can be used directly as the `model` field in inference requests. ### Method POST ### Endpoint https://api.baiduqianfan.ai/v2/overseas/team/tokenplan?Action=DescribeSupportModels ### Authentication Requires API Key authentication via Bearer token in the Authorization header. ### Request Body - No parameters required. ### Request Example ```json {} ``` ### Response #### Success Response (200) - **requestId** (string) - The request ID in UUID format. - **result** (object) - The business data object. - **items** (array) - The list of supported model names. #### Response Example ```json { "requestId": "ca8ae258-3da6-4fd4-ba3c-a13e04d4f2cc", "result": { "items": [ "glm-5", "glm-5.1", "glm-5.2", "deepseek-v3.2", "deepseek-v4-flash-0731", "deepseek-v4-flash", "deepseek-v4-pro" ] } } ``` ``` -------------------------------- ### Multimodal Chat Completion Response Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/fm8r1ndsm-intl-en Example JSON response containing the detailed analysis of the provided images. ```json { "id": "as-14hvmej1ts", "object": "chat.completion", "created": 1742198435, "model": "ernie-4.5-8k-preview", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Of course, let's analyze the differences between these two images in more detail: 1. **Subject and Content**: - **First image**: This is a landscape photograph showing a natural environment. The photo features a wooden boardwalk passing through a green meadow, with a blue sky and some trees in the background. The overall atmosphere is serene, with vivid colors, giving a sense of openness and relaxation. - **Second image**: This is a close-up photograph showing a hand interacting with a decorative object. The object looks like a turtle with intricate patterns and textures, surrounded by some green plant decorations. The overall atmosphere is more refined and artisanal, with rich colors and exquisite details. 2. **Perspective and Composition**: - **First image**: Uses a wide-angle perspective, capturing a large area of natural landscape. The boardwalk extends from the foreground to the background, guiding the viewer's line of sight deep into the image. The ratio of sky to ground is balanced, giving a sense of space and depth. - **Second image**: Uses a close-up perspective, focusing on the details of the hand and the turtle. The textures of the fingers and turtle are clearly visible, with a blurred background highlighting the subject. The composition is compact with rich details, drawing the viewer's attention to the fine craftsmanship of the handicraft. 3. **Color and Light**: - **First image**: Colors are mainly green and blue, with natural lighting, possibly shot during the day. Sunlight shines on the meadow and boardwalk, creating contrast between light and shadow, enhancing the three-dimensional sense of the image. - **Second image**: Colors are more diverse, with the turtle's green, blue, and yellow colors being vivid, with soft lighting, possibly shot indoors. Light focuses on the hand and turtle, highlighting details and texture. 4. **Emotion and Atmosphere**: - **First image**: Conveys emotions of serenity, nature, and relaxation, suitable for showcasing natural scenery or outdoor activity scenes. - **Second image**: Conveys emotions of refinement, craftsmanship, and focus, suitable for showcasing handicrafts or creative works. Overall, these two images have significant differences in subject, perspective, color, and emotion, respectively showcasing the beauty of natural landscapes and handicrafts." }, "finish_reason": "stop", "flag": 0 } ], "usage": { "prompt_tokens": 3130, "completion_tokens": 394, "total_tokens": 3524 } } ``` -------------------------------- ### POST /v2/overseas/team/tokenplan?Action=DescribeSeats Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/fmt6xifyu Retrieves a paginated list of seats for token plans. ```APIDOC ## POST /v2/overseas/team/tokenplan?Action=DescribeSeats ### Description Retrieves a list of seats associated with token plans, supporting pagination and filtering by cloud IDs. ### Method POST ### Endpoint https://api.baiduqianfan.ai/v2/overseas/team/tokenplan?Action=DescribeSeats ### Parameters #### Request Body - **cloudIds** (array) - Optional - List of cloud IDs to filter by. - **pageNo** (integer) - Optional - The page number to retrieve. - **pageSize** (integer) - Optional - The number of items per page. ### Request Example { "cloudIds": [], "pageNo": 1, "pageSize": 10 } ### Response #### Success Response (200) - **requestId** (string) - The request ID in UUID format. - **result** (object) - The business data object. - **total** (integer) - The total number of items. - **items** (array) - The seat list. - **seatId** (string) - The seat ID. - **planType** (string) - The plan type: lite, pro, max, ultra. - **seatState** (integer) - The seat state (0: Unallocated, 1: In use, 2: Expired, 3: Deactivated). - **tpResourceId** (string) - The ID of the plan resource. - **cloudId** (string) - The cloudId of the bound member. - **memberName** (string) - The login name of the bound member. - **bindTime** (string) - The binding time. - **subscribeStart** (string) - The subscription start time. - **subscribeEnd** (string) - The subscription end time. - **seatCreditsTotal** (string) - Total credits of the seat. - **seatCreditsUsed** (string) - Used credits of the seat. ### Response Example { "requestId": "98186cde-f322-4022-be90-0d944555bcee", "result": { "total": 2, "items": [ { "seatId": "tpst-w25ysj7mghkt", "planType": "lite", "seatState": 1, "memberName": "fluxa_f1_e2e_user" }, { "seatId": "tpst-f77gwdgksmri", "planType": "lite", "seatState": 0, "memberName": "" } ] } } ``` -------------------------------- ### JSON Object Response Example Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/6m8r1x5hz-intl-en The expected JSON structure returned by the API when using json_object mode. ```json { "id": "as-edpps57f2v", "object": "chat.completion", "created": 1751006944, "model": "deepseek-v3", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "{\n \"question\": \"Which is the longest river in the world?\",\n \"answer\": \"The Nile River\"\n}" }, "finish_reason": "stop", "flag": 0 } ], "usage": { "prompt_tokens": 111, "completion_tokens": 27, "total_tokens": 138, "prompt_tokens_details": { "cached_tokens": 2 } } } ``` -------------------------------- ### POST /v2/overseas/team/tokenplan?Action=CreateMemberAndBindSeat Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/Lmt6u8kfb Creates a sub-user (member) under the current master account and binds it to a specified seat. ```APIDOC ## POST /v2/overseas/team/tokenplan?Action=CreateMemberAndBindSeat ### Description Call this API to create a sub-user (member) under the current master account and bind it to a specified seat. The member's apiKey is also returned upon successful creation. ### Method POST ### Endpoint https://api.baiduqianfan.ai/v2/overseas/team/tokenplan?Action=CreateMemberAndBindSeat ### Parameters #### Query Parameters - **Action** (string) - Required - The action name: CreateMemberAndBindSeat #### Request Body - **userName** (string) - Required - The login name of the team member. - **seatId** (string) - Optional - The seat ID. If not provided, the system automatically selects an available seat. ### Request Example { "userName": "user01" } ``` -------------------------------- ### Unbind Seat cURL Request Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/Fmt6wni21 Example of how to invoke the UnbindSeat API using the cURL command-line tool. ```bash curl -X POST 'https://api.baiduqianfan.ai/v2/overseas/team/tokenplan?Action=UnbindSeat' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer ' \ -d '{ "unbindSeatMemberInfo": [ { "seatId": "tpst-w25ysj7mghkt" } ] }' ``` -------------------------------- ### Configure OpenAI SDK for Qianfan Structured Output Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/6m8r1x5hz-intl-en Initializes the OpenAI client with the Qianfan base URL and uses Pydantic models to enforce a structured response format. ```python 1from openai import OpenAI 2from pydantic import BaseModel 3 4client = OpenAI( 5 api_key="your-api-key", 6 base_url="https://api.baiduqianfan.ai/v1" 7) 8 9class Step(BaseModel): 10 explanation: str 11 output: str 12 13class MathReasoning(BaseModel): 14 steps: list[Step] 15 final_answer: str 16 17completion = client.chat.completions.parse( 18 model="deepseek-v3", 19 messages=[ 20 {"role": "system", "content": "You are a helpful math tutor. Guide the user through the solution step by step."}, 21 {"role": "user", "content": "how can I solve 8x + 7 = -23"} 22 ], 23 response_format=MathReasoning, 24) 25 26resp = completion.choices[0].message.parsed 27# Print JSON format result 28print(resp.model_dump_json(indent=2)) ``` -------------------------------- ### Generate text via Python SDK Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/Mm8r1mejk-intl-en Initialize the OpenAI-compatible client with the Qianfan base URL and API key to perform chat completions. ```python from openai import OpenAI client = OpenAI( api_key="bce-v3/ALTAK-KZke********/f1d6ee*************", # Qianfan bearer token base_url="https://api.baiduqianfan.ai/v1", # Qianfan domain ) completion = client.chat.completions.create( model="deepseek-v3.1-250821", # For preset services, refer to the model list; for custom services, enter the API address messages=[{'role': 'system', 'content': 'You are a helpful assistant.'}, {'role': 'user', 'content': 'Hello!'}] ) print(completion.choices[0].message) ``` -------------------------------- ### Specify Chain-of-Thought Length Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/Wm95lyynv-intl-en Example of using the thinking_budget parameter to limit the number of tokens generated during the thinking process. ```Bash curl --location 'https://api.baiduqianfan.ai/v1/chat/completions' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer your-api-key' \ --data '{ "model": "qwen3-14b", "stream": true, "stream_options": { "include_usage": true, "chunk_include_usage": true }, "enable_thinking": true, "thinking_budget": 100, "messages": [ { "role": "user", "content": "Recite 'Peacock Flies Southeast'" } ] }' ``` -------------------------------- ### List Team Members Response Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/Mmt6v11t0 Example JSON response containing the list of team members and their associated metadata. ```json { "requestId": "73af74df-dd3d-44d5-a09f-423623542b8d", "result": { "total": 4, "items": [ { "memberName": "fluxa_f1_e2e_user", "cloudId": "a60ba3c706214bf4bbe95ad0dd9768e7", "apiKey": "bce-v3/ALTAKSP-******", "dailyCreditLimit": "-1", "seatInfo": { "seatId": "tpst-w25ysj7mghkt", "planType": "lite" } }, { "memberName": "fluxa_f3_02_test", "cloudId": "a210569933f24e44b7d4af0755670d57", "apiKey": "", "dailyCreditLimit": "-1", "seatInfo": { "seatId": "", "planType": "" } }, { "memberName": "fluxa_qa_test02", "cloudId": "a54442376c4a4be791b6ccd962105bc8", "apiKey": "", "dailyCreditLimit": "-1", "seatInfo": { "seatId": "tpst-dc2009k8u4xa", "planType": "lite" } }, { "memberName": "fluxa_qa_test01", "cloudId": "b486a17d5d4b499d9c09237bfbff2b74", "apiKey": "", "dailyCreditLimit": "-1", "seatInfo": { "seatId": "", "planType": "" } } ] } } ``` -------------------------------- ### API Response Example Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/Fmt6wni21 Represents a successful API response containing a request ID and an empty result object. ```json { "requestId": "ed9a1ee2-a2fb-4c5a-a16b-e0bf66666271", "result": {} } ``` -------------------------------- ### Call Deep Thinking Model via API Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/Wm95lyynv-intl-en Basic example of sending a request to the deep thinking model endpoint. ```Bash curl --location 'https://api.baiduqianfan.ai/v1/chat/completions' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer bce-v3/ALTAK-*********/614fb**********' \ --data '{ "model": "deepseek-r1", "messages": [ { "role": "user", "content": "9.11 and 9.8, which is greater?" } ] }' ``` -------------------------------- ### POST /v1/chat/completions (Image Token) Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/fm8r1ndsm-intl-en Demonstrates how to use the placeholder to specify the position of images within a text prompt for supported vision models. ```APIDOC ## POST /v1/chat/completions ### Description Uses as a placeholder to mark the position of images within the text content. The number of image_url entries must match the number of placeholders. ### Request Example { "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Image 2: , Image 1: , please introduce image 1 and image 2" }, { "type": "image_url", "image_url": { "url": "https://testimage1*****.jpg" } }, { "type": "image_url", "image_url": { "url": "https://testimage2*****.jpg" } } ] } ], "stream": false, "model": "llama-4-maverick-17b-128e-instruct" } ``` -------------------------------- ### POST /v2/overseas/team/tokenplan?Action=BindSeat Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/Tmt6vcdx5 Call this API to bind seats to specified members in batches. ```APIDOC ## POST /v2/overseas/team/tokenplan?Action=BindSeat ### Description Call this API to bind seats to specified members in batches. ### Method POST ### Endpoint https://api.baiduqianfan.ai/v2/overseas/team/tokenplan?Action=BindSeat ### Parameters #### Request Body - **memberSeatBindInfo** (array) - Required - The list of seat-member binding pairs. - **seatId** (string) - Required - The seat ID. - **cloudId** (string) - Required - The cloudId of the member's sub-account to bind. ### Request Example { "memberSeatBindInfo": [ { "seatId": "tpst-w25ysj7mghkt", "cloudId": "a60ba3c706214bf4bbe95ad0dd9768e7" } ] } ``` -------------------------------- ### Calculate Image and Video Token Counts Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/ymh4sv71t-intl-en Calculate token counts for image or video files using multimodal.py. ```bash 1python multimodal.py --path /path/to/image.jpg ``` ```bash 1python multimodal.py --path /path/to/video.mp4 --video 1 ``` -------------------------------- ### POST /v2/overseas/team/tokenplan?Action=DescribeSeats Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/fmt6xifyu Call this API to query the seat list under the master account. Filtering by sub-user, plan resource, plan type, and seat state is supported, as well as pagination. ```APIDOC ## POST /v2/overseas/team/tokenplan?Action=DescribeSeats ### Description Call this API to query the seat list under the master account. Filtering by sub-user, plan resource, plan type, and seat state is supported, as well as pagination. ### Method POST ### Endpoint https://api.baiduqianfan.ai/v2/overseas/team/tokenplan?Action=DescribeSeats ### Parameters #### Request Body - **cloudIds** (array) - Optional - Filters by sub-user cloudId. - **tpResourceIds** (array) - Optional - Filters by plan resource ID (prefixed with tps-). - **planType** (array) - Optional - Filters by plan type (lite, pro, max, ultra). - **seatState** (array) - Optional - Filters by seat state (0: Unallocated, 1: In use, 2: Expired, 3: Deactivated). - **pageNo** (integer) - Optional - The page number, starting from 1. - **pageSize** (integer) - Optional - The number of items per page. ### Request Example { "cloudIds": [], "pageNo": 1, "pageSize": 10 } ``` -------------------------------- ### List Members Request Structure Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/Mmt6v11t0 Example of a POST request to the ListMembers endpoint including authentication headers and body parameters. ```http POST /v2/overseas/team/tokenplan?Action=ListMembers HTTP/1.1 Host: api.baiduqianfan.ai Authorization: Bearer Content-Type: application/json { "keyword": "", "pageNo": 1, "pageSize": 10 } ``` -------------------------------- ### Bind Seat Response Example Source: https://intl.cloud.baidu.com/en/doc/qianfan/s/Tmt6vcdx5 The API returns a JSON object containing a requestId and an empty result object upon successful binding. ```json { "requestId": "e424ae2b-ff67-4740-98ce-7d096a797809", "result": {} } ```