EN ▾
Get API key

100K Context Window: What Fits and What It Costs

People who ask about the qwen coder context window usually want to know one thing: how much code or text can go into a single request. On this API the answer is 100,000 tokens, shared between your prompt and the reply.

Updated

Isometric glass gauge filled with stacked glowing blocks representing a token window

Key points

  • The window is 100,000 tokens, and prompt plus completion must fit inside it.
  • max_tokens is optional; the completion can use whatever the prompt leaves free.
  • A prompt that fills the whole window costs about $0.015 in input tokens.
  • Chat apps resend history every turn, so trim or summarise old messages.

The number, and what it covers

The window is 100,000 tokens. That figure counts everything in one request: the system message, every earlier turn you send back, the new question, tool definitions, tool results, and the answer the model writes. If your prompt takes 80,000 tokens, the reply has at most 20,000 tokens of room. You do not have to set max_tokens, because the completion may use the rest of the window by default. Set it only when you want a hard cap on output cost or length.

This is the context window you get on this hosted API for the uncensored model. It is not a statement about any model sold under another vendor's name, and the numbers on other services change often, so check their current documentation before comparing. What matters for your project is whether 100,000 tokens fits your typical job, and the next section gives a way to measure that.

How much text is 100,000 tokens?

A token is a chunk of text, often a short word or part of a longer one. For ordinary English prose, a common rule of thumb is that one token is about four characters, or three quarters of a word. By that rule, 100,000 tokens is roughly 75,000 words, which is the length of a full-size novel. Treat that as an estimate. Other languages, and source code in particular, often split into more tokens per character, so the same character count can use a larger share of the window.

ContentRough token useFits several times in 100K?
A 300-line source file3,000 to 5,000Yes, many files
A 20-page report10,000 to 14,000Yes, several reports
A long chat with 50 turns20,000 to 40,000Usually once, with room left
A whole small repositoryVaries widelyCount it first

The table is a planning aid, not a measurement. The only reliable number is the one you get from your own data, so count real prompts before you design around the limit.

Count tokens before you send

You can estimate locally and then confirm with the API. For a quick local guard, divide the character count by four and keep a safety margin of 10 to 15 percent. For an exact figure after the fact, read the usage block in the response. In a non-streamed call it comes back with the result, and in a streamed call it arrives at the end of the stream.

import os
from openai import OpenAI

client = OpenAI(base_url="https://api.qwencoder.cc/v1", api_key=os.environ["API_KEY"])

def rough_tokens(text: str) -> int:
    return len(text) // 4 + 1

with open("big_module.py", encoding="utf-8") as f:
    source = f.read()

print("estimated prompt tokens:", rough_tokens(source))

resp = client.chat.completions.create(
    model="uncensored",
    messages=[
        {"role": "system", "content": "You review code. Reply with a short list of problems."},
        {"role": "user", "content": source},
    ],
)
print(resp.usage.prompt_tokens, resp.usage.completion_tokens)

Run this on a few typical inputs and write down the gap between the estimate and the real prompt token count. If your estimate runs 20 percent low on your kind of content, raise your safety margin to match. The request body also has a limit of 8 MB, which is far above what 100,000 tokens needs, so the token window is the limit you will meet first.

What a long prompt costs

Input tokens cost $0.15 per 1M and output tokens cost $0.50 per 1M. Long context is not a premium tier here; you pay the same rates for token number 90,000 as for token number 9.

  • A prompt of exactly 100,000 tokens with no reply room: 0.1 million tokens times $0.15 is $0.015.
  • A 90,000-token prompt with a 10,000-token answer: input 0.09 times $0.15 is $0.0135, output 0.01 times $0.50 is $0.005, for a total of $0.0185.
  • A 20-turn chat with a 2,000-token system prompt, where each turn adds 300 tokens from you and 700 from the model.

Work through that third case, because it shows why history matters. Turn k sends 2,000 plus 1,000 for every earlier turn plus 300 for the new message. Across 20 turns the input adds up to 20 times 2,300, which is 46,000, plus 1,000 times the sum of 0 through 19, which is 190,000. That makes 236,000 input tokens. Output is 20 times 700, or 14,000 tokens. Cost: 0.236 times $0.15 is $0.0354, plus 0.014 times $0.50 which is $0.007, for $0.0424 in total.

The conversation itself only holds about 22,000 tokens by the end, yet you paid for 236,000 input tokens because every turn resends everything. That is how chat APIs work, and it is the reason trimming is worth the effort. Failed or refused requests are not charged, so a request that errors out costs nothing. See the pricing page for the rate card and the top-up options.

Keep long conversations under the limit

A chat that runs for hours will eventually reach the ceiling. You have three practical options, and they combine well.

  1. Drop the oldest turns. Keep the system message and the most recent messages that fit a budget you choose.
  2. Summarise. Ask the model to condense the older half of the conversation into a short note, then replace those messages with the note.
  3. Pin what must survive. Rules, character sheets and project facts belong in the system message, which you never drop.

Here is a simple trimming function for option one:

import os
from openai import OpenAI

client = OpenAI(base_url="https://api.qwencoder.cc/v1", api_key=os.environ["API_KEY"])

BUDGET = 70_000  # leave room for the reply inside 100,000

def est(msg):
    return len(msg["content"]) // 4 + 4

def trim(messages):
    system, rest = messages[0], messages[1:]
    used = est(system)
    kept = []
    for m in reversed(rest):
        cost = est(m)
        if used + cost > BUDGET:
            break
        kept.append(m)
        used += cost
    return [system] + list(reversed(kept))

history = [{"role": "system", "content": "You are a patient pair programmer."}]

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

Keeping the budget at 70,000 rather than 100,000 leaves about 30,000 tokens for the reply and absorbs estimation error. Tune it to the longest answer you expect.

Habits that make long prompts work better

A big window lets you paste a lot, but pasting a lot is not the same as being understood. A few habits help with any model, and you should verify each on your own material, since this page makes no benchmark claims.

  • Put the instruction near the end as well as the start. A one-line reminder after a long document keeps the task in view.
  • Label sections. Wrap files or chapters in clear headers such as a file path, so the model can point back to them.
  • Send only what is relevant. Shorter prompts are cheaper, and they leave more room for the answer.
  • Ask for quotes or line references when accuracy matters, then check them against your source.
  • Test recall on your own data. Hide a known fact deep inside a long input and see whether the model finds it.

The docs quickstart lists the request parameters you can pass, including temperature and seed, which are useful for making a long-context test repeatable.

When 100K is not enough

Some jobs outgrow a single window: a full monorepo, a year of chat logs, a book series. Do not try to force them in. Split the input into chunks that each fit, run the same instruction on every chunk, and merge the partial results in a final call. For code, send the files that touch the change plus the interfaces they use, rather than the whole tree. This keeps each request cheap, and it keeps the answers focused.

The service is text only, with no embeddings endpoint, so a retrieval setup needs an embedding model from elsewhere to pick the chunks. If you only need keyword search over your files, a plain text search tool will often do the job.

Questions and answers

What is the context window on this API?

100,000 tokens, counted across the prompt and the completion together.

Do I need to set max_tokens?

No. It is optional, and the completion can use whatever part of the window your prompt leaves free.

Does a longer prompt cost more per token?

No. Input is $0.15 per 1M tokens at any length, so a prompt that fills the window costs about $0.015 before the reply.

How do I know how many tokens I used?

Read the usage field in the response. With streaming, usage is sent at the end of the stream.

Your key is one form away

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