Migration API: Troubleshooting Common LLM Integration Errors
Migrating your LLM integration often fails due to subtle configuration errors rather than complex logic bugs. This guide addresses the most frequent pitfalls when moving to a new uncensored AI API, ensuring your code works reliably from day one.
Last updated
Summary
- Base URL misconfiguration is the most common cause of immediate connection failures.
- Ignoring the 100,000-token context window leads to silent truncation of long conversations.
- Streaming requires specific header and event handling that standard synchronous calls do not need.
- Rate limits of 300 requests per minute require robust retry logic to avoid 429 errors.
Misconfiguring the Base URL
The first point of failure is almost always the base URL. When you switch providers, you must update the endpoint that your SDK contacts. A wrong URL results in a 404 or 403 error before your payload even leaves your machine.
Ensure your client points to the correct domain. For our service, the base URL is https://api.apimigration.com/v1. This URL works with standard OpenAI SDKs by simply changing the base_url parameter.
- Verify the protocol (HTTPS vs HTTP).
- Check for trailing slashes in your client configuration.
- Confirm the version path (
/v1) matches your API specification.
curl https://api.apimigration.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "Run the latest migration script for the user table"}]
}'
Ignoring Context Window Limits
Your model has a hard limit of 100,000 tokens for the combined prompt and completion. If you exceed this, the API rejects the request or truncates your history silently depending on implementation. Always track your token usage to avoid hitting this wall.
Additionally, the maximum output per request is 16,000 tokens. If you do not set max_tokens, the default is 2,048 tokens. This difference is significant for long-form generation tasks.
- Monitor total token count per request.
- Set
max_tokensexplicitly for long outputs. - Implement sliding window logic for very long conversations.
from openai import OpenAI
client = OpenAI(base_url="https://api.apimigration.com/v1", api_key="YOUR_KEY")
resp = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Summarise this thread without softening it."}],
)
print(resp.choices[0].message.content)
Incorrect Streaming Implementation
Streaming responses require specific handling of Server-Sent Events (SSE). If you treat a stream as a single JSON object, your code will hang or crash. Each chunk contains partial data, and the final chunk includes token usage statistics.
Read the stream incrementally. Process each event as it arrives. This reduces perceived latency for end-users. Do not wait for the entire response before processing.
- Open a connection and read line by line.
- Parse
data:lines as JSON. - Handle the
[DONE]signal correctly.
stream = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Tell the story in second person."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
Overlooking Rate Limits
Our API allows 300 requests per minute per key. If your application spikes, you will receive 429 Too Many Requests errors. You must implement exponential backoff to handle these gracefully.
Concurrent requests are also limited to 8 at the same time per key. Exceeding this limit can cause connection pool exhaustion. Monitor your concurrent connections closely.
- Implement exponential backoff for 429 errors.
- Limit concurrent connections to 8.
- Use a circuit breaker pattern for high load.
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.apimigration.com/v1", apiKey: process.env.API_KEY });
const resp = await client.chat.completions.create({
model: "uncensored",
messages: [{ role: "user", content: "Draft a villain monologue for my game." }],
});
console.log(resp.choices[0].message.content);
Assuming Standard JSON Formats
While we follow OpenAI-compatible formats, assumptions can break your integration. Ensure you request json_object in response_format if you need strict JSON. Without this, the model may return markdown or plain text.
Parse the response carefully. Validate the JSON structure before using it. This prevents runtime errors in downstream services.
- Set
response_formatto{"type": "json_object"}. - Validate JSON before parsing.
- Handle malformed responses gracefully.
curl https://api.apimigration.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "Run the latest migration script for the user table"}]
}'
Neglecting Error Handling
APIs fail. Network timeouts, server errors, and invalid payloads happen. Your code must handle these errors without crashing. Log the error details for debugging.
Check the error code and message. Retry on transient errors. Fail fast on permanent errors. This distinction saves time and resources.
- Log error codes and messages.
- Retry on 5xx errors with backoff.
- Fail fast on 4xx errors.
from openai import OpenAI
client = OpenAI(base_url="https://api.apimigration.com/v1", api_key="YOUR_KEY")
resp = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Summarise this thread without softening it."}],
)
print(resp.choices[0].message.content)
Payment and Key Rotation Issues
Our API uses prepaid credit via crypto. Credit does not expire. If you run out of credit, requests fail. Monitor your balance and top up before it hits zero.
Each account has one active key. Generating a new key invalidates the old one immediately. Ensure your deployment updates the key atomically to avoid downtime.
- Monitor credit balance regularly.
- Rotate keys atomically.
- Update all instances simultaneously.
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.apimigration.com/v1", apiKey: process.env.API_KEY });
const resp = await client.chat.completions.create({
model: "uncensored",
messages: [{ role: "user", content: "Draft a villain monologue for my game." }],
});
console.log(resp.choices[0].message.content);
Summary of Best Practices
Migration success depends on attention to detail. Verify your base URL. Respect context limits. Handle streaming correctly. Manage rate limits. Validate JSON. Handle errors. Manage payments and keys. Following these steps ensures a smooth transition.
Test your integration thoroughly before going live. Use the trial credit to verify your setup. This prevents costly downtime in production.
- Verify base URL.
- Respect context limits.
- Handle streaming correctly.
- Manage rate limits.
- Validate JSON.
- Handle errors.
- Manage payments and keys.
curl https://api.apimigration.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "Run the latest migration script for the user table"}]
}'Common questions
What is the context window size?
The context window is 100,000 tokens for prompt and completion combined. The maximum output per request is 16,000 tokens. If you do not set max_tokens, the default is 2,048 tokens.
How do I stream responses?
Use Server-Sent Events (SSE). Read each line and parse the JSON data. The final chunk includes token usage. Do not wait for the entire response.
What are the rate limits?
You can make 300 requests per minute per key. You can have 8 concurrent requests per key. Exceeding these limits results in 429 errors.
How do I pay for the API?
Payments are crypto only. You can use USDT (TRC20) or USDC (Base). Top-ups range from $20 to $500. Credit does not expire.
Get your API key
Register, copy the key, update the base URL. Setup is complete.