Stateless loops, tool calls and retry budgets on a keyless endpoint

An agent that plans, calls a tool, reads the result and tries again can send dozens of requests for one task, each carrying the whole conversation. Here is why that gets costly on a paid API, how to keep loops lean, and a free endpoint for debugging them.

  • Built for loop testing
  • No key to leak
  • OpenAI request format
  • Per-IP daily quota

FreeAPIDeepSeek editorial team · Updated 2026-11-16

Terminal window showing an agent loop printing a tool call, a tool result and a final reply
Each loop step is an ordinary chat request; nothing secret is sent with it.

Coding agents, research agents and automation frameworks are where API bills surprise people most. The model is the same one you chat with, but the usage pattern is not. An agent works in a loop: read the goal, decide on an action, call a tool, append the output, decide again. Every turn resends everything that came before, so token use grows faster than the number of steps, and a loop that gets stuck can spend for hours unattended.

This page explains that pattern in concrete terms, with the habits that keep agent costs predictable on DeepSeek or any per-token provider. It also introduces an independent, keyless, OpenAI-compatible API running an open-weight model called free-ai, useful for debugging loop logic, parsers and stop conditions at zero cost. free-ai is not a DeepSeek model, and a small model is not a substitute for a strong one inside a serious coding agent.

Agent loops, tool calls and free testing: questions

Why does an AI agent use so many more tokens than a chat?

Because LLM APIs are stateless. On each step the agent sends the system prompt, tool descriptions, the whole history and every tool output so far. Step ten carries everything from steps one to nine. Long tool outputs such as file contents or web pages make this worse, and retries repeat the full payload again.

Is it cheaper to run agents on DeepSeek's API than elsewhere?

DeepSeek has been known for low per-token prices, and it has also announced increases and peak-hour pricing, so the comparison moves. Your loop design usually matters more than the rate card: a lean agent on a pricier model can cost less than a bloated one on a cheap model. Check DeepSeek's current pricing page for real numbers.

How do I get a DeepSeek API key for an agent framework?

Create an account on DeepSeek's developer platform, add balance, and generate a key on the API keys page. Put it in the environment of the machine running the agent, not in a committed config file. Use a separate key per tool or project so you can see which one is spending and revoke it alone.

What is free-ai and is it related to DeepSeek?

No relation. free-ai is an independent open-weight model of about 35B parameters, fine-tuned to refuse far less than commercial assistants, with two hard rules: no sexual content involving minors and no operational instructions for mass-casualty weapons. It speaks the same OpenAI-style request format, so agent frameworks can point at it with a base URL change.

DeepSeek vs free-ai inside an agent: what changes?

A large DeepSeek model plans better, recovers from tool errors more often and handles long multi-file tasks. free-ai is suited to short loops with clear tools and simple decisions, and to testing your harness. Expect a small model to need tighter instructions, fewer tools and stricter output formats to behave reliably in a loop.

Does the free API support native tool or function calling?

Do not build on a native tools parameter here. The reliable approach is prompt-based: describe the available tools in the system message, ask the model to reply with a small JSON object naming the tool and arguments, and parse that in your code. Many agent frameworks support this mode for models without native calling.

What limits will an agent hit on the free endpoint?

Per IP: one request a second with bursts of three, two concurrent requests, and 10,000 requests or 10,000,000 tokens a day, reset at 00:00 UTC. Each call can carry 32,000 tokens of context and return up to 16,000. A fast loop sees 429 with Retry-After; a busy server answers 503.

How do I stop an agent from looping forever?

Set hard limits in your own code: a maximum number of steps, a total token budget per task, and a wall-clock timeout. Detect repetition, such as the same tool called with the same arguments twice in a row, and stop or ask a human. Never rely on the model to decide on its own that it is done.

What does the free service log about agent traffic?

One technical record per request: time, IP, User-Agent, country, endpoint, status, latency, sizes and token counts. The IP is used for rate limits. There is no session or memory between calls. Agents often paste file contents and command output into prompts, so keep secrets and credentials out of what the loop sends.

