Menu

Integrate into OpenAI official SDK

Just change the key and base url to ours, and the rest of the usage remains the same as the official one.

 from openai import OpenAI

client = OpenAI(
#302.AI Backend-Use API-API Keys generated API KEY
    api_key="sk-xxx",
#302.AI的base-url
    base_url="https://api.302.ai/v1/chat/completions"
)

chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "hello",
        }
    ],
    model="gpt-4o-mini",
)

print(chat_completion)

(Note: Add /v1 to the end of the BASE_URL)

Previous
Integrate into LangChain
Next
Integrate into Cursor
Last modified: 2024-09-27