OpenAI
Replace https://api.openai.com/
with https://llmfoundry.straive.com/openai/
.
All OpenAI models and APIs are supported.
Curl
curl -X POST https://llmfoundry.straive.com/openai/v1/chat/completions \
-H "Authorization: Bearer $LLMFOUNDRY_TOKEN:my-test-project" \
-H "Content-Type: application/json" \
-d '{"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "What is 2 + 2"}]}'
curl -X POST https://llmfoundry.straive.com/openai/v1/audio/speech \
-H "Authorization: Bearer $LLMFOUNDRY_TOKEN:my-test-project" \
-H "Content-Type: application/json" \
-d '{"model": "tts-1", "input": "Hello, world", "voice": "echo", "response_format": "mp3"}' > hello-world.mp3
Python requests
import os
import requests # Or replace requests with httpx
response = requests.post(
"https://llmfoundry.straive.com/openai/v1/chat/completions",
headers={"Authorization": f"Bearer {os.environ['LLMFOUNDRY_TOKEN']}:my-test-project"},
json={"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "What is 2 + 2"}]}
)
print(response.json())
JavaScript
const token = process.env.LLMFOUNDRY_TOKEN;
const response = await fetch("https://llmfoundry.straive.com/openai/v1/chat/completions", {
method: "POST",
headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}:my-test-project` },
// If the user is already logged into LLM Foundry, use `credentials: "include"` to send **THEIR** API token instead of the `Authorization` header.
credentials: "include",
body: JSON.stringify({
model: "gpt-4o-mini",
messages: [{ role: "user", content: "What is 2 + 2" }],
}),
});
console.log(await response.json());
Python OpenAI
import os
from openai import OpenAI
client = OpenAI(
api_key=f'{os.environ.get("LLMFOUNDRY_TOKEN")}:my-test-project',
base_url="https://llmfoundry.straive.com/openai/v1/",
)
# Rest of your code is the same
chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": "What is 2 + 2?"}],
model="gpt-4o-mini",
)
print(chat_completion.json())
LangChain
import os
from langchain_openai import ChatOpenAI
# Chat
chat_model = ChatOpenAI(
openai_api_base="https://llmfoundry.straive.com/openai/v1/",
openai_api_key=f'{os.environ["LLMFOUNDRY_TOKEN"]}:my-test-project',
model="gpt-4o-mini",
)
print(chat_model.invoke("What is 2 + 2?").content)
# Embeddings
from langchain_openai import OpenAIEmbeddings
embeddings_model = OpenAIEmbeddings(
openai_api_base="https://llmfoundry.straive.com/openai/v1/",
openai_api_key=f'{os.environ["LLMFOUNDRY_TOKEN"]}:my-test-project',
model="text-embedding-3-small",
)
embeddings = embeddings_model.embed_documents(["Alpha", "Beta", "Gamma"])
print(len(embeddings), len(embeddings[0]))