Baiyun Super Intelligence BAIYUN.SI
API integration tutorial

Baiyun API tutorial: Python, Node.js, and LangChain

Free to read

Server-side environment variables, Responses/Chat SDK minimum examples and retrys. Includes complete inspection steps, practical verification, and error handling.

Python, Node.js, and LangChain

The server stores the key

The key passes through process environment variables BAIYUN_API_KEY Read it. Browser web pages and mobile apps cannot have built-in shared keys; You need to have your own backend authentication and quota to send the request on your behalf. Before deployment, check whether the logs print request headers or environment variables.

Python

python
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["BAIYUN_API_KEY"],
                base_url="https://api.baiyun.si/v1",
                timeout=120.0, max_retries=0)
response = client.responses.create(model="gpt-6-luna",
                                   input="用一句话说明 Token 是什么。")
print(response.output_text)

output_text It is the convenience provided by the SDK; When parsing REST JSON directly, it should be traversed output Text field in the message item. Dependencies should be installed in an isolated environment and the project lock files retained; Don't upgrade the entire production project just for testing.

Node.js

javascript
import OpenAI from 'openai';
const client = new OpenAI({
  apiKey: process.env.BAIYUN_API_KEY,
  baseURL: 'https://api.baiyun.si/v1',
  maxRetries: 0,
  timeout: 120000,
});
const stream = await client.chat.completions.create({
  model: 'gpt-6-luna', stream: true,
  messages: [{role: 'user', content: '你好'}],
});
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
}

LangChain

Use a model adapter that supports OpenAI-compatible addresses, and set the API Key, Base URL, and model in its current version. First call the plain text, then add links, retrieval, or tools; Any additional parameters automatically added by the framework must still comply with the site's open scope; do not treat the framework name as a guarantee of compatibility.

Mistakes and retrys

First, distinguish between HTTP state, SDK parsing errors, and business return errors. Generation interrupts may already consume money; do not automatically retry infinitely; 429 Retreat as prompted, 401 Repair credentials, 400 Repair parameters. When connection timeouts, check the status page and network before deciding whether to retry.

Official Python SDK project · Official Node SDK project · Official LangChain documentation

Checklist before practical use

  1. Prepare your own account and access keys, and do not use others' shared credentials.
  2. Records client versions, systems, and models to be used for easy reproduction during troubleshooting.
  3. Save the original configuration or screenshot, hide keys, verification codes, and private content.
  4. Confirm that testing may consume a small amount of DK, starting with a single sentence and a single request.
  5. Review the current model plaza and status page before deciding whether to enable more features.

Detailed troubleshooting: Separate request issues from code issues

First, run the minimum curl with the same key and model, then compare the SDK's actual address, request protocol, and parameters. If curl succeeds but the SDK fails, troubleshoot the proxy environment, SDK auto-retry, timeout, and extra fields. Do not print Authorization in error logs; Keys during deployment cannot be written to frontend build variables.

How to confirm that this section has been learned

Don't just check the "Configuration saved successfully" prompt. You should be able to clearly state the current Base URL, key usage, chosen model, and request protocol, and be able to verify your operation results on the corresponding console. The client-side tutorial uses a single actual plain text response and corresponding logs as the initial completion standard; Account tutorials are based on comprehensive security information; The billing tutorial uses the correspondence between principal, channel fees, and DK as the standard.

If an error occurs, record the occurrence time, HTTP status, content of the anonymized error, and the actual expected result. Do not screenshot the entire page key, and do not give the password or verification code to others. For 401, authentication should be resolved first; for 400, parameters should be resolved first; for 429, intensive retries should be stopped; for 404, request paths and upstream verification should be verified; recharging cannot resolve all errors.

A small task suitable for practice

Complete the minimum steps in this section in your own testing environment, recording in text "how you originally set it, which item you modified, and what results you saw." Do not treat production data, real payments, or irrecoverable commands as exercises. If you encounter features beyond what this section offers, first check the corresponding protocol tutorial before considering adding features; Changing only one configuration at a time makes it easy to judge which step leads to errors.

The next step is the boundary of the version

Return to the full learning map · Streamlined API site configuration · Real-time status of this site。

The tutorial was compiled on October 9, 2026. The specific interface and capabilities may vary depending on the client and upstream versions; The configuration guidelines do not mean that all client versions have passed the test. For balance payments, QQ / Alipay login, and open channels, please refer to the actual page page; Compression interfaces: Previously, upstream 404 and raw image channels were not available, so don't assume configuration files can be automatically removed.

Once you've learned it, give it a try.

Use SIN1's 100 questions to check your foundation.

Take the test

Contact Baiyun SI Community

Contact via email.

For inquiries, needs exchange, or cooperation discussions, please send an email.