EN ▾
Get API key

How to Use an LLM Model Through an API, Step by Step

Using a hosted language model comes down to one HTTP call with a key, a model name and a list of messages. This walkthrough takes you from an empty folder to streaming, JSON output and tool calls.

Updated

Terminal connected to a cube of chat bubbles with data streaming between them, representing an LLM API call
01

Key points

  • The API is OpenAI-compatible: change the base URL and key, keep your SDK.
  • Use the model ID uncensored with POST /v1/chat/completions.
  • Streaming, JSON mode and tool calling all work with the standard parameters.
  • A 429 means a limit was hit, and the error code tells you which one.

What you need before the first request

If you want to know how to use LLM model endpoints in your own code, three things are enough: a key, a base URL and a model name. There is no special client to install. Any OpenAI SDK or client works once you point it at a different address.

  • Base URL: https://api.llmmodelsapi.com/v1
  • Model ID: uncensored
  • Auth: an Authorization: Bearer YOUR_KEY header, which the SDKs add for you

To get a key, sign up with Google or with email and password, then open the API key page. New accounts can claim $0.50 of trial credit there with one click, no card, valid for 7 days. That is plenty for everything in this article. The endpoint supports two methods: POST /v1/chat/completions for generation and GET /v1/models to list what is available.

It helps to know what the model is, so your expectations are right. It 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 any big vendor, and it handles text only. There is no image or audio generation, no embeddings and no fine-tuning.

Step 1: check the key with curl

Before writing any application code, confirm the key and the network path work. Listing the models is the cheapest check, because it generates nothing.

export LLM_KEY="paste-your-key-here"

# the list should include the model id: uncensored

curl https://api.llmmodelsapi.com/v1/models   -H "Authorization: Bearer $LLM_KEY"

You should get a JSON list that includes uncensored. If you see a 401, the key is wrong or missing the word Bearer. Now send a real chat request.

curl https://api.llmmodelsapi.com/v1/chat/completions   -H "Authorization: Bearer $LLM_KEY"   -H "Content-Type: application/json"   -d '{
    "model": "uncensored",
    "messages": [
      {"role": "system", "content": "You are a concise assistant."},
      {"role": "user", "content": "Explain what a context window is in two sentences."}
    ],
    "max_tokens": 150
  }'

The reply contains a choices array, and the text sits at choices[0].message.content. The response headers carry X-Request-Id and X-Balance-USD, so you can see your remaining credit on every call. The usage field shows the tokens counted for billing.

Step 2: call it from Python or Node

In practice you will use an SDK. Install the official OpenAI package, then set the base URL when you create the client. Nothing else about your code changes.

Python

from openai import OpenAI

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

resp = client.chat.completions.create(
    model="uncensored",
    messages=[
        {"role": "system", "content": "You answer in plain language."},
        {"role": "user", "content": "Give me three names for a fantasy tavern."},
    ],
    temperature=0.9,
    max_tokens=200,
)

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

Node

import OpenAI from "openai";

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

const resp = await client.chat.completions.create({
  model: "uncensored",
  messages: [{ role: "user", content: "Summarise HTTP caching in one paragraph." }],
});

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

Keep the key in an environment variable rather than in the source file. If a key leaks, replace it on the key page and the old one stops working.

Step 3: shape the output with parameters

The model is a text predictor, so how you phrase the request matters as much as the parameters. A few habits pay off immediately.

  • Use the system message for standing rules. Put tone, format and role there, and keep the user message for the actual task.
  • Be specific about length. Ask for "three bullet points" or "under 120 words". It is more reliable than only lowering max_tokens, which cuts text off mid-sentence.
  • Tune temperature to the job. Around 0.2 suits extraction and classification. Around 0.8 to 1.0 suits fiction and roleplay.
  • Pass what you need. top_p, stop, seed and the frequency and presence penalties are passed through to the model.

The context window is 100,000 tokens, counting the prompt and the completion together. You do not have to set max_tokens, because the answer can use whatever room is left. Setting it anyway is a good way to put a ceiling on cost.

A practical way to learn these settings is to run the same prompt three times at different temperatures and compare. Change one value per run and keep the rest fixed, using the same seed where you can. After ten minutes of this you will know how the model behaves for your task far better than any description could tell you, and the cost of the experiment is a fraction of a cent.

Pricing is $0.15 per million input tokens and $0.50 per million output tokens. A request with 1,500 input tokens and 400 output tokens costs 1,500 x 0.15 / 1,000,000 = $0.000225 plus 400 x 0.50 / 1,000,000 = $0.0002, so $0.000425 in all. The pricing page has the top-up options.

Step 4: stream the response

Waiting for a full answer feels slow in an interactive app. With stream: true the server sends tokens as server-sent events, and your UI can print them as they arrive. Usage is reported at the end of the stream.

