EN ▾
Get API key

Your private, refusal-free API alternative.

Get API key
https://api.uncensoredllama.top/v1uncensored

LlamaIndex API Key Setup for an OpenAI-Compatible LLM

LlamaIndex needs no key of its own. The key belongs to the model provider you connect. Here is how to wire a custom OpenAI-compatible endpoint into LlamaIndex and avoid the usual key error.

Updated

Document sheets flowing into a glowing index lattice linked to a cloud server, illustrating a LlamaIndex RAG setup.

Key points

  1. LlamaIndex is a framework, not a Llama model; the key comes from your LLM endpoint.

  2. Use OpenAILike with api_base, api_key and model uncensored.

  3. Set Settings.embed_model too, or LlamaIndex asks for an OpenAI key for embeddings.

  4. Chunk and retrieve with the 100,000-token context window in mind.

Where the LlamaIndex API key comes from

When people search for a llama index api key, they usually hit one of two confusions. LlamaIndex is a Python framework for building retrieval and agent apps over your data. It is not Meta's Llama model, and the framework itself does not issue keys. (LlamaIndex's separate cloud product has its own keys; this page does not cover it.) What the framework needs is a key for whichever language model you plug in.

Here that is a key from this site's OpenAI-compatible API. Create one on the API key page after sign-up. New users can claim $0.50 of trial credit with one click, which is enough to index and query a small document set. The model ID is uncensored, a single open-weight model run by an independent provider and tuned to answer without content refusals for lawful adult use.

Install the packages

LlamaIndex splits integrations into small packages. You need the core, the generic OpenAI-compatible LLM wrapper, and a local embedding model.

pip install llama-index llama-index-llms-openai-like llama-index-embeddings-huggingface
export UNCENSORED_API_KEY="your-key-here"

The embedding package is needed because this API is text-generation only: it has no embeddings endpoint. Embeddings turn your documents into vectors for search, so you run a small embedding model on your own machine, or use a separate provider you already trust.

One more check before you start: confirm the key works outside LlamaIndex. A single request with the plain OpenAI client, or a curl call to https://api.uncensoredllama.top/v1/models with the header Authorization: Bearer YOUR_KEY, tells you whether any later failure is in the key or in your LlamaIndex configuration. That one test removes half the guesswork.

Configure the LLM with a custom base URL

Use the OpenAILike class. It exists for servers that speak the OpenAI format but are not OpenAI, which is exactly this case. Set it globally through Settings so every index and engine picks it up.

import os
from llama_index.core import Settings
from llama_index.llms.openai_like import OpenAILike

Settings.llm = OpenAILike(
    model="uncensored",
    api_base="https://api.uncensoredllama.top/v1",
    api_key=os.environ["UNCENSORED_API_KEY"],
    is_chat_model=True,
    context_window=100000,
    timeout=120,
)

Three of these arguments matter. is_chat_model=True tells LlamaIndex to use the chat completions route. context_window=100000 matches the real limit, so prompt packing does not shrink needlessly. timeout gives long answers room. If you use agents with tools, also pass is_function_calling_model=True, since tool calling is supported here.

The same pattern applies to agents. Wrap a query engine as a tool, give the agent the tool list, and let it decide when to search. Each step is one more call against your limits, so watch the concurrency count when several agents run side by side, and keep the retrieval top-k modest to leave room for the reasoning steps.

Set the embedding model or you will see an OpenAI key error

The most common failure is an error asking for an OPENAI_API_KEY even though you configured another LLM. The cause is that LlamaIndex defaults to OpenAI's embedding model, and building an index calls it. Set the embedding model explicitly.

from llama_index.core import Settings
from llama_index.embeddings.huggingface import HuggingFaceEmbedding

Settings.embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")

This downloads a small model once and runs it on your CPU. It keeps your document text on your machine during indexing. Only the retrieved chunks and the question go to the API at query time. The provider does not use prompts for training.

Keep the same embedding model for indexing and querying. If you change it later, rebuild the index, because vectors from different models are not comparable.

Build an index and ask a question

Put some files in a data folder, then load, index and query.

import os
from llama_index.core import Settings, SimpleDirectoryReader, VectorStoreIndex
from llama_index.core.node_parser import SentenceSplitter
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
from llama_index.llms.openai_like import OpenAILike

Settings.llm = OpenAILike(
    model="uncensored",
    api_base="https://api.uncensoredllama.top/v1",
    api_key=os.environ["UNCENSORED_API_KEY"],
    is_chat_model=True,
    context_window=100000,
)
Settings.embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
Settings.node_parser = SentenceSplitter(chunk_size=512, chunk_overlap=64)

docs = SimpleDirectoryReader("data").load_data()
index = VectorStoreIndex.from_documents(docs)

