Skip to main content

Python (OpenAI SDK & Frameworks)

Official SDK

pip install openai
from openai import OpenAI

client = OpenAI(
    base_url="https://api.openference.com/v1",
    api_key="sk-token-YOUR_KEY_HERE"
)

response = client.chat.completions.create(
    model="your-model-name",
    messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
Streaming, tools, embeddings, and vision all work the same as with OpenAI directly.

LangChain (example)

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    base_url="https://api.openference.com/v1",
    api_key="sk-token-YOUR_KEY_HERE",
    model="your-model-name",
)
print(llm.invoke("Say hi in French").content)

LlamaIndex, Haystack, etc.

Any framework that accepts an OpenAI-compatible base_url + api_key will work. Just point them at https://api.openference.com/v1.