SDK-Referenz OpenAI SDK-Kompatibilität BazaarLink ist vollständig kompatibel mit den OpenAI Python- und Node.js-SDKs. Nur zwei Änderungen erforderlich:
Vorher (OpenAI direkt)
from openai import OpenAI
client = OpenAI(
api_key="sk-..."
)
response = client.chat.completions.create(
model="gpt-4o" ,
messages=[...]
)
⌄ Alle 10 Zeilen anzeigenNachher (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=[...]
)
⌄ Alle 11 Zeilen anzeigenDas war's!
Alle anderen Funktionen — Streaming, Tool Calling, Structured Output, Async — funktionieren genau gleich. Die einzige Änderung ist base_url, api_key und das Hinzufügen des Anbieter-Präfix zur Modell-ID.
Python Installation Synchron 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)
⌄ Alle 13 Zeilen anzeigenAsynchron 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())
⌄ Alle 16 Zeilen anzeigenStreaming mit 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())
⌄ Alle 12 Zeilen anzeigenTypeScript / Node.js Installation Grundlegende Nutzung 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 ?? "" ;
}
⌄ Alle 14 Zeilen anzeigenStreaming 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 ?? "" );
}
⌄ Alle 9 Zeilen anzeigenLangChain Verwenden Sie BazaarLink mit LangChain, indem Sie die OpenAI-kompatible Base-URL konfigurieren.
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)
⌄ Alle 10 Zeilen anzeigenLlamaIndex Verwenden Sie BazaarLink in LlamaIndex-RAG-Pipelines. LlamaIndex unterstützt jeden OpenAI-kompatiblen Endpunkt — ändern Sie einfach zwei Parameter.
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)
⌄ Alle 17 Zeilen anzeigenVercel AI SDK Integrieren Sie das Vercel AI SDK mit BazaarLink in Ihrer Next.js-App. Unterstützt Streaming, Tool Calling und 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);
⌄ Alle 14 Zeilen anzeigen