EN ▾

Uncensored OpenAI-compatible API for developers

Get API key
llamaapi.cc

Llama API Integration: Python, Node and LangChain

Integrating this API takes three changes to an existing OpenAI client: the base URL, the key and the model ID. This page shows the code for Python, Node, curl and LangChain.

Isometric illustration of a laptop connected to a server by a glowing cable, representing an API integration

Updated

Key points

  • Set the base URL to https://api.llamaapi.cc/v1 and the model to uncensored; everything else is a normal OpenAI client.
  • Two endpoints exist: POST /v1/chat/completions and GET /v1/models.
  • Full keys allow 8 concurrent requests and 300 requests per minute; trial keys allow 2 and 60.
  • Handle HTTP 429 with a short backoff and keep streams short enough to free their concurrency slot.

What a llama api integration actually involves

Most people who search for a llama api integration want one thing: to call a hosted chat model from their own code without running GPUs themselves. This service does that through the same wire format the OpenAI SDKs already speak. If your project works with an OpenAI client today, you do not need a new library or a new request shape. You point the client somewhere else.

A short clarification before the code. The model behind this API is one open-weight model, run by an independent provider and tuned to answer without content refusals for lawful adult use. It is not the official API of Meta or of any other vendor, and it is not a router that forwards your request to several providers. Every call goes to the same model, whose ID is uncensored.

The integration surface is small on purpose. There are two methods: POST /v1/chat/completions for generation and GET /v1/models for listing. Authentication is a bearer header. The service is text only, so there is no image or audio generation, no embeddings and no fine-tuning. If your stack needs those, keep that part on another service and use this one for chat.

Step 1: get a key and test it

Sign up with Google, or with an email and password, and open the API key page. New accounts can claim $0.50 of trial credit with one click there. It is one per person, valid for 7 days, and needs no card. That is enough for many thousands of short test calls, as the cost section below shows. The page how to get an API key walks through the screens.

Store the key in an environment variable instead of in source files. The examples below read LLAMAAPI_KEY. Then confirm the key works by listing models:

export LLAMAAPI_KEY="your-key-here"

curl https://api.llamaapi.cc/v1/models \
  -H "Authorization: Bearer $LLAMAAPI_KEY"

A JSON list that includes uncensored means the key, the base URL and your network path are all fine. If you get a 401, the key is wrong or the header is malformed. Fix that before you write any application code, because it removes a whole class of confusing errors later.

Step 2: Python with the openai SDK

Install the official package with pip install openai. The only differences from a default setup are the base_url argument and the model name.

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.llamaapi.cc/v1",
    api_key=os.environ["LLAMAAPI_KEY"],
)

resp = client.chat.completions.create(
    model="uncensored",
    messages=[
        {"role": "system", "content": "You are a concise assistant."},
        {"role": "user", "content": "Explain idempotency keys in two sentences."},
    ],
    temperature=0.7,
)

print(resp.choices[0].message.content)
print(resp.usage)

The usage object gives prompt and completion token counts, which you can multiply by the per-token price to track spend. The response headers also carry X-Balance-USD, so a long-running job can watch its remaining credit without a separate call. Parameters such as temperature, top_p, stop, seed and the frequency and presence penalties are passed through to the model.

Step 3: Node.js

The Node setup mirrors the Python one. Install with npm install openai and use an ES module so top-level await works.

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.llamaapi.cc/v1",
  apiKey: process.env.LLAMAAPI_KEY,
});

const resp = await client.chat.completions.create({
  model: "uncensored",
  messages: [{ role: "user", content: "Give me three names for a fantasy tavern." }],
});

console.log(resp.choices[0].message.content);

If you use a plain fetch instead of the SDK, send the same JSON body to https://api.llamaapi.cc/v1/chat/completions with the headers Authorization: Bearer ... and Content-Type: application/json. Keep the request body under 8 MB, which is the maximum the API accepts.

LangChain and other frameworks

Frameworks that wrap the OpenAI client usually expose the same two settings under different names. In LangChain for Python, the ChatOpenAI class from langchain-openai takes a base URL and a model name:

import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="uncensored",
    base_url="https://api.llamaapi.cc/v1",
    api_key=os.environ["LLAMAAPI_KEY"],
    temperature=0.8,
)

reply = llm.invoke("Write a two-line toast for a guild feast.")
print(reply.content)

Chat front ends and agent tools follow the same pattern. Look for a field labelled custom endpoint, OpenAI-compatible provider or base URL, paste the address with the /v1 suffix, add the key, and type uncensored as the model name. SillyTavern, for example, lets you add an OpenAI-compatible endpoint this way. If a tool insists on a model dropdown that you cannot edit, call GET /v1/models and check whether it has a refresh button that reads the list from the server.

