Official SDK Support
Quickly integrate with MoleAPI using OpenAI-compatible SDKs
MoleAPI is compatible with mainstream OpenAI-style SDKs. In most cases, you only need to replace two items:
apiKeybaseURL
When to use an SDK directly
If any of the following applies to you, you should generally prioritize using the official SDK instead of manually assembling HTTP requests:
- You are already developing your application in Python / Node.js
- You plan to add streaming output, images, audio, or tool calling later
- You want to minimize low-level request handling and get the functionality working first
A simple rule of thumb
If you only want to verify that your account works, start with cURL; if you're ready to integrate the capability into a project, go straight to the SDK.
Python example
from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ["MOLEAPI_KEY"],
base_url="https://api.moleapi.com/v1",
)
resp = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "用一句话说明 SDK 接入要点"}],
)
print(resp.choices[0].message.content)If you have not set an environment variable yet, you can run this first in your current terminal:
$env:MOLEAPI_KEY="sk-xxxxxxxxxxxxxxxx"Node.js example
import OpenAI from "openai";
async function main() {
const client = new OpenAI({
apiKey: process.env.MOLEAPI_KEY,
baseURL: "https://api.moleapi.com/v1",
});
const res = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: "Hello MoleAPI" }],
});
console.log(res.choices[0]?.message?.content);
}
main().catch(console.error);In Node.js, it is also recommended to read the Key from environment variables rather than hardcoding the real secret key in source code or committing it to the repository.
Most common compatibility issues
baseURLpoints to another platform's address, or/v1is missing- The environment variable was not injected successfully, so the actual value used in the request is empty
- An incompatible model name or parameter was copied along with the example
- It works locally, but the deployment environment does not use the same Key and Base URL
Recommended integration order
- Run the shortest example successfully first
- Then replace it with the actual model your application needs
- Finally add streaming output, Retry, timeout handling, and logging
This makes troubleshooting the simplest, because you can clearly tell whether the issue is "the platform integration is not working" or "more complex application logic introduced a new problem."
Common troubleshooting
- If you get a 401: check your API Key and environment variables first
- If you get a 404: first check whether
baseURLincludes/v1 - If the model is unavailable: check your Group and model permissions
What to read next
How is this guide?
Last updated on