EN ▾
Get API key

NSFW WriterLLM Frameworks Like LangChain vs Calling the API

LLM Frameworks Like LangChain vs Calling the API

LLM frameworks like LangChain, LlamaIndex and Haystack save time on retrieval and agent plumbing, and they add layers you must learn and debug. For many apps, a direct call to an OpenAI-compatible endpoint is shorter, cheaper to maintain and easier to read.

Updated

Key points

  • A framework earns its place when you need retrieval, multi-step agents, tracing or swappable providers.
  • For chat, drafting and single-shot tools, the plain OpenAI SDK with a changed base URL is usually enough.
  • Frameworks and this API are not rivals: LangChain's OpenAI chat class can point at the base URL with model uncensored.
  • This API is text only, with no embeddings, so retrieval pipelines need an embedding source elsewhere.
Illustration comparing a direct line to a model core with a longer chain of linked framework blocks

Short answer: framework or direct calls

If you are weighing llm frameworks like langchain against writing the HTTP calls yourself, start from the shape of your app. A chat feature, a story generator, a character bot, a batch job that rewrites text: these are one request in, one answer out, maybe with a loop. A direct SDK call handles all of them in a few dozen lines, and you can read every line.

A framework starts to pay off when your app has many moving parts: document retrieval, several tools, memory stores, branches that depend on earlier results, or a team that wants a shared vocabulary. Even then, the model endpoint is a separate decision. You can run a framework on top of this API, because it speaks the OpenAI format. The sections below show where each approach wins.

What the main options do

The names overlap, so a quick map helps. Descriptions below stick to what each project says about itself; check their current documentation for details and versions.

OptionMain ideaTypical use
LangChainBuilding blocks for prompts, models, tools and chains, with LangGraph for stateful agents and LangSmith for tracingAgents, tool use, apps that mix many services
LlamaIndexData ingestion and retrieval over your documentsQuestion answering over files and databases
HaystackPipelines of components for search and generationSearch-heavy applications
DSPyPrograms with prompts that are tuned from examplesPipelines you want to optimise against a metric
Plain OpenAI SDKA thin client over the chat completions endpointChat, drafting, single-purpose tools

Most of these frameworks wrap a model behind their own interface. The wrapper for OpenAI-style endpoints accepts a base URL, which is the hook that lets a framework talk to any compatible provider.

What a framework gives you

The honest list is longer than critics admit.

  • Retrieval parts. Document loaders, chunking, vector store connectors and rerankers exist already. Writing them yourself takes days.
  • Agent loops. Deciding which tool to call next, passing results back and stopping at the right moment is fiddly. Graph-style agent libraries give you state, retries and checkpoints.
  • Tracing and evaluation. Seeing each step of a multi-call run, with inputs and outputs, saves hours when an answer goes wrong.
  • Provider swapping. If you want to compare two models, one interface lets you change a string instead of rewriting a client.
  • Community examples. A problem you hit has probably been solved in a public repository.

If three or more of those apply to you, a framework is a reasonable choice and the setup time will come back to you.

A concrete case: a companion app that stores character sheets, recalls earlier scenes from a database, calls a dice or inventory tool and writes the reply. That is retrieval, tools and memory in one request path, and writing all of it by hand means owning a lot of glue code. A smaller case: a button that turns a premise into a 500-word scene. There the framework adds a dependency and nothing else.

What it costs you

The costs are real too, and they are mostly in your head and your debugger rather than on the bill.

Layers between you and the request

When a reply looks wrong, you want to see the exact JSON that went to the model. Inside a framework that JSON is assembled from templates, message classes and callbacks, and you may need tracing or a debug flag to see it. With the plain SDK it is the dictionary in front of you.

API churn

Frameworks in this space have changed their module layout and class names several times, so code from a two-year-old tutorial often fails on a fresh install. Pin versions and read the changelog before you upgrade. A direct call to /v1/chat/completions has barely moved.

Hidden tokens

Prompt templates, memory classes and agent scaffolding add text to every request. You pay for that text as input at $0.15 per 1M tokens. Suppose a scaffold adds 600 tokens to a request and your app makes 100,000 requests in a month: that is 60,000,000 extra input tokens, and 60 × $0.15 = $9.00. Small at this price, but it is also invisible unless you log usage. With output at $0.50 per 1M, an agent that loops five times to finish a job can cost five times as much as one clean call.