The quickstart in the docs has the same settings in one place, which is handy when you are configuring several tools in a row.

Streaming, tools and JSON mode

Three features matter for most real applications, and all three work through the standard parameters. Streaming uses server-sent events: set stream: true and read chunks as they arrive. Usage is reported at the end of the stream. Tool calling accepts tools and tool_choice, streams tool_calls deltas, and expects your results back as messages with role: "tool". JSON mode is enabled with response_format: {"type": "json_object"}.

stream = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "List five test cases for a login form."}],
    stream=True,
)

for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

When you use JSON mode, also tell the model in the prompt that you expect JSON and describe the keys. The setting constrains the output format, but a clear instruction produces better field names and fewer empty values. Parse the result inside a try block anyway, since any model can occasionally return something unexpected.

A short production checklist

Before you ship the integration, walk through a few items that tend to be skipped in a first prototype. None of them takes long, and each one prevents a specific kind of late-night incident.

  • Timeouts. Set a client timeout well above your typical generation time, but not infinite. Long completions on a 100,000-token window can run for a while, and a hung connection that never closes will also hold a concurrency slot.
  • Queueing. With 8 concurrent requests on a full key, a burst of 50 users needs a queue on your side. A small worker pool with a semaphore of 6 or 7 leaves headroom for retries.
  • Key handling. Keep the key on your server. Never ship it in a browser bundle or a mobile app, because anyone can read it and spend your credit.
  • Balance alerts. Read X-Balance-USD from responses and warn yourself when it drops under a threshold, so a job does not stop in the middle of the night.
  • Context trimming. Prompt and completion share the 100,000-token window. Cap the history you send, and you cap both errors and input cost.

If something behaves differently from what this page describes, the page on the Llama-style uncensored API gives background on the model, and support can look at a specific request ID.

Limits, errors and retries

A full key allows 8 concurrent requests and 300 requests per minute. A trial key allows 2 concurrent requests and 60 per minute. Exceeding either returns HTTP 429. The error code tells you which limit you hit: rate_limited means too many requests per minute, and concurrency means too many at once. On temporary overload the API also answers 429, with a Retry-After: 5 header.

One detail catches people in production: a streamed request holds its concurrency slot until the stream ends. If a client opens a stream and then stops reading, that slot stays busy. Always consume or close the stream, and set a client-side timeout.

import time
from openai import OpenAI, RateLimitError

client = OpenAI(base_url="https://api.llamaapi.cc/v1", api_key="your-key-here", max_retries=0)

def ask(messages, tries=4):
    for attempt in range(tries):
        try:
            return client.chat.completions.create(model="uncensored", messages=messages)
        except RateLimitError as err:
            wait = 5 * (attempt + 1)
            print("429, waiting", wait, "seconds:", err)
            time.sleep(wait)
    raise RuntimeError("still rate limited after retries")

Log the X-Request-Id header with every failure. If you contact support, that ID lets them find the exact request. Failed or refused requests are not charged, so retrying costs nothing for the failed attempt.

What the integration costs

Pricing is pay as you go from prepaid credit: $0.15 per 1M input tokens and $0.50 per 1M output tokens, with no subscription and no expiry on the balance. A typical chat turn with 2,000 input tokens and 500 output tokens costs 2,000 x $0.15 / 1,000,000 = $0.0003 for input plus 500 x $0.50 / 1,000,000 = $0.00025 for output, so $0.00055 in total. That means $0.50 of trial credit covers roughly 900 turns of that size.

When you move to production, top-ups run from $20 to $500 in whole dollars, with a bonus of 5% from $50, 10% from $100 and 15% from $200. You can pay with crypto (USDT on TRC20, USDC on Base). The pricing page has the current table. Prompts are not used for training, which is worth knowing before you send customer data through any integration.

Questions and answers

Is this the official Llama API from Meta?

No. It is a hosted OpenAI-compatible API in front of one open-weight model run by an independent provider. It is not the official API of Meta or any other vendor.

Which base URL and model name do I use?

Use https://api.llamaapi.cc/v1 as the base URL and uncensored as the model ID. Authentication is a standard Bearer token in the Authorization header.

Can I use LangChain or LlamaIndex with it?

Yes, any framework that lets you set a custom OpenAI-compatible base URL and model name works. In LangChain that means ChatOpenAI with base_url and model set.

Does it support embeddings or image generation?

No. The API is text only and offers chat completions and a model list. Use another service for embeddings, images, audio or fine-tuning.

What happens when I hit a rate limit?

You get HTTP 429 with the code rate_limited or concurrency. Wait a few seconds and retry, and avoid leaving streams open longer than needed.

Your key is one form away

Create an account, copy the key, change the base URL. That is the whole setup.

Start with trial credit

Email and password, key on screen right away.