How to use an LLM API

To use an LLM API, you send a request with your messages (what the user said, plus optional instructions) and settings like temperature and max_tokens, and the API sends back the model's answer. The API remembers nothing between calls, so for a conversation you send the earlier messages again each time. Our AI Chat Answer API works this way and costs $0.01 per answer.

Try it free AI Chat Answer API — one answer from a large open model · $0.01 / call

The parts of a request

Reading the answer

Our API returns answer (the text), model (gpt-oss-120b) and finish_reason. If finish_reason is "length", the answer was cut off at max_tokens; raise the limit or ask for something shorter.

A conversation in JavaScript

Keep the history in an array, add each new message, and send the whole list. payFetch stands for your x402 v2 client, which pays $0.01 in USDC on Base per answer.

const URL = "https://iamai.markets/api/x402/services/3zGQQ2mdFxk1";
const history = [];

async function ask(text) {
  history.push({ role: "user", content: text });
  const r = await payFetch(URL, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      system: "You are a patient cooking teacher.",
      messages: history.slice(-20), // the API takes up to 20 messages
      temperature: 0.5,
    }),
  });
  const { result } = await r.json();
  history.push({ role: "assistant", content: result.answer });
  return result.answer;
}

console.log(await ask("How do I make rice less sticky?"));
console.log(await ask("And for sushi?")); // the model sees the first question too

Habits that save money and trouble

  1. Put rules in system, not in every user message.
  2. Trim old history: our API takes 20 messages and 12,000 characters in total.
  3. Ask for a format ("three bullet points", "JSON with keys title and tags") and check it in code.
  4. Never trust the output blindly for facts, numbers or legal points; check them.
  5. Keep secrets and personal data out of prompts unless you must send them.

Try before you write code

The listing page (/l/3zGQQ2mdFxk1) lets people ask 5 questions a day free. Use it to tune your system prompt and temperature, then copy the settings into your code. Note the limits: one model, no streaming, no tool calling, and the request format is not OpenAI's.

The product

Questions

Does the API remember earlier chats?

No. Each call is separate; send the earlier messages in messages to continue a conversation.

What is a good temperature?

Start at 0.3 for factual or code answers and around 0.8 for brainstorming, then adjust by reading the results.

Do I need an API key?

No. Each answer is paid with x402 in USDC on Base, so there is no key to create or store.

Related

Updated 2026-12-01