Independent service. FreeAPIDeepSeek is not affiliated with DeepSeek and gives out no DeepSeek keys or credit. The free-ai model here is not one of DeepSeek's chat, coder or reasoning models; it shares only the OpenAI-style request format.

Crossed-out key icon: no API key is needed
No key: nothing for a runaway agent to drain
Plug connector icon for OpenAI-compatible clients
OpenAI-compatible: frameworks accept a custom base URL
Browser window icon calling the API directly
Works in the browser: open CORS for web-based agents
Globe icon with letters from several languages
Many languages: tool results and replies in any
Lightning bolt over a speedometer for fast replies
Fast: 100+ tokens per second keeps loops moving

Run your first agent loop in five steps

Most agent frameworks let you set an OpenAI-compatible endpoint. These steps also work for a hand-written loop of thirty lines.

Numbered steps from one to three
The loop, the tools and the stop rules live in your code; the API only answers one step at a time.
  1. Configure the endpoint

    Set the base URL to https://api.freeapideepseek.com/v1 in your framework or client, and the model to free-ai.

  2. Give a placeholder key

    Frameworks often require a key value. Enter any short string; the server does not read it.

  3. Describe tools as JSON

    List two or three tools in the system message and ask for replies shaped like a JSON object with tool and arguments.

  4. Set hard stop rules

    Cap steps, total tokens and time per task in code, and break on repeated identical tool calls.

  5. Pace the loop

    Keep one step per second and two in flight at most, honour Retry-After on 429 and wait 2-5 seconds on 503.

How an agent loop spends tokens

Picture a coding agent fixing a failing test. Step one sends the task and tool list. The model asks to read a file, and your code appends the file to the conversation. Step two sends all of that again plus the request for a second file. Step three adds a test run log. By step eight the request may hold tens of thousands of tokens, most of it material the model has already read several times.

That is the core reason agents cost more than chat: input grows with every step, and the total is roughly the sum of a rising series rather than a flat amount per turn. Prompt caching can soften this on providers that support it, if the start of the conversation stays byte-identical. Trimming, summarising and smaller tool outputs soften it everywhere.

Tool outputs dominate

File contents, search results and command logs are usually the bulk of an agent's context. Truncate them to what the next decision needs.

Retries resend everything

A failed step that is retried pays for the whole history again. Fix the cause before letting a loop retry blindly.

Connected nodes forming an automated workflow
Each step carries all the steps before it, so input climbs fast.

Why stateless design is the real constraint

Chat completions APIs, DeepSeek's and this one alike, remember nothing between requests. What looks like memory in a chat app is the client resending the transcript. For an agent this is a design decision you must make on purpose: what to keep verbatim, what to compress, and what to drop before each call.

A good pattern is a working memory with layers. Keep the system prompt and the current goal fixed at the top, so caching can work where it exists. Keep the last few steps in full. Replace older steps with a short running summary of what was tried and learned. Store large artefacts such as files outside the prompt and send only the excerpt the model asked for.

  • Fixed prefix: system rules, tool list and goal, unchanged between calls
  • Recent window: the last few actions and results in full
  • Rolling summary: older steps condensed to a few lines
  • External store: files and logs kept outside the prompt
  • Excerpts only: send the lines the model needs, not whole files

Statelessness helps testing

Because each call is independent, you can replay any single step from a log and get comparable behaviour, which makes debugging loops much easier.

Illustration of code brackets and a developer tools panel
Decide on purpose what each call carries.

Try one agent step by hand

Describe a small task and ask free-ai which step it would take first. No key and no login; API limits apply here too.

freeapideepseek engine8 live panels

Every request, live. One real day of the free-ai API, 1 Dec, replayed second by second.

REPLAY · --:--:-- UTC · 1 Dec
  • Answers so far55,510of 55,510 on 1 Dec
  • Tokens read489Mprompts + history
  • Tokens written46.0Mmodel replies
  • Answer time3.0 smedian · p90 15.6 s
  • Speed22 tok/smedian · p90 34
  • Since 10 Nov509Kanswers · peak 61.0K
01

Live requests

