OpenAI-Compatible API: Migrate in 5 Minutes
Switch to Layermod in minutes — no code rewrite needed. Simply change the base URL and start using GDPR-compliant AI.
Switching Is This Easy
Layermod offers a fully OpenAI-compatible API. This means you don't need to rewrite any code. Just change two lines in your configuration and your entire application runs on European infrastructure — GDPR-compliant and without vendor lock-in.
Whether you're using the OpenAI SDK directly, running LangChain pipelines, or building with the Vercel AI SDK: the migration works the same everywhere. In this guide, we'll walk you through the switch step by step.
Step 1: Create an Account
Sign up at console.layermod.com and create an API key. The process takes less than a minute:
- Create an account (email or OAuth)
- In the dashboard, go to API Keys and generate a new key
- Store the key securely in your
.envfile:
LAYERMOD_KEY=lm_sk_your_api_key_hereLayermod API keys always start with the lm_sk_ prefix. Keep the key safe — it is only displayed once. Starter credits are included in the free plan; additional packages are available at /pricing.
Step 2: Change the Base URL
Replace the OpenAI base URL with the Layermod URL. This is the only code change you need to make:
// Before
const openai = new OpenAI({
baseURL: "https://api.openai.com/v1"
})
// After
const openai = new OpenAI({
baseURL: "https://api.layermod.com/v1",
apiKey: process.env.LAYERMOD_KEY
})If you set the base URL via environment variables, you can make the change entirely in your .env file — no code modifications at all:
OPENAI_BASE_URL=https://api.layermod.com/v1
OPENAI_API_KEY=lm_sk_your_api_key_hereThe OpenAI SDK reads these variables automatically. This lets you switch between Layermod and OpenAI without touching your code. Learn more about why EU hosting matters for AI applications.
Step 3: Choose a Model
Use any available model — GPT-5.4, Claude, Llama, and more. Layermod acts as an LLM API Gateway giving you access to all major model providers through a single API:
const response = await openai.chat.completions.create({
model: "gpt-5.4", // or "claude-sonnet-4-6", "llama-4-maverick"
messages: [{ role: "user", content: "Hello!" }]
})You can always find the full list of available models via the /v1/models endpoint or in your dashboard.
What Changes (and What Doesn't)
Changes:
- Base URL points to Layermod
- API key is a Layermod key
- Data is processed in the EU
Stays the same:
- Your existing code
- The OpenAI SDK
- The API interface (Chat Completions, Streaming, Function Calling)
Framework-Specific Guides
LangChain (Python)
If you're using LangChain, simply replace the ChatOpenAI model configuration:
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="gpt-5.4",
base_url="https://api.layermod.com/v1",
api_key="lm_sk_your_api_key_here"
)
response = llm.invoke("Explain GDPR in three sentences.")
print(response.content)All LangChain features — Chains, Agents, Retrieval-Augmented Generation, and output parsers — work without modification. The compatible API ensures LangChain cannot tell the difference.
Vercel AI SDK (TypeScript)
The Vercel AI SDK works seamlessly with Layermod as well. Use the OpenAI provider with a custom base URL:
import { createOpenAI } from "@ai-sdk/openai";
import { generateText } from "ai";
const layermod = createOpenAI({
baseURL: "https://api.layermod.com/v1",
apiKey: process.env.LAYERMOD_KEY,
});
const { text } = await generateText({
model: layermod("gpt-5.4"),
prompt: "What is Layermod?",
});This works with both generateText and streamText for streaming use cases in Next.js, Nuxt, or SvelteKit.
curl (Quick Test)
Test the API directly from the command line before modifying your code:
curl https://api.layermod.com/v1/chat/completions \
-H "Authorization: Bearer lm_sk_your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.4",
"messages": [{"role": "user", "content": "Hello Layermod!"}]
}'If you get a valid response here, you know your API key works and the connection is established.
Streaming
Server-Sent Events (SSE) streaming works exactly like it does with OpenAI. You don't need to change anything in your streaming code:
const stream = await openai.chat.completions.create({
model: "gpt-5.4",
messages: [{ role: "user", content: "Write a short story." }],
stream: true,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content || "";
process.stdout.write(content);
}The streaming format is 100% compatible. Whether you use stream: true in the SDK, consume Server-Sent Events directly, or use the Vercel AI SDK with streamText — everything works without modification.
Function Calling / Tool Use
Layermod fully supports Function Calling (Tool Use). Define your tools as usual:
const response = await openai.chat.completions.create({
model: "gpt-5.4",
messages: [{ role: "user", content: "What's the weather in Berlin?" }],
tools: [
{
type: "function",
function: {
name: "get_weather",
description: "Get current weather for a location",
parameters: {
type: "object",
properties: {
location: { type: "string", description: "City or location" }
},
required: ["location"]
}
}
}
]
});
const toolCall = response.choices[0].message.tool_calls?.[0];
if (toolCall) {
console.log(toolCall.function.name); // "get_weather"
console.log(toolCall.function.arguments); // '{"location": "Berlin"}'
}Parallel function calling, forced tool invocation via tool_choice, and multi-turn conversations with tool results are all fully supported.
Troubleshooting
Authentication Errors (401 Unauthorized)
- Verify that your API key starts with
lm_sk_. OpenAI keys (sk-...) do not work with Layermod. - Make sure the key is correctly set in your environment variable — no extra spaces or line breaks.
- If needed, generate a new key in the Dashboard.
Model Not Found (404 Not Found)
- Not all OpenAI model names are available 1:1. Fetch the list of available models:
curl https://api.layermod.com/v1/models \
-H "Authorization: Bearer lm_sk_your_api_key_here"- Double-check the exact spelling of the model name (case-sensitive).
Rate Limiting (429 Too Many Requests)
- The Starter plan has standard rate limits. For higher limits, purchase a credit package at /pricing.
- The response headers
x-ratelimit-remainingandx-ratelimit-resetshow your current status. - Contact support for enterprise-grade limits if needed.
Timeout Errors
- Large context windows or long responses can increase response times. Raise the timeout in your HTTP client.
- Use streaming (
stream: true) to reduce time-to-first-token.
Conclusion
Migrating to Layermod literally takes 5 minutes. No breaking changes, no new SDKs, no learning curve. Whether you're using the OpenAI SDK, LangChain, Vercel AI SDK, or a simple curl request — everything works instantly on our GDPR-compliant infrastructure in the EU.
Ready to get started? Create your account and claim your first credits. Flexible packages are available on our pricing page.