Codex api quickstart
Start using the Codex API by pointing your OpenAI-compatible SDK to our base URL and authenticating with your generated key. This quickstart covers the exact endpoints, headers, and streaming patterns needed for immediate integration.
Base URL and Authentication
Direct all requests to https://api.codexllm.cc/v1 using standard OpenAI headers. You receive a single API key upon signup, which authorizes all calls. Replace the default endpoint in your SDK configuration with our base URL and insert your key into the Authorization header. This setup ensures compatibility with existing client libraries without modifying core request logic.
curl https://api.codexllm.cc/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "Convert this JSON object to a YAML file."}]
}'Authentication relies on a bearer token passed in every request. If the key is invalid or expired, the server returns a 401 error. Ensure your key is securely stored in environment variables rather than hardcoded in your source files. The system does not support multiple keys per account; generating a new key automatically invalidates the previous one.
First Request with Python SDK
Initialize the OpenAI client in Python by specifying the custom base URL and your API key. Pass the model identifier uncensored to access the unfiltered large language model. Set the context window to handle up to 100,000 tokens for extensive prompt histories. This approach allows you to inject large codebases or documents without truncation errors.
from openai import OpenAI
client = OpenAI(base_url="https://api.codexllm.cc/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)The response object contains the generated text in choices[0].message.content. Handle exceptions for rate limits or insufficient credits gracefully. This method works with any standard OpenAI Python library version that supports custom base URLs.
Node SDK Integration
Configure the Node.js OpenAI client with the same base URL structure used in other languages. Specify the model as uncensored to ensure consistent behavior across your stack. Pass your messages array with the system and user roles defined. The SDK handles serialization and header injection automatically.
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.codexllm.cc/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);Extract the content from the response stream or promise. This integration supports both synchronous and asynchronous patterns. Use this setup for server-side generation or agent workflows requiring deterministic outputs.
Streaming Responses via SSE
Enable streaming by setting the stream parameter to true in your request. The server returns Server-Sent Events (SSE) delivering tokens incrementally. This reduces perceived latency for long-form generation tasks. Parse the SSE stream to render text character-by-character in your UI.
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)The final chunk contains the total token usage for the request. Track costs in real-time by summing the input and output tokens from each chunk. This method is ideal for chat interfaces where immediate feedback improves user experience.
Function Calling and JSON Mode
Define tools in the request payload to enable function calling capabilities. The model returns structured tool calls that your application can execute. Use response_format: {"type": "json_object"} to force strict JSON output for reliable parsing. This feature supports automated data extraction and structured data generation.
Set the temperature parameter to control randomness. Lower values produce more deterministic outputs suitable for code generation. Higher values increase creativity for narrative tasks. Adjust top_p to refine the sampling distribution.
Context Window, Limits, and Errors
The API supports a 100,000 token context window for combined input and output. Max output per request is 16,000 tokens, or 2,048 if max_tokens is omitted. Respect the rate limit of 300 requests per minute per key. Concurrent requests are capped at eight per key.
Handle HTTP 402 errors when prepaid credit is exhausted. Requests fail immediately without consuming tokens if the account balance is insufficient. HTTP 429 indicates rate limit exceeded; implement exponential backoff. The 8 MB request body limit applies to JSON payload size. Errors do not consume credit.
Common questions
Is the Codex API key the same as the standard OpenAI key?
No, you must generate a unique API key from your account dashboard. It is specific to the Codex LLM service and does not work with OpenAI endpoints. Store this key securely as it grants access to your prepaid credit.
How do I handle streaming with the Codex API?
Set the <code>stream</code> parameter to true in your SDK request. The server returns SSE events containing token chunks and final usage statistics. Parse these events to update your UI in real-time without waiting for full completion.
What happens if I exceed the rate limit?
The API returns a 402 error if your credit runs out, and a 429 error if you exceed 300 requests per minute. Implement exponential backoff to retry after a short delay. Concurrent requests are limited to eight per key.
Start with free credit
Use email and password. Key displays immediately.