from openai import OpenAI

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

stream = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Write a short story opening about a lighthouse."}],
    stream=True,
    stream_options={"include_usage": True},
)

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

One thing to remember about concurrency: a streamed request occupies its slot until the stream finishes. A full key allows 8 concurrent requests, a trial key allows 2. If you open a stream in the browser and never close it, that slot stays busy.

Step 5: JSON mode and tool calling

When another program has to read the answer, free text becomes a problem. JSON mode asks the model to return a valid JSON object.

import json
from openai import OpenAI

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

resp = client.chat.completions.create(
    model="uncensored",
    response_format={"type": "json_object"},
    messages=[
        {"role": "system", "content": "Reply with JSON only: {\"title\": string, \"tags\": [string]}"},
        {"role": "user", "content": "Describe a post about growing tomatoes on a balcony."},
    ],
)

data = json.loads(resp.choices[0].message.content)
print(data["title"], data["tags"])

Describe the shape you want in the prompt too, since JSON mode guarantees valid syntax and not your exact field names. Wrap the parse in a try block and retry once if it fails.

Tool calling lets the model ask your code to run a function. You describe the tools, the model replies with a tool_calls entry, you run it and send the result back as a message with role: "tool".

import json
from openai import OpenAI

client = OpenAI(base_url="https://api.llmmodelsapi.com/v1", api_key="YOUR_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({"time": "14:05"}),
})

final = client.chat.completions.create(model="uncensored", messages=messages, tools=tools)
print(final.choices[0].message.content)

In production, check that tool_calls is present before indexing into it, because the model may answer directly instead of calling the function. The tool_choice parameter lets you force or forbid a call when you need that.

Keeping a conversation going

The API has no memory between calls. If you want the model to remember what was said two turns ago, you send those turns again. A chat app is therefore a list that grows: you append the user message, call the API, append the assistant reply, and repeat.

from openai import OpenAI

client = OpenAI(base_url="https://api.llmmodelsapi.com/v1", api_key="YOUR_KEY")
history = [{"role": "system", "content": "You are a friendly writing coach."}]

def say(text):
    history.append({"role": "user", "content": text})
    resp = client.chat.completions.create(model="uncensored", messages=history, max_tokens=300)
    reply = resp.choices[0].message.content
    history.append({"role": "assistant", "content": reply})
    return reply

print(say("Give me a tip for opening a short story."))
print(say("Now apply it to a story about a night train."))

Because every call carries the whole list, cost and latency grow with the conversation. Once the history gets long, drop the oldest turns or replace them with a one-paragraph summary. You have a lot of room, since 100,000 tokens is roughly the length of a short novel, but there is no reason to pay for tokens that no longer help the answer.

For the same reason, keep the system message short and stable. It is sent on every call, so a 1,000 token system prompt over 500 requests is 500,000 input tokens, which costs 500,000 x 0.15 / 1,000,000 = $0.075 on its own.

Mistakes beginners make

  • Forgetting to append the assistant reply. The model then sees only your questions and loses the thread.
  • Putting secrets in the front end. A key inside browser code is visible to everyone. Call the API from your server and expose your own endpoint instead.
  • Expecting facts from a text predictor. The model can state wrong details with confidence. Give it the source text in the prompt when accuracy matters, and check important output.
  • Parsing free text. If code has to read the answer, use JSON mode or a tool call instead of regular expressions.

Errors, limits and where to go next

Most problems fall into a short list.

SymptomLikely causeFix
401 responseMissing or wrong keyCheck the Bearer header and the key on the key page
429, code rate_limitedOver 300 requests per minute (60 on a trial key)Slow down or queue requests
429, code concurrencyOver 8 requests at once (2 on a trial key)Limit parallel workers, close open streams
429 with Retry-After: 5Temporary overloadWait 5 seconds and retry
Request too largeBody over 8 MBSend less text per call

A simple retry with a short delay handles the 429 cases. Failed requests are not charged, so retrying costs nothing extra. Prompts are not used for training.

From here, the API documentation lists every parameter, and the pay-per-token overview covers who the service is for. One rule applies everywhere: sexual content involving minors is never allowed.

02

Questions and answers

Which model ID do I send in the request?

Use uncensored as the model value in every request. You can confirm it by calling GET /v1/models.

Do I need a special SDK?

No. Any OpenAI SDK or client works once you change the base URL to https://api.llmmodelsapi.com/v1 and use your own key.

Can I use it without a credit card?

Yes, for testing. New users can claim $0.50 of trial credit with one click after sign-up, with no card, valid for 7 days.

How large can my prompt be?

The context window is 100,000 tokens for prompt and completion together, and the request body can be up to 8 MB.

Your key is one form away

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

Get API key