EN ▾
Get API key

Gemma 4 31B API: What You Can Actually Call

This page explains what you get when you call a hosted open-weight model through an OpenAI-compatible endpoint, how it behaves on long and complex tasks, and what those tasks cost.

Isometric illustration of a long stack of data slabs feeding a large glowing model block connected to tool nodes

Key points

  1. One open-weight model, model ID uncensored, served through POST /v1/chat/completions
  2. 100,000 token context window, streaming, tool calling and JSON mode
  3. $0.15 per 1M input tokens and $0.50 per 1M output tokens, prepaid
  4. Not an official vendor API, and no parameter count is promised on this page

The short answer

If you want a Gemma 4 31B API in the sense of an official Google endpoint with a named checkpoint, this is not that. This site serves a single open-weight model, run by an independent provider and tuned to answer without content refusals for lawful adult use. You call it with the model ID uncensored, and this page makes no claim about its parameter count or exact base checkpoint. If a specific size matters to your project, read the model card of whatever checkpoint you plan to compare against and judge the output yourself on your own prompts.

What you can rely on is the interface and the limits. The API is OpenAI-compatible, so any OpenAI SDK works after you change the base URL and the key. The context window is 100,000 tokens, covering prompt and completion together. Streaming, tool calling and JSON mode are supported. Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens from prepaid credit.

The rest of this page shows how to point your code at the endpoint, how to structure complex jobs so they finish reliably, and how to estimate cost before you run anything large. For the product-level overview, see the integration and pricing guide.

Check what the endpoint reports

Before you write any application code, ask the server what it offers. GET /v1/models lists the models available to your key. You should see the model ID uncensored, and that is the string you pass in every chat request.

curl https://api.gemmaapi.top/v1/models \
  -H "Authorization: Bearer $API_KEY"

Treat this call as your connectivity test. If it returns a list, your key and base URL are correct, and any later error comes from the request body rather than from setup. If you have not created a key yet, the API key page walks through sign-up with Google or with email and password.

Two response headers are useful from the first call on. X-Request-Id identifies a single request, which helps when you contact support. X-Balance-USD shows your remaining credit, so a long batch job can watch its own budget without a separate billing call.

First request in Python

The official openai package works unchanged. Set base_url, set the key, and use uncensored as the model.

from openai import OpenAI

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

resp = client.chat.completions.create(
    model="uncensored",
    messages=[
        {"role": "system", "content": "You are a careful analyst. Answer directly."},
        {"role": "user", "content": "Compare two plans for migrating a monolith and name the main risk of each."},
    ],
    temperature=0.4,
)
print(resp.choices[0].message.content)
print(resp.usage)

Print resp.usage during development. It gives you the exact prompt and completion token counts, which you can multiply by the prices below to get the real cost of each call. The same request in curl looks like this:

curl https://api.gemmaapi.top/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"uncensored","messages":[{"role":"user","content":"Say hello in one sentence."}]}'

The full parameter list lives in the documentation. Temperature, top_p, stop, seed and the frequency and presence penalties are passed through, so sampling settings you tuned elsewhere carry over.

Handling complex tasks with tools and JSON mode

Large models are usually chosen for work that needs several steps: extract facts, decide, call a function, write the result. Two features carry most of that load here.

Tool calling

You describe functions in tools, optionally force a choice with tool_choice, and the model replies with tool_calls. You run the function and send the result back as a message with role: "tool". Streamed responses carry tool_calls too, so an agent loop can show progress while it works.

tools = [{
    "type": "function",
    "function": {
        "name": "lookup_order",
        "description": "Fetch an order by id",
        "parameters": {
            "type": "object",
            "properties": {"order_id": {"type": "string"}},
            "required": ["order_id"],
        },
    },
}]

first = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Where is order A-1042?"}],
    tools=tools,
)
call = first.choices[0].message.tool_calls[0]
print(call.function.name, call.function.arguments)

Always validate the arguments before you execute anything. A model can produce a malformed or unexpected value, and your code is the one that has side effects.

JSON mode