Content behaviour

Some framework agents and prompt templates include safety wording of their own. If you run adult fiction through a model that is tuned to answer without refusals, a template that tells the model to decline sensitive topics will undo that tuning. Read the default prompts before you trust them.

Using this API with LangChain

The two are compatible. The OpenAI chat class in LangChain's Python package takes a model name, a key and a base URL, so pointing it at this API is a small change. Check the current package documentation for argument names, as they have shifted between versions.

from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate

llm = ChatOpenAI(
    model="uncensored",
    base_url="https://api.nsfwwriter.com/v1",
    api_key="YOUR_API_KEY",
    temperature=0.8,
)

prompt = ChatPromptTemplate.from_messages([
    ("system", "You write fiction for lawful adult readers. Match the requested tone."),
    ("human", "Write a short scene: {premise}"),
])

chain = prompt | llm
print(chain.invoke({"premise": "two rivals share a lift during a power cut"}).content)

The same call in the plain SDK is shorter and shows exactly what is sent:

from openai import OpenAI

client = OpenAI(base_url="https://api.nsfwwriter.com/v1", api_key="YOUR_API_KEY")

resp = client.chat.completions.create(
    model="uncensored",
    messages=[
        {"role": "system", "content": "You write fiction for lawful adult readers. Match the requested tone."},
        {"role": "user", "content": "Write a short scene: two rivals share a lift during a power cut"},
    ],
    temperature=0.8,
)
print(resp.choices[0].message.content)

Both produce the same request. The framework version earns its keep once the prompt grows variables, branches and tools. Streaming, tool calling and JSON mode pass through the OpenAI interface in either case, so framework features built on those work without changes.

The key limits apply per key whatever client you use: 8 concurrent requests and 300 per minute on a full key, 2 and 60 on a trial key. An agent that fans out many parallel tool calls can hit a concurrency 429 quickly, so set the maximum concurrency of your framework's runner to your limit.

Where the framework approach has a gap here

This API offers text generation through chat completions and a model list. It does not offer image, audio or video generation, embeddings or fine-tuning. That matters for the most popular framework use case, retrieval over your documents, because the retrieval step needs an embedding model. You would get embeddings from another source, such as a local open model, and send only the retrieved passages here for the answer.

It also means an agent framework cannot call an image tool through this endpoint. If you write prompts for an image tool, the image prompt guide shows how the text layer fits next to a separate image service.

How to choose

Walk through these questions in order. Stop at the first answer that settles it.

  1. Is it one prompt in and one answer out, with at most a loop or two? Use the plain SDK.
  2. Do you need retrieval over many documents? Consider LlamaIndex or LangChain for the data part, and arrange embeddings separately.
  3. Do you need a multi-step agent with state and retries? A graph-style framework saves real work.
  4. Do you need to compare several providers in one codebase? A framework interface helps, though a thin wrapper of your own around the OpenAI SDK also works.
  5. Will other developers join the project? A well-known framework gives them a shared starting point, at the price of its conventions.

A practical path is to start direct. Build the core prompt and the parsing with the OpenAI SDK, measure tokens per request, and add a framework only when a concrete need appears. Moving from a thin client to a framework is easier than the reverse, because your prompts and data formats stay the same.

When you are ready to try the endpoint, claim a trial key and run one of the snippets above. The documentation covers parameters, and the pricing page shows top-ups paid in crypto from $20.

Questions and answers

Can I use LangChain with this API?

Yes. The API is OpenAI-compatible, so LangChain's OpenAI chat class works with the base URL https://api.nsfwwriter.com/v1, your key and the model ID uncensored.

Do I need a framework to use tool calling?

No. Tool calling works through the normal tools and tool_choice parameters, and tool results go back as messages with role tool. A framework only organises the loop for you.

Is the API a router across several model vendors?

No. It serves one open-weight model, run by an independent provider. It is not the official API of any other vendor.

Can I build retrieval over my documents?

You can, but embeddings are not offered here. Create the embeddings elsewhere and send the retrieved text to this API for the final answer.

Which is cheaper, a framework or direct calls?

The per-token price is identical, $0.15 per 1M input and $0.50 per 1M output. Frameworks can raise the bill indirectly through extra prompt text and repeated agent steps, so log usage.

Your key is one form away

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

Get API keyRead the docs

Get API keynsfwwriter.comuncensoreden