EN ▾

Uncensored API. No refusals. Crypto only.

Create key

Llama AI SDK: Using the OpenAI SDK With Llama-Style APIs

If you searched for a llama ai sdk, the practical answer is that you do not need a special one. Hosted open-weight models usually expose an OpenAI-compatible API, so the official OpenAI libraries for Python and JavaScript work after you change two settings.

Last updated

A toolbox with glowing connector pieces snapping into a server socket, representing an SDK linking to an API

Summary

  • Change base_url and api_key; keep the rest of your OpenAI code as it is.
  • Our endpoint is https://api.llamaaiapi.com/v1 and the model ID is uncensored.
  • Streaming, system prompts, JSON mode and tool calling use the standard parameters.
  • Frameworks such as LangChain and the Vercel AI SDK accept a custom base URL too.

Why the OpenAI SDK is the Llama SDK

Open-weight model families have no single vendor SDK that every host follows. What most hosts agree on is the wire format: the chat completions API that OpenAI popularized. A client library built for that format talks to any server that implements it. So the standard route to a llama ai sdk is the OpenAI package you probably already have installed, pointed at a different address.

That has a practical benefit. Your code does not tie you to one provider. Moving between hosts means editing a base URL, a key and a model name in config. Nothing else in your application needs to know.

A note on what you are connecting to. This service is an independent text API serving one open-weight model under the ID uncensored. It is not Meta's API and does not route across vendors. If a project requires a specific named Llama checkpoint, pick a host that lists it. Our beginner's guide to the llama ai api, covers that background in more detail.

Python: install, configure, call

Install with pip install openai, create a key on the API key page (new accounts can claim $0.50 of trial credit, valid 7 days, no card) and export it as API_KEY.

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.llamaaiapi.com/v1",
    api_key=os.environ["API_KEY"],
)

response = client.chat.completions.create(
    model="uncensored",
    messages=[
        {"role": "system", "content": "You answer in plain language and stay brief."},
        {"role": "user", "content": "What does an SDK do?"},
    ],
)
print(response.choices[0].message.content)

The system message sets behaviour for the whole conversation. Put stable instructions there, such as tone, format and role, and keep the user message for the actual question. Each token in the system message is billed as input on every call, so keep it tight.

Writing system prompts that hold

The system message is the most useful lever you have, and most beginners overload it. A few habits keep behaviour steady across a long conversation:

  • State the role and the output format in two or three sentences. "You are a support agent for a bike shop. Reply in under 80 words, no lists." beats a page of rules.
  • Put hard constraints last. Models weigh recent text strongly, so end with the rule you care about most.
  • Test with hostile input. Paste in a user message that tries to override the instructions and see what survives.
  • Keep it identical between calls if you want comparable results, and store it in one constant.

An uncensored model follows the persona and tone you set with fewer detours into refusals, which is a reason fiction, roleplay and companion apps for adults often pick this kind of endpoint. Use it for lawful adult use only. Sexual content involving minors is not allowed and cannot be enabled.

Node.js: the same thing in JavaScript

Install with npm install openai. The package supports ES modules and top-level await.

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.llamaaiapi.com/v1",
  apiKey: process.env.API_KEY,
});

const response = await client.chat.completions.create({
  model: "uncensored",
  messages: [
    { role: "system", content: "You answer in plain language and stay brief." },
    { role: "user", content: "What does an SDK do?" },
  ],
});

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

Keep the key on the server. Never put it into browser code, because anyone can read it from the page. If you need a front end, add a small API route of your own that holds the key and forwards the request.

Streaming responses

Streaming lets users see text as it appears. Both SDKs use server-sent events under the hood and give you an iterator.

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.llamaaiapi.com/v1",
  apiKey: process.env.API_KEY,
});