Set response_format to {"type":"json_object"} when you need machine-readable output. Mention JSON in your prompt as well, describe the keys you expect, and parse inside a try block. If parsing fails, retry once with the error message appended; that fixes most cases.

Using the 100k window on long inputs

A large window changes what you can attempt in a single call. Instead of chunking a long contract or a codebase excerpt into pieces and merging answers, you can often send the whole thing and ask for the result directly. The window is shared: prompt plus completion must fit inside 100,000 tokens. The completion may use whatever the prompt leaves free, and max_tokens is optional.

Practical habits for long inputs:

  • Put the task instruction at the end of the prompt as well as the start. A long document in the middle, with the question repeated after it, tends to give more focused answers.
  • Set max_tokens anyway when you know the answer should be short. It protects your budget if the model rambles.
  • Stream long generations. A request that runs for a minute is easier to handle when tokens arrive as they are produced.
  • Keep the body under 8 MB. For text this is rarely a problem, but base64 blobs pasted into a prompt can hit it.

For a deeper look at how the window behaves in long conversations, the same logic applies as in any chat model: every turn resends the full history, so input cost grows with conversation length.

What heavy jobs cost

Costs are easy to compute because there are only two rates: $0.15 per 1M input tokens and $0.50 per 1M output tokens. Here are three worked examples.

JobInputOutputMathCost
Summarize one 20,000-token report20,0001,0000.003 + 0.0005$0.0035
Fill a full 100k window, 2,000-token answer98,0002,0000.0147 + 0.001$0.0157
Agent run: 10 steps of 8,000 in and 400 out80,0004,0000.012 + 0.002$0.014

Scaled up, a thousand report summaries cost $3.50. That is the whole bill for the input and output together. Failed or refused requests are not charged, so retries after an error do not add to the total unless a retry itself succeeds.

Credit is prepaid in whole-dollar amounts from $20 to $500. Larger top-ups add a bonus: +5% from $50, +10% from $100 and +15% from $200. Credit never expires, and there is no subscription. Crypto (USDT on TRC20, USDC on Base) is accepted. Current numbers are on the pricing page.

Rate limits and concurrency

A full key allows 8 concurrent requests and 300 requests per minute. A trial key allows 2 concurrent requests and 60 per minute. The two limits fail differently. Too many requests per minute returns HTTP 429 with the code rate_limited. Too many in flight at once returns HTTP 429 with the code concurrency. Temporary overload also returns 429, with a Retry-After: 5 header.

One detail catches people: a streamed request holds its concurrency slot until the stream ends. If you start 8 streams and your client is slow to read them, the ninth request will be rejected even though the per-minute count is low. Use a semaphore sized to your key, and back off on 429 using the header when present.

import time
from openai import OpenAI, RateLimitError

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

When another option fits better

A hosted endpoint is the right choice when you want to start in minutes, pay only for tokens used and avoid managing GPUs. It is a weaker fit in a few cases. If you need image, audio or video generation, embeddings or fine-tuning, this API does not offer them; it is text only. If you need a specific vendor's official model with that vendor's service terms, use the vendor directly and check their current pricing. If you need guaranteed local processing, run an open-weight model on your own hardware.

One hard rule applies to all use: no sexual content involving minors. Everything else about content is the responsibility of you and your users, within the law. Prompts are not used for training.

Questions and answers

Is this the official Gemma 4 31B API from Google?

No. It is a hosted open-weight model run by an independent provider. It is not the official API of Google or any other vendor, and this page does not state a parameter count.

What model name do I send in requests?

Send uncensored as the model value. You can confirm it with GET /v1/models.

How much context can I use?

The window is 100,000 tokens for prompt plus completion together. max_tokens is optional.

Do tool calling and JSON mode work?

Yes. Tool calling supports tools, tool_choice, streamed tool_calls and role tool results. JSON mode uses response_format with type json_object.

Can I test it without paying?

New users can claim $0.50 of trial credit with one click on the API key page after sign-up. It lasts 7 days and needs no card.

Your key is one form away

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