SDK Reference OpenAI SDK Compatibility BazaarLink is fully compatible with the OpenAI Python and Node.js SDKs. Only two changes needed:
Before (OpenAI direct)
from openai import OpenAI
client = OpenAI(
api_key="sk-..."
)
response = client.chat.completions.create(
model="gpt-4o" ,
messages=[...]
)
⌄ See all 10 linesAfter (BazaarLink)
from openai import OpenAI
client = OpenAI(
base_url="https://api.bazaarlink.ai/v1" ,
api_key="sk-bl-YOUR_API_KEY"
)
response = client.chat.completions.create(
model="openai/gpt-4o" ,
messages=[...]
)
⌄ See all 11 linesThat's it!
All other features — streaming, tool calling, structured output, async — work exactly the same. The only change is base_url, api_key, and adding the provider prefix to model IDs.
Python Installation Synchronous from openai import OpenAI
client = OpenAI(
base_url="https://api.bazaarlink.ai/v1" ,
api_key="sk-bl-YOUR_API_KEY" ,
)
response = client.chat.completions.create(
model="openai/gpt-4o" ,
messages=[{"role" : "user" , "content" : "Hello!" }],
)
print (response.choices[0 ].message.content)
⌄ See all 13 linesAsync import asyncio
from openai import AsyncOpenAI
client = AsyncOpenAI(
base_url="https://api.bazaarlink.ai/v1" ,
api_key="sk-bl-YOUR_API_KEY" ,
)
async def main ():
response = await client.chat.completions.create(
model="anthropic/claude-sonnet-4.6" ,
messages=[{"role" : "user" , "content" : "Hello async world!" }],
)
print (response.choices[0 ].message.content)
asyncio.run(main())
⌄ See all 16 linesStreaming with async async def stream_chat ():
stream = await client.chat.completions.create(
model="deepseek/deepseek-chat" ,
messages=[{"role" : "user" , "content" : "Tell me a story" }],
stream=True ,
)
async for chunk in stream:
content = chunk.choices[0 ].delta.content
if content:
print (content, end="" , flush=True )
asyncio.run(stream_chat())
⌄ See all 12 linesTypeScript / Node.js Installation Basic Usage import OpenAI from "openai" ;
const client = new OpenAI ({
baseURL : "https://api.bazaarlink.ai/v1" ,
apiKey : process.env .BAZAARLINK_API_KEY ,
});
async function chat (message : string ): Promise <string > {
const response = await client.chat .completions .create ({
model : "openai/gpt-4o" ,
messages : [{ role : "user" , content : message }],
});
return response.choices [0 ].message .content ?? "" ;
}
⌄ See all 14 linesStreaming const stream = await client.chat .completions .create ({
model : "openai/gpt-4o" ,
messages : [{ role : "user" , content : "Tell me a story" }],
stream : true ,
});
for await (const chunk of stream) {
process.stdout .write (chunk.choices [0 ]?.delta ?.content ?? "" );
}
⌄ See all 9 linesLangChain Use BazaarLink with LangChain by configuring the OpenAI-compatible base URL.
Python JavaScript
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
base_url="https://api.bazaarlink.ai/v1" ,
api_key="sk-bl-YOUR_API_KEY" ,
model="anthropic/claude-sonnet-4.6" ,
)
response = llm.invoke("Explain BazaarLink in one sentence." )
print (response.content)
⌄ See all 10 linesLlamaIndex Use BazaarLink in LlamaIndex RAG pipelines. LlamaIndex supports any OpenAI-compatible endpoint — just change two parameters.
Python TypeScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from llama_index.llms.openai import OpenAI
from llama_index.core import Settings
Settings.llm = OpenAI(
model="openai/gpt-4o" ,
api_base="https://api.bazaarlink.ai/v1" ,
api_key="sk-bl-YOUR_API_KEY" ,
)
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
documents = SimpleDirectoryReader("./docs" ).load_data()
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()
response = query_engine.query("What is this documentation about?" )
print (response)
⌄ See all 17 linesVercel AI SDK Integrate the Vercel AI SDK with BazaarLink in your Next.js app. Supports streaming, tool calling, and structured output.
Installation npm install ai @ai-sdk/openaigenerateText streamText Next.js Route
import { createOpenAI } from "@ai-sdk/openai" ;
import { generateText } from "ai" ;
const bazaarlink = createOpenAI ({
baseURL : "https://api.bazaarlink.ai/v1" ,
apiKey : "sk-bl-YOUR_API_KEY" ,
});
const { text } = await generateText ({
model : bazaarlink ("openai/gpt-4o" ),
prompt : "Write a haiku about programming" ,
});
console .log (text);
⌄ See all 14 lines