const stream = await client.chat.completions.create({
  model: "uncensored",
  stream: true,
  messages: [{ role: "user", content: "Write a haiku about open weights." }],
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}

Two details save debugging time. First, the final chunk carries usage, so you can log token counts. Second, a streamed request holds one of your concurrent slots until it ends: 8 on a full key, 2 on a trial key. Always read the stream to the end or abort it.

Tool calling in a few lines

Describe a function with a JSON schema, let the model decide when to call it, run it yourself, and send the result back as a tool message.

import json, os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.llamaaiapi.com/v1",
    api_key=os.environ["API_KEY"],
)

tools = [{
    "type": "function",
    "function": {
        "name": "get_time",
        "description": "Return the current time for a city",
        "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"],
        },
    },
}]

messages = [{"role": "user", "content": "What time is it in Lisbon?"}]
first = client.chat.completions.create(model="uncensored", messages=messages, tools=tools)
call = first.choices[0].message.tool_calls[0]

messages.append(first.choices[0].message)
messages.append({
    "role": "tool",
    "tool_call_id": call.id,
    "content": json.dumps({"city": "Lisbon", "time": "14:05"}),
})
final = client.chat.completions.create(model="uncensored", messages=messages, tools=tools)
print(final.choices[0].message.content)

In real code, check that tool_calls exists before indexing it, since the model may answer directly. Pass tool_choice to force a call when you need one. JSON mode, with response_format set to {"type": "json_object"}, is the simpler option when you only want structured output.

Using it from frameworks

Frameworks that wrap OpenAI accept a custom base URL, so they work here too. In LangChain for Python, use the OpenAI chat class and give it the same three values:

import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="uncensored",
    base_url="https://api.llamaaiapi.com/v1",
    api_key=os.environ["API_KEY"],
)
print(llm.invoke("Give me one tip for writing prompts.").content)

The Vercel AI SDK has an OpenAI-compatible provider that takes a base URL and key in the same way. Check each library's current documentation for exact option names, since they change between versions. The rule of thumb never changes: find where the library sets the OpenAI base URL, and put ours there.

Moving an existing OpenAI project over

If you already have working code, migration is mostly a checklist.

  1. Replace the base URL and key with ours, ideally through environment variables so the same code runs on both.
  2. Change the model string to uncensored.
  3. Remove calls to unsupported endpoints: images, audio, embeddings and fine-tuning are not available. The supported methods are POST /v1/chat/completions, POST /v1/responses and GET /v1/models.
  4. Lower any hard-coded max_tokens assumptions. The completion can use whatever remains of the 100,000-token window, and the parameter is optional.
  5. Run your tests with temperature 0 and a fixed seed, then compare outputs by hand. Different models word things differently even when both are correct.

Keep a thin wrapper function around your client calls. Then if you ever want to send some traffic to another provider, only the wrapper changes.

Limits, cost and the errors you will meet

A full key allows 8 concurrent requests and 300 per minute. A trial key allows 2 and 60. Above that you get HTTP 429 with the code rate_limited or concurrency. The OpenAI SDKs retry some failures by default, which is usually fine. A 401 means a missing or wrong key. The context window is 100,000 tokens, the maximum body is 8 MB, and the API is text only.

Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens from prepaid credit. A request with 800 tokens in and 300 out costs $0.00012 plus $0.00015, so $0.00027, and $20, the smallest top-up, covers about 74,000 of them. Top-ups run from $20 to $500 in USDT (TRC20) or USDC (Base), with bonuses from $50. See pricing and the docs for the full parameter list.

Frequently asked questions

Is there an official Llama SDK?

Hosts differ, and many simply support the OpenAI-compatible API. With ours you use the official OpenAI SDK for Python or JavaScript.

Which model name do I pass?

Pass uncensored as the model. It is the only model ID on this API.

Does it support streaming and function calling?

Yes. Use stream=true for server-sent events, and the tools and tool_choice parameters for tool calling.

Can I keep my existing OpenAI code?

Mostly yes. Change the base URL, the key and the model name, and test any feature that is not text, since there is no image, audio or embeddings support.

Get your key now

Sign up, copy the key, update the base URL. Done.