engine = index.as_query_engine(similarity_top_k=4)
print(engine.query("What are the main plot points in these notes?"))

Indexing runs locally and costs nothing in API credit. Each query sends the question plus four chunks of about 512 tokens, so it is a small request. By the rates on the pricing page, 2,400 input tokens and 300 output tokens cost 2,400 x $0.15 / 1M + 300 x $0.50 / 1M = $0.00036 + $0.00015 = $0.00051 per answer.

What happens during a query

Knowing the flow makes debugging easier. When you call query, LlamaIndex embeds your question with the local embedding model, searches the vector store for the closest chunks, and fills a prompt template with those chunks and the question. Only that final prompt goes to the API. The response comes back as text, which LlamaIndex wraps in a response object with the source nodes attached.

That means two separate things can go wrong. If the answer is off topic, the retrieval step probably returned the wrong chunks, and the fix is in chunking or the embedding model. If the retrieved chunks are right but the answer is poor, the fix is in the prompt or the generation settings. Print response.source_nodes to tell which case you have, and check the scores next to each node.

If you prefer a hosted embedding service, LlamaIndex has integration packages for many of them, and you set them the same way through Settings.embed_model. The trade-off is that your document text then goes to that second provider. A local model avoids that, and a small one like the one above is fast enough for thousands of pages on an ordinary laptop.

Streaming and chat engines

For an interactive feel, stream the answer. For follow-up questions, use a chat engine that rewrites each question using the conversation so far.

# continuing from the index above
stream_engine = index.as_query_engine(streaming=True, similarity_top_k=4)
stream_engine.query("Summarise the setting in three sentences.").print_response_stream()

chat = index.as_chat_engine(chat_mode="condense_plus_context")
print(chat.chat("Who is the antagonist?"))
print(chat.chat("What does that character want?"))

A streamed request holds one of your concurrency slots until it ends. A full key has 8, a trial key has 2.

Saving the index so you do not rebuild it

Embedding a large folder takes minutes on a CPU, so do it once and store the result. The default vector store lives in memory, but you can write it to disk and load it later.

from llama_index.core import StorageContext, load_index_from_storage

index.storage_context.persist(persist_dir="./storage")

# in a later run, after setting Settings.llm and Settings.embed_model again
storage = StorageContext.from_defaults(persist_dir="./storage")
index = load_index_from_storage(storage)

Remember that Settings are not saved with the index. Each new process must set the LLM (with your base URL https://api.uncensoredllama.top/v1 and key) and the same embedding model before loading. For larger collections, LlamaIndex supports external vector databases, which you can attach through their own integration packages.

Before shipping this, test with questions whose answers you already know. Ask five questions about facts that appear in exactly one place in your documents and see whether the source nodes point there. If retrieval misses, lower the chunk size, raise similarity_top_k, or add metadata such as file names that you can filter on. Only after retrieval looks right is it worth tuning the prompt wording.

Using the large context window well

With 100,000 tokens of context, you can pass far more than four chunks. Raising similarity_top_k to 12 or 20 often improves answers on questions that span several passages. Each extra 512-token chunk adds 512 x $0.15 / 1M, about $0.000077, so retrieval depth is cheap. The real limit is relevance: more chunks add noise as well as coverage.

Smaller chunks (256 to 512 tokens) suit factual lookup. Larger chunks (1,024 or more) suit narrative material where meaning spans paragraphs. Try both on a handful of real questions before you index everything.

Troubleshooting

  • Error 401 or invalid key. Check that the key is exported in the shell that runs Python, and that you use the bearer value without extra quotes.
  • Asks for OPENAI_API_KEY. Embeddings are not configured. Set Settings.embed_model.
  • Model not found. The name must be uncensored. Call GET /v1/models to confirm.
  • HTTP 429. Code rate_limited means too many requests per minute; concurrency means too many at once. Reduce parallel queries and honour Retry-After.
  • Empty or short answers. Check whether retrieval returned relevant nodes by printing response.source_nodes.

More setup detail is in the docs.

Questions and answers

Does LlamaIndex have its own API key?

The open-source framework does not. You supply a key for the language model you connect, and optionally for an embedding provider.

Can I use this API for embeddings in LlamaIndex?

No. The API is text generation only, with no embeddings. Use a local model such as a HuggingFace embedding, or a separate embedding provider.

Which class should I use for a custom OpenAI-compatible endpoint?

OpenAILike from llama-index-llms-openai-like. Pass api_base, api_key, model and is_chat_model=True.

Is LlamaIndex the same as Llama?

No. LlamaIndex is a framework for connecting models to your data. Llama is a family of language models from Meta.

Your key is one form away

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