Base URL and Authentication
Our API lives at https://api.huggingfacellmapi.com/v1. You authenticate using a Bearer token sent in the Authorization header. Generate your key instantly via the Get API key page using Google or email. Keep this key secure; anyone with it can spend your prepaid credits. If you lose it, generate a new one to replace the old active key. No phone number is required to start.
First Request with cURL
Send a raw JSON payload to test the endpoint immediately. Use the model ID uncensored to bypass standard filters. The following cURL command demonstrates a basic text generation request.
curl https://api.huggingfacellmapi.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "Summarize the release notes for version three point zero five"}]
}'This returns a JSON object containing the generated text. Check the choices array for the actual content. If you receive a 401 error, verify your key is correct and active.
Python SDK Integration
Use the official openai Python library for a clean interface. Point the client to our base URL and set your API key. This approach handles retries and JSON parsing automatically.
from openai import OpenAI
client = OpenAI(base_url="https://api.huggingfacellmapi.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)Install the package via pip. You can then call the chat completions endpoint just like you would with OpenAI. The response object gives you access to token usage and finish reasons.
Node.js Client Setup
JavaScript developers can use the openai Node package. Configure the client with our specific base URL. This ensures all requests route through our uncensored servers.
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.huggingfacellmapi.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);Run this snippet in your Node environment. It demonstrates a simple synchronous call. You can integrate this into Express routes or serverless functions easily.
Streaming Responses
Enable streaming by setting stream: true. The server sends Server-Sent Events (SSE) containing partial tokens. This reduces perceived latency for end-users.
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)Parse each chunk as it arrives. The final chunk contains the total token usage for the request. This is useful for building chat interfaces that type out responses in real-time.
Limits, Errors, and Context
The context window is 100,000 tokens for prompt and completion combined. You can request up to 16,000 output tokens. Errors like 401 indicate an invalid key, while 402 means insufficient credit. Rate limits cap you at 300 requests per minute. Requests exceeding 8 MB in size will be rejected. Errors during processing do not consume your credits.