one node = one real request · grouped by prompt sizeLOADING
  • prompt < 1K tokens0
  • prompt 1K–4K0
  • prompt 4K–16K0
  • prompt 16K+0
  • since you opened · 1 Dec
zoom 100% · nodes 0 · links 0 · signals 0
02

Request log

no prompt textLOADING
$ tail -f requests.log
    03

    Request lifecycle

    one sampled request · real timingLOADING
    1. request receivedok
    2. per-IP limitok
    3. safety checkpass
    4. routed to modelfree-ai
    5. generating
    6. answer returned
    04

    24 hours

    answers per hour, UTCLOADING
    5,149peak hour 03:00 UTC
    0006121824
    05

    Day by day

    answers per dayLOADING
    509,307answers since 10 Nov
    11-1012-01
    06

    Speed

    output tokens per second, streamed repliesLOADING
    median
    22 tok/s
    fastest 10%
    34+ tok/s
    needle
    sampled requests
    07

    Answer time

    full reply, all requestsLOADING
    3.0 smedian
    02 s6 s15 s30 s+
    08

    Plug in

    OpenAI-compatible · no keyLOADING
    curl https://api.freeapideepseek.com/v1/chat/completions -H "Content-Type: application/json" -d '{"model":"free-ai","messages":[{"role":"user","content":"Hi"}]}'
    • Base URLhttps://api.freeapideepseek.com/v1
    • Modelfree-ai, open-weight, about 35B
    • Keynot needed
    • Limitsper IP

    Data: the request log of the free-ai API that serves this site and the other sites of the same service, all together, for 1 Dec 2026 (UTC): successful answers only, automated bot traffic excluded. The log keeps counts, token sizes and timings; this panel shows no prompt text, no sites and no visitors. The live panels replay that day at real speed: one node or log line is one request made that day at this time of day.

    Tool use without a native tools field

    Native function calling is convenient, but it is not required for an agent. The older and very portable method is to describe tools in plain text and ask the model to answer with a JSON object such as a tool name and an arguments map, or with a final answer when it is done. Your loop parses the JSON, runs the tool and appends the result as the next message.

    This works on the free endpoint and on almost any model, which is useful when you want one harness for several providers. Keep the format small and strict, show one example in the system message, and reject anything that does not parse. A smaller model like free-ai follows such formats well when there are only a few tools and each has a clear one-line description.

    Few tools, clear names

    Three well-named tools beat fifteen vague ones, especially on a small model. Remove tools the task does not need.

    Validate every call

    Check the tool exists and the arguments have the right types before executing anything, and send a short error back if not.

    Sandbox the tools

    Shell and file tools should run with limited permissions, since any model can produce a harmful command by mistake.

    Diagram of a 429 error followed by retries
    A small JSON action is easy to parse and easy to validate.

    DeepSeek pricing changes and agent budgets

    DeepSeek's API became popular for agents partly on price. Since then it has announced price increases, introduced different rates by time of day and offered temporary discounts, and new model versions have changed how long reasoning runs. For an agent that spends millions of tokens a week, each of those changes shows up directly on the bill.

    We do not quote figures here because they shift; the current DeepSeek pricing page is the only reliable source. What you can control is exposure. Put the provider and model in configuration, track tokens per task rather than per day, and set a hard monthly limit on the balance you top up. Then a pricing notice is a decision about configuration, not a crisis.

    Track cost per task

    Sum usage across all steps of one task. A few runaway tasks usually explain most of an unexpected bill.

    Schedule what can wait

    If a provider prices off-peak hours lower, batch background agent work into those windows.

    Chat bubbles between a person and an assistant
    Group usage by task to see which loops cost the most.

    One loop step in several languages

    Each tab sends the same request to https://api.freeapideepseek.com/v1 with the model free-ai. The key is a placeholder; wrap the call in your loop with step, token and time limits.

    curl https://api.freeapideepseek.com/v1/chat/completions \
      -H "Content-Type: application/json" \
      -d '{"model":"free-ai","messages":[{"role":"user","content":"Reply with JSON naming one tool to check the weather in Paris."}]}'

    Window with a JSON response from the API including the generated text
    A response in Chat Completions format

    Debugging loops on the keyless endpoint

    Most agent bugs are not intelligence problems. They are parsing failures, tools that return too much text, stop conditions that never trigger, prompts that grow without bound, and error handling that retries forever. Finding them takes many runs, and on a paid API every one of those runs costs money, often while doing nothing useful.

    The free endpoint serves free-ai, an independent open-weight model of about 35B parameters with no key and no balance. It is tuned to refuse far less than commercial assistants, keeping two firm rules: no sexual content involving minors and no operational instructions for mass-casualty weapons. Point the harness at it while you build, run it hundreds of times, then switch the base URL to a stronger paid model when the plumbing is solid.

    • POST /v1/chat/completions for each agent step, with optional streaming
    • POST /v1/completions for raw prompt formats
    • GET /v1/models to confirm the model name in setup checks
    • GET /health as a pre-flight check before a long run
    • GET /ask?q= for one-off plain text, or &format=json
    Diagram from your app to the gateway, the GPU model and the answer
    Build the harness on the free URL, then swap in the paid one.

    Stop conditions every loop needs

    An agent without limits in code will eventually loop. The model asks to read the same file again, gets the same error and tries the same fix; or it never emits a final answer because the format drifted. On a paid key that burns money; on a free endpoint it burns your daily quota and returns 429s. Either way the fix belongs in your harness, not in the prompt.

    Set a step limit suited to the task, a total token budget, and a time limit. Detect repeats by hashing each tool call and its arguments. When a limit trips, stop and return what you have with a clear reason, or hand off to a person. Log each step so you can replay the run and see where it went wrong.

    Budget in tokens, not steps alone

    Ten steps with tiny outputs and ten steps reading large files differ hugely. A token cap catches both.

    Make done explicit

    Require a specific final-answer format and treat anything else as another step, up to the limit.

    Code editor with a JavaScript fetch call to the API
    Limits in code stop a loop the model cannot stop itself.

    Limits an agent loop should respect

    Per IP: 1 request per second with bursts of 3, no more than 2 in flight, and 10,000 requests or 10,000,000 tokens per day, reset at 00:00 UTC. Context up to 32,000 tokens per call, replies up to 16,000. On 429 sleep for Retry-After; on 503 retry after 2-5 seconds. Text only; no images, audio or embeddings.

    requests per second
    1
    parallel requests
    2
    context, tokens
    32,000
    answer, tokens
    16,000
    requests per day
    10,000
    tokens per day
    10,000,000
    Bar chart of the per-second, parallel and daily limits of the API
    The limits at a glance
    Ring gauge showing how much of the daily request allowance is left
    Daily allowance resets at 00:00 UTC
    Diagram of a 429 error followed by retries with growing waits
    Orderly retry after a 429

    Pacing agents under per-IP limits

    Agents are bursty: several fast steps, then a pause while a tool runs. The free endpoint counts per IP. You get one request each second with bursts up to three, two requests open at once, and daily ceilings of 10,000 requests or 10,000,000 tokens, reset at 00:00 UTC. Context per call is up to 32,000 tokens and output up to 16,000.

    For a single agent this is plenty, provided the loop does not fire requests back to back with no delay. Parallel sub-agents need a shared limiter so they do not exceed two concurrent calls together. On 429, read Retry-After and sleep that long. On 503, the model is busy; retry after two to five seconds with a little random jitter.

    Context is the hard wall

    With 32,000 tokens per call, history management is not optional. Summarise or drop old steps before you reach the ceiling.

    Share one limiter

    If several agents run on one machine, route their calls through a single queue so their combined rate stays within limits.

    Illustration of a document with a pen writing text
    One queue keeps several workers inside the same per-IP limits.

    Where a DeepSeek model belongs in your agent

    For real work, a large model is worth its cost inside an agent. DeepSeek's larger models plan multi-step changes, understand big codebases, recover when a tool returns an unexpected error and keep track of a long goal. A 35B model will lose the thread sooner, choose the wrong tool more often and need more steps for the same task, which can erase the savings on anything complex.

    free-ai fits loops that are short and well defined: classify an incoming message and route it, extract fields and call one API, look something up and summarise it, or run a simple checklist. It is also the right tool for harness development, CI tests of your agent code and demos where nobody should need a key.

    Mixed routing

    Let a small model handle triage and simple steps, and call the larger model only for planning or hard code edits.

    Measure success rate

    Compare tasks completed per million tokens, not price per token. A stronger model that finishes in fewer steps can be cheaper.

    Code editor with a Python script using the OpenAI client
    Small models are fine for short loops; long ones favour larger models.

    DeepSeek API vs free-ai for agent loops

    A realistic comparison for agent and tool-use workloads. For DeepSeek's current prices, models and features, check its own documentation and pricing pages.

    DeepSeek APIfree-ai on FreeAPIDeepSeekWho wins
    AccessAccount, balance and secret keyNo key or accountfree-ai for harness work
    Cost of long loopsGrows with every step, billed per tokenFree within daily quotafree-ai on price
    Planning and recoveryLarge models, stronger on long tasksFine for short, clear loopsDeepSeek
    Tool callingSee DeepSeek docs for native supportPrompt-based JSON actionsDeepSeek
    ThroughputHigher limits on a paid platformPer-IP limits, 2 concurrentDeepSeek
    Key exposure riskKey can leak via files or logsNo key to leakfree-ai
    RefusalsProvider policiesRefuses far less, two hard rulesDepends on the task
    Support and SLACommercial platform and termsNoneDeepSeek
    Chart comparing a free service with paid plans
    Debug and test the loop for free; run serious agent work on a model that can carry it.

    Coding assistants and editor plugins

    Editor extensions and terminal coding tools are agents too, and most let you bring your own key and set a custom OpenAI-compatible endpoint. That is how people wire DeepSeek into them, and it is also how you can point them at this endpoint to check that the integration works before spending anything. Expect simple completions and explanations to work, and complex multi-file edits to be beyond a small model.

    If a plugin shows a cost tracker, watch it for the first few sessions with a paid key. Background indexing, automatic context gathering and retries can send far more than you typed. For writing client code against this API, copy prompt.txt with the button on this page and hand it to your assistant; it describes the endpoint so the generated code is correct.

    Check what gets sent

    Some tools attach open files, terminal output or whole folders to each request. Turn off what you do not need.

    Use llms.txt

    The site also publishes llms.txt, a short machine-readable description that assistants and agents can read directly.

    Window with a JSON response from the API
    Most coding tools accept a custom base URL and model name.

    Aggregators, resold keys and agent safety

    Agent users are a prime audience for offers of unified keys, cheap aggregator access and shared DeepSeek keys. Some aggregators are legitimate routers with their own contracts, so read their terms and logging policy. But a key sold by a stranger, or one shared in a thread, is almost always someone else's credential, and an agent will spend it fast until it is revoked.

    Agents also raise the stakes for your own key. A loop that reads files can read a config file containing the key and paste it into a prompt, a log or a commit. Keep keys in the environment of the process that makes API calls, keep them out of directories the agent can read, and rotate any key that appears in output.

    Unexplained usage

    Spending on days your agent did not run points to an exposed key. Revoke it, create a new one and search your repositories and logs.

    No key in the loop

    With a keyless endpoint there is no credential for an agent to leak; the worst case is your own IP reaching its daily quota.

    Text tokens arriving one by one as the model writes
    Keep keys where the agent's file tools cannot reach them.

    What an agent's requests leave behind

    Each request leaves a technical log record with the time, IP address, User-Agent, country, endpoint, status code, latency, request and response sizes, and token counts. The IP address drives the rate limiter. There are no accounts, so nothing links a request to a name unless the prompt contains it.

    The API is stateless, so every step of a loop sends its own context and nothing is kept for the next call. Agents tend to paste file contents, environment details and command output into prompts automatically; review what your harness sends, filter out keys, tokens and personal data, and use a provider with written data terms for confidential code.

    Shield icon for good practice with a public service
    Good practice with a public service

    Guides and answers for Free API DeepSeek

    Articles →