Connect Your Apps to Your Gateway
Your gateway address is shown on the gateway page, for example https://u3447abc.llm.cdnshark.com. Use that one address everywhere:
- OpenAI SDKs and OpenAI-compatible tools: set it as the base URL. Adding
/v1on the end also works. - Ollama tools: set it as the Ollama server URL.
Send your key as Authorization: Bearer YOUR_KEY. The x-api-key header also works. In the examples below, the model name is whatever your model server calls it, such as llama3.2 in Ollama.
curl
curl -N https://YOUR-ID.llm.cdnshark.com/v1/chat/completions \
-H "Authorization: Bearer $LLM_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"llama3.2","stream":true,
"messages":[{"role":"user","content":"Hello!"}]}'
JavaScript (OpenAI SDK)
import OpenAI from "openai";
const ai = new OpenAI({
baseURL: "https://YOUR-ID.llm.cdnshark.com/v1",
apiKey: process.env.LLM_KEY,
});
const stream = await ai.chat.completions.create({
model: "llama3.2",
stream: true,
messages: [{ role: "user", content: "Hello!" }],
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || "");
}
Python (OpenAI SDK)
from openai import OpenAI
import os
ai = OpenAI(base_url="https://YOUR-ID.llm.cdnshark.com/v1",
api_key=os.environ["LLM_KEY"])
stream = ai.chat.completions.create(
model="llama3.2", stream=True,
messages=[{"role": "user", "content": "Hello!"}])
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="", flush=True)
Web and mobile apps
Don't put the API key inside a mobile app or in a web page's JavaScript. Anything shipped to users can be extracted, and whoever has the key can use your model. Call the gateway from your own backend, and have your app talk to your backend.
Using an AI coding assistant or a chat interface? See Use Your Gateway with Cline or Open WebUI.