OpenAI SDK compatibility
LAYSO AI provides OpenAI-compatible endpoints. An existing OpenAI SDK project usually only needs a new Base URL and API key, plus the exact model ID shown on the LAYSO AI pricing page.
One key for every platform model
One LAYSO AI API key can access every model available on the platform. Billing follows the selected model's current price. Every successful request has an itemized charge, while failed tasks are not charged.
Before you begin
- Create and copy a key on the API Keys page.
- Choose a model on the Models and pricing page, then copy the exact model ID displayed there.
- Confirm that your server can reach
https://api.layso.ai.
| Setting | LAYSO AI value |
|---|---|
| Base URL | https://api.layso.ai/v1 |
| API key environment variable | LAYSO_API_KEY |
| Model | <MODEL_ID> from the Models and pricing page |
Do not place a key in frontend code
Run the OpenAI SDK on a server, in a command-line script, or in another trusted environment. Never commit a complete API key to Git or expose it in logs, screenshots, or browser code.
Install the SDK
Python
python -m pip install --upgrade openaiTypeScript / JavaScript
npm install openaiMigrate from a direct OpenAI connection
Python
The Python SDK uses the snake-case base_url option:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["LAYSO_API_KEY"],
base_url="https://api.layso.ai/v1",
)TypeScript / JavaScript
The TypeScript and JavaScript SDKs use the camel-case baseURL option:
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.LAYSO_API_KEY,
baseURL: "https://api.layso.ai/v1",
});The option names are different
Python uses base_url; TypeScript and JavaScript use baseURL. The Base URL already contains /v1, so do not append it again.
Set the API key
macOS / Linux / WSL
export LAYSO_API_KEY="<YOUR_LAYSO_API_KEY>"Windows PowerShell
$env:LAYSO_API_KEY = "<YOUR_LAYSO_API_KEY>"Windows CMD
set LAYSO_API_KEY=<YOUR_LAYSO_API_KEY>These commands affect only the current terminal session. For production, store the key with your deployment platform's secret manager.
Use the Responses API
The Responses API is the recommended choice for new projects. The selected model must support this endpoint; verify its capabilities in the LAYSO AI API reference and model details.
Python
response = client.responses.create(
model="<MODEL_ID>",
input="Introduce LAYSO AI in one sentence.",
)
print(response.output_text)TypeScript / JavaScript
const response = await client.responses.create({
model: "<MODEL_ID>",
input: "Introduce LAYSO AI in one sentence.",
});
console.log(response.output_text);Use Chat Completions
Existing projects can continue using Chat Completions. The message structure remains compatible with the OpenAI SDK.
Python
completion = client.chat.completions.create(
model="<MODEL_ID>",
messages=[
{"role": "user", "content": "Introduce LAYSO AI in one sentence."}
],
)
print(completion.choices[0].message.content)TypeScript / JavaScript
const completion = await client.chat.completions.create({
model: "<MODEL_ID>",
messages: [
{ role: "user", content: "Introduce LAYSO AI in one sentence." },
],
});
console.log(completion.choices[0].message.content);Stream output
Python
stream = client.chat.completions.create(
model="<MODEL_ID>",
messages=[{"role": "user", "content": "Write a short welcome message."}],
stream=True,
)
for chunk in stream:
text = chunk.choices[0].delta.content or ""
print(text, end="", flush=True)TypeScript / JavaScript
const stream = await client.chat.completions.create({
model: "<MODEL_ID>",
messages: [{ role: "user", content: "Write a short welcome message." }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}Verify the migration
After a minimal request succeeds, confirm the following:
- The response model matches the model selected on the Models and pricing page.
- The successful request has an itemized charge in LAYSO AI task or billing details.
- A failed request did not create a charge.
- The project no longer contains the direct OpenAI URL or an old key.
Compatibility scope
LAYSO AI's OpenAI-compatible layer covers common call patterns, but exact capabilities depend on the endpoint, model, and provider. Do not assume that every OpenAI-specific option works with every model.
| Capability | Guidance |
|---|---|
| Responses | Prefer for new projects; confirm model support first |
| Chat Completions | Suitable for migrating existing chat projects |
| Streaming | Supported by both call patterns; follow the matching API reference |
| Function calling / JSON / Vision | Check the selected model's capability details |
| Embeddings / Images | Use the matching endpoint and a capable model |
| Models | Query through /v1/models |
Frameworks and tools
Any server-side framework that accepts a custom OpenAI Base URL and API key can follow the same migration pattern. This documentation includes dedicated guides for:
When configuring another framework, use the option names supported by its current version. Do not assume they are identical to the OpenAI SDK's base_url or baseURL names.
Troubleshooting
401 or 403
Confirm the key came from the LAYSO AI API Keys page, contains no whitespace or line breaks, and has been reloaded by the process.
404
The client Base URL must be https://api.layso.ai/v1. Do not use only https://api.layso.ai, and do not duplicate the path as /v1/v1.
Model not found
Do not guess a model alias. Return to the Models and pricing page, copy the exact model ID, and retry.
An option is rejected
Provider and model capabilities differ. Remove optional parameters, then compare the request with the current LAYSO AI API reference.
Browser CORS or exposed-key warning
Do not call the API directly from browser code. Run the OpenAI SDK on your server and expose only a controlled backend route to the frontend.
