OpenAI official library usage tutorial
Our API is fully compatible with the OpenAI interface protocol and supports seamless integration with various applications that utilize the OpenAI interface.Note: All chat models (including non-OpenAI models) support the official OpenAI library. Please ensure that the request URL and format adhere to OpenAI's request method.Reference: Official development documentation.When making requests to the interface, replace https://api.openai.com with our API address (which can be found in the API website -> Console). Your KEY must correspond with the API website, so be careful not to mix up mixed sites with official transition sites. OpenAI official Python library#
Official project address
⚠️ Note: Please upgrade the openai library to version 1.25+ or the latest version, otherwise any call errors will not be supported.Installation#
DEMO:#
Note: base_url needs to include the /v1/ suffix.import os
import openai
openai.api_key = "你的sk"
openai.base_url = "https://Base_Url(网址域名地址)/v1/"
openai.default_headers = {"x-foo": "true"}
completion = openai.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "user",
"content": "Hello world!",
},
],
)
print(completion.choices[0].message.content)
#It usually outputs results.:Hello there! How can I assist you today ?`
Modified at 2025-08-12 03:52:15