EN ▾
llmwebsearchapi.com
llmwebsearchapi.com›Guide
Get API key

Make Your First LLM API Call in Python and curl

Here is how to do llm api call in practice: one POST request with a key, a model name and a list of messages, and the reply comes back as JSON. This page walks through curl, Python, streaming, cost and the errors you will meet first.

Isometric illustration of a terminal sending data packets to a cube that returns speech bubbles

The call in five steps

If you want to know how to do llm api call without reading a manual, this is the whole procedure. Every request to a chat-style language model follows the same five steps, whichever client you use.

  1. Get an API key from the key page. New accounts can claim a small trial balance there with one click.
  2. Pick the endpoint: https://api.llmwebsearchapi.com/v1/chat/completions.
  3. Send the key in the header Authorization: Bearer YOUR_API_KEY.
  4. Send a JSON body with model set to uncensored and a messages list.
  5. Read choices[0].message.content from the JSON that comes back.

That is all there is to it. Everything else on this page is detail around those five steps: what the message list should contain, how to see what the call cost, and what to do when the server answers with an error instead of text.

Your first request with curl

curl is the quickest way to prove that your key and network path work, because there is no library in between. Save your key in an environment variable first so it does not end up in your shell history as part of a long command.

export API_KEY="YOUR_API_KEY"

curl https://api.llmwebsearchapi.com/v1/chat/completions   -H "Authorization: Bearer $API_KEY"   -H "Content-Type: application/json"   -d '{
    "model": "uncensored",
    "messages": [
      {"role": "system", "content": "You answer in two short sentences."},
      {"role": "user", "content": "What is a token in a language model?"}
    ],
    "temperature": 0.7
  }'

The body has three parts that matter. model names what should answer you; on this service there is one model, so the value is always uncensored. messages is the conversation so far. temperature controls how adventurous the wording is, from near 0 for repeatable output up to about 1 for more variety.

You can also check that the key is accepted without generating anything: send a GET request to /v1/models with the same Authorization header. If the list contains uncensored, authentication works and any later failure is about the request body, not the key.

The same call in Python

You do not need a special client. The official openai package works if you point it at a different base URL. Install it with pip install openai.

from openai import OpenAI

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

resp = client.chat.completions.create(
    model="uncensored",
    messages=[
        {"role": "system", "content": "You answer in two short sentences."},
        {"role": "user", "content": "What is a token in a language model?"},
    ],
    temperature=0.7,
)

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

Two things are worth copying into your own code. First, keep the key out of the source file; read it from an environment variable with os.environ["API_KEY"] once you move past experiments. Second, print resp.usage while you are learning. Seeing the token counts next to the text is the fastest way to build a feel for what a call costs.

Because the interface follows the OpenAI format, the same shape works from Node, Go, Ruby or plain fetch. Only the syntax around the POST changes. The quickstart in the docs lists the supported parameters.

Reading the response

The reply is a JSON object. You will touch four parts of it most often:

  • choices[0].message.content is the generated text.
  • choices[0].finish_reason says why generation stopped. stop means the model finished; length means it hit a token limit and the text may be cut off.
  • usage holds prompt_tokens, completion_tokens and the total. This is what billing is based on.
  • The response headers include X-Request-Id and X-Balance-USD. Log the request ID with every call. If you ever contact support, that ID lets them find your exact request.

The context window is 100,000 tokens, counting the prompt and the completion together. A normal chat turn uses a tiny part of that. You only start to feel the limit when you paste whole documents or send a very long history. max_tokens is optional; if you leave it out, the completion can use whatever room is left in the window.

Messages, memory and streaming

The API does not remember you

This surprises people who have only used a chat website. Each call stands alone. If the user asks a follow-up question, you must send the earlier turns again: the system message, the first question, the model's first answer, then the new question. Your code keeps the list and appends to it.

from openai import OpenAI

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

history = [{"role": "system", "content": "You are a concise assistant."}]

def ask(text):
    history.append({"role": "user", "content": text})
    r = client.chat.completions.create(model="uncensored", messages=history)
    answer = r.choices[0].message.content
    history.append({"role": "assistant", "content": answer})
    return answer

print(ask("Name one use for a text API."))
print(ask("Give a second one."))

Remember that a longer history means more input tokens on every later call. For long sessions, trim or summarise the oldest turns.

Streaming for a responsive interface

Set stream to true and the server sends the text in pieces over server-sent events, so a chat window can show words as they arrive. Usage figures arrive at the end of the stream.

from openai import OpenAI

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

stream = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Explain HTTP in three sentences."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

One practical point: a streaming request holds one of your concurrency slots until the stream ends, so an abandoned connection keeps a slot busy for a while.

What one call costs

Pricing is per token and pay as you go: $0.15 per 1M input tokens and $0.50 per 1M output tokens, taken from prepaid credit. There is no subscription, and failed or refused requests are not charged. Credit does not expire.

Take the small call from earlier and say it used 1,200 input tokens and 400 output tokens:

  • Input: 1,200 / 1,000,000 x $0.15 = $0.00018
  • Output: 400 / 1,000,000 x $0.50 = $0.00020
  • Total: $0.00038

The $0.50 trial balance would cover roughly 1,300 calls of that size, since $0.50 divided by $0.00038 is about 1,316. The trial is valid for 7 days and needs no card. When you move on, top-ups run from $20 to $500 in whole amounts, with a bonus of 5% from $50, 10% from $100 and 15% from $200. The pricing page has the current details and accepted payment methods.

Output tokens cost more than input tokens, so the cheapest habit is to ask for short answers when short answers are enough. A system message such as "answer in two sentences" cuts the bill and the waiting time together.

Errors and limits you will meet first

Most early failures fall into a few groups.

SymptomUsual causeFix
Authentication error (typically HTTP 401)Missing or wrong key, or the word Bearer left outCheck the header, and that the key has no trailing space
Request rejected as malformed (typically HTTP 400)Invalid JSON, or messages missingValidate the JSON; in curl, mind the quote marks around -d
HTTP 429, code rate_limitedMore than 300 requests per minute on a full key, or 60 on a trial keySlow down and retry
HTTP 429, code concurrencyMore than 8 requests at once on a full key, or 2 on a trial keyQueue requests in your code
HTTP 429 with Retry-After: 5Temporary overloadWait the stated 5 seconds and try again

Retrying is easy to add. This version waits a little longer after each failed attempt:

import time
from openai import OpenAI, RateLimitError

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

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

The request body can be up to 8 MB, which is far more than any prompt that fits in the context window.

A note for a search-flavoured site

This site's pages talk about web search, so one clarification is useful: the endpoint described here is a text model. It does not browse the internet by itself, and it has no access to pages you have not given it. If your product needs fresh web results, fetch them in your own code and place the relevant snippets in the user message, or expose your search function as a tool through tool calling and let the model ask for it.

Either way, the shape of the call stays the same as in the examples above. You send messages, you get text back, and you pay for the tokens in both directions. When you are ready, create a key and run the curl command from the top of this page.

Questions and answers

Do I need the OpenAI library to call this API?

No. Any HTTP client works because it is a normal JSON POST. The OpenAI SDKs are convenient, and they only need a different base URL and key.

Why does my follow-up question get an answer with no context?

The API keeps no memory between calls. Send the earlier messages again in the messages array each time.

How do I see how many tokens a call used?

Read the usage field in the response. It lists prompt tokens and completion tokens, which are the two numbers the price is based on.

What should I do after an HTTP 429?

Wait and retry. If a Retry-After header is present, wait that long; otherwise back off for a few seconds and reduce how many requests you send at once.

Your key is one form away

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