Skip to content

API Integration Example Code

Method 1: Direct OpenAI Configuration

import openai

# Set API base URL and key
openai.api_base = "https://www.kkiai.com/v1"
openai.api_key = "sk-xxxxxxxxx"

Method 2: Environment Variable Configuration

If Method 1 does not work, you can try this method

You need to set the following environment variables:

OPENAI_API_BASE=https://www.kkiai.com/v1
OPENAI_API_KEY=sk-xxxxx

Note: If changes to environment variables do not take effect, please restart your system

Method 3: Using OpenAI Client

from openai import OpenAI

# Initialize client
client = OpenAI(
    base_url="https://www.kkiai.com/v1",
    api_key='Your API KEY',
    timeout=120
)

# Create chat completion
response = client.chat.completions.create(
  model="gpt-4o",
  messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Who won the world series in 2020?"},
    {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
    {"role": "user", "content": "Where was it played?"}
  ]
)
print(response)

# response format

response = client.responses.create(
    model="gpt-5",
    input="Write a one-sentence bedtime story about a unicorn."
)

print(response.output_text)