Python OpenAI SDK

Use the official Python SDK with a server-side environment variable. Keep the key outside the repository and do not expose it to browsers.

Install the SDK

pip install openai

Set an environment variable

export ONEPK_API_KEY="replace-with-your-key"

Create a chat completion

from openai import OpenAI
import os

client = OpenAI(
    api_key=os.environ["ONEPK_API_KEY"],
    base_url="https://1pkapi.com/v1",
)

response = client.chat.completions.create(
    model="your-model-id",
    messages=[{"role": "user", "content": "Summarize this in one sentence."}],
)

print(response.choices[0].message.content)

Next

Use the model list to choose an applicable model ID. After the basic request succeeds, see streaming output for incremental responses.