Connect to the LLMPort API
Call available AI models through one API. These examples use chat completions and require a compatible chat model. For images and videos, use the Studio or the endpoint listed for that model.
Prepare your account and key
Sign in, create an API key in your account, and check that you have available credit. Keep the key in server environment variables; never include it in browser code.
Set environment variables
Replace the placeholders with your key and an exact chat model ID from the catalog, rather than a display name.
export LLMPORT_API_KEY="your-llmport-api-key"
export LLMPORT_MODEL="exact-chat-model-id-from-pricing"Python example
Run pip install openai, then run this Python code.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://llmport.si/v1",
api_key=os.environ["LLMPORT_API_KEY"],
)
response = client.chat.completions.create(
model=os.environ["LLMPORT_MODEL"],
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)Node.js example
Run npm install openai, save the code as quickstart.mjs, then run node quickstart.mjs.
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://llmport.si/v1",
apiKey: process.env.LLMPORT_API_KEY,
});
const response = await client.chat.completions.create({
model: process.env.LLMPORT_MODEL,
messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.choices[0].message.content);curl example
Test the connection from your terminal. This makes a real request and is billed according to your account settings.
curl https://llmport.si/v1/chat/completions \
-H "Authorization: Bearer $LLMPORT_API_KEY" \
-H "Content-Type: application/json" \
-d "$(printf '{"model":"%s","messages":[{"role":"user","content":"Hello!"}]}' "$LLMPORT_MODEL")"Streaming and common errors
For models that support streaming, set stream=true and read the response chunks. For 401, check your key; for 403, check model and group access; for 429, check rate limits and credit. If a model is unavailable, check its exact ID and supported endpoint. Image, video and model-specific parameters differ.