EN ▾
Try with trial credit

Uncensored APIUncensored GPT for Android: Call an API from Kotlin

Uncensored GPT for Android: Call an API from Kotlin

For uncensored gpt for android you do not need a special app: your own Android app can call an OpenAI-compatible API over HTTPS. This guide shows a Kotlin request that works, and the one design rule that matters most, which is never to ship your key inside the app.

Last updated

A phone linked by a glowing cable to a server cube that holds the key, showing a safe API relay for Android

The architecture that works

There are two ways to wire an Android app to an API. The wrong one puts the key in the app. The right one adds a thin backend you control:

  • App to your server. The app sends the user's message to your own endpoint, with your own login or per-user token.
  • Your server to the API. The server holds the key, adds the system prompt, calls /v1/chat/completions and relays the reply.

This costs you one small server, and in return you can rate limit users, hide your prompts, cap spending and rotate the key without publishing a new app version.

Even a hobby app benefits from this. A relay is about thirty lines of code and can sit on any small server or serverless function. It also gives you a single place to log token usage, which matters because you pay per token: a bug in the app that loops requests would otherwise drain your balance before you notice.

Why you must not embed the key

An APK is a zip file. Anyone can unpack it, search the strings or watch traffic with a proxy, and your key is exposed. Obfuscation slows this down by minutes, not by days. A leaked key lets strangers spend your balance.

If it happens anyway, open the API key page and regenerate the key. The old one stops working at once. Accounts that have topped up can also hold up to 5 keys with labels, so you can give each environment its own and revoke only the one that leaked.

If you do want a quick experiment on your own device, put the key in local.properties or an environment variable, keep that file out of version control and never build a release from it. Treat the experiment build as private. Once the idea is proven, move the call to the server and delete the key from the project history, since keys committed to git remain visible in old commits.

A Kotlin call with OkHttp

Add OkHttp to your dependencies, for example implementation("com.squareup.okhttp3:okhttp:4.12.0"). Then use this function from a background thread or a coroutine, never the main thread:

// Kotlin
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
import org.json.JSONArray
import org.json.JSONObject

val client = OkHttpClient()

fun ask(apiKey: String, prompt: String): String {
    val body = JSONObject()
        .put("model", "uncensored")
        .put("messages", JSONArray().put(
            JSONObject().put("role", "user").put("content", prompt)
        ))
        .toString()
        .toRequestBody("application/json".toMediaType())

    val request = Request.Builder()
        .url("https://api.gptuncensoredapi.com/v1/chat/completions")
        .header("Authorization", "Bearer $apiKey")
        .post(body)
        .build()

    client.newCall(request).execute().use { resp ->
        val text = resp.body?.string() ?: error("empty body")
        if (resp.isSuccessful.not()) error("HTTP ${resp.code}: $text")
        return JSONObject(text)
            .getJSONArray("choices")
            .getJSONObject(0)
            .getJSONObject("message")
            .getString("content")
    }
}

The response has the usual OpenAI shape, so choices[0].message.content holds the reply. On failure the function throws with the HTTP code, which makes 429 handling easy to add.

The server side in a few lines

A minimal relay in Node shows the pattern. The app never sees the key:

import express from "express";

const app = express();
app.use(express.json({ limit: "1mb" }));

app.post("/chat", async (req, res) => {
  const upstream = await fetch("https://api.gptuncensoredapi.com/v1/chat/completions", {
    method: "POST",
    headers: {
      "Authorization": "Bearer " + process.env.API_KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: "uncensored",
      messages: req.body.messages,
      max_tokens: 600,
    }),
  });
  res.status(upstream.status).json(await upstream.json());
});

app.listen(3000);

Add your own user authentication before this route goes live, otherwise it is an open proxy for anyone who finds the address.

A few additions make the relay production-ready. Verify the user's session token before forwarding. Reject bodies with more than a sensible number of messages. Set a maximum max_tokens on the server, regardless of what the app asks for, so a modified client cannot request enormous completions. Log the request ID from the X-Request-Id response header so you can trace any complaint. The maximum body the API accepts is 8 MB, but your own limit should be far lower.

Streaming and limits on mobile

Set stream: true and read the response as server-sent events, so text appears as it is generated. Usage is reported at the end of the stream. A streamed request holds its concurrency slot until it finishes, so close the stream when the user leaves the screen.

A full key allows 8 concurrent requests and 300 per minute across all your users combined. If your app has many users, queue on the server and return a friendly retry message on HTTP 429. When the response carries Retry-After: 5, wait five seconds.

Reading the stream

With OkHttp you can read the response body line by line. Each event starts with data: followed by JSON, and, as in the OpenAI format, the stream usually ends with a data: [DONE] line (check this against a real response from your key). Parse each chunk's choices[0].delta.content and append it to the text view on the main thread. Cancel the call in onStop so a user who leaves the screen does not leave a stream open and a slot occupied.

Handling weak networks

Phones switch between wifi and mobile data in the middle of a request. Set sensible timeouts, expect failures, and make retries safe. A failed request is not charged on our side, but a retried request that succeeds is, so avoid retry loops with no limit.

What a chat turn costs

The price is $0.15 per 1M input tokens and $0.50 per 1M output tokens. For a mobile chat turn of 1,200 input and 300 output tokens:

  • Input: 1,200 / 1,000,000 x $0.15 = $0.00018
  • Output: 300 / 1,000,000 x $0.50 = $0.00015
  • Total: $0.00033

A $20 top-up covers about 60,000 such turns. Check the X-Balance-USD header on each response to show an alert when the balance runs low. The trial of $0.50 helps you test the whole flow first; see pricing and the docs.

Because history is resent every turn, cost grows during a long chat. A conversation that adds 500 tokens per turn sends about 5,000 input tokens on turn 10, which costs 5,000 / 1,000,000 x $0.15 = $0.00075 for the input alone. Cap the history you resend, for example to the last 20 messages, and the cost per turn levels off instead of climbing.

Rules for what you ship

The endpoint is for lawful adult use and has one fixed rule: no sexual content involving minors. If your app is open to the public, show an age notice and have your own terms. The model is text only. If a user taps on voice or images, you will need another service for those. Prompts are not used for training, but say in your privacy policy that messages pass through your server.

Before you publish, check the store policies for AI apps and for content that is only suitable for adults, since each store sets its own rules and changes them. Those rules apply to your app, not to us. Build an age gate if your content needs one, and offer a way for users to report bad output. Your backend is also the right place to filter or log by user, so you can show a reasonable record if a store reviewer asks questions. The common mistakes page covers server-side errors that tend to appear in the first week.

Common questions

Can I call the API directly from an Android app?

Technically yes, but the key would be stored in the app and could be extracted. Use a small backend that keeps the key and relays requests.

Do I need a special Android SDK?

No. Any HTTP client works, since the endpoint speaks the OpenAI chat completions format. OkHttp or Retrofit are common choices.

Does it work offline?

No. The model runs on a hosted server, so the device needs a network connection.

What if my key leaks?

Regenerate it on the API key page. The old key stops working at once, and you do not need to contact support.

Your key is ready

Sign up, copy the credential, and update your base URL. That is all.