How to Use GapGPT API With Python: Gateway Pattern
Third-party OpenAI-compatible gateways all work the same way in Python: install the openai package, set a base URL, pass the provider's key and use the provider's model name. This page shows that pattern with working code against this site's API.
Last updated

Summary
This site is a separate service and is not affiliated with GapGPT; for GapGPT itself use the base URL and model names in their own docs.
Only three values change between gateways: base_url, api_key and the model id.
Here they are https://api.gapgptapi.com/v1, your Bearer key and uncensored.
Handle HTTP 429 and keep keys out of source code, whichever gateway you use.
Which service this page covers
A quick clarification, because the names are close. This page is on gapgptapi.com, a separate hosted API that is not affiliated with GapGPT. If you are asking how to use gapgpt api with python for an account you already have there, the method is identical, but you must take the base URL, key and model names from GapGPT's own documentation. We will not guess at them.
What follows is the general method for any gateway that copies the OpenAI format, demonstrated with this service's real values. Once it works here, you can repeat it with another gateway by changing three strings.
The service in the examples is one open-weight text model, run by an independent provider and tuned to answer without content refusals for lawful adult use. It is not the official API of any model vendor.
The three values every gateway needs
An OpenAI-compatible gateway copies the shape of OpenAI's REST API, so the official Python SDK can talk to it. What differs is:
| Value | Where it comes from | This service |
|---|---|---|
base_url | Provider's docs | https://api.gapgptapi.com/v1 |
api_key | Your account page | From the API key page |
model | Provider's model list | uncensored |
The key is sent as Authorization: Bearer <key>; the SDK does that for you. Get a key by signing up with Google or an email and password; new accounts can claim a $0.50 trial credit with one click (7 days, no card, one per person).
Install and make the first call
python -m venv .venv
source .venv/bin/activate
pip install openai
export AI_API_KEY="paste-your-key-here"
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.gapgptapi.com/v1",
api_key=os.environ["AI_API_KEY"],
)
resp = client.chat.completions.create(
model="uncensored",
messages=[
{"role": "system", "content": "Answer in one short paragraph."},
{"role": "user", "content": "What is an OpenAI-compatible API?"},
],
)
print(resp.choices[0].message.content)
print("tokens:", resp.usage.prompt_tokens, resp.usage.completion_tokens)
Run it. If you see a paragraph and two token counts, the connection works. The most common first errors are a missing environment variable (a KeyError), a typo in the base URL such as a missing /v1, and a model id that the gateway does not know. Check these in that order.
Prefer plain HTTP? The same call with requests:
import os
import requests
r = requests.post(
"https://api.gapgptapi.com/v1/chat/completions",
headers={"Authorization": "Bearer " + os.environ["AI_API_KEY"]},
json={
"model": "uncensored",
"messages": [{"role": "user", "content": "Say hi in four words."}],
},
timeout=60,
)
r.raise_for_status()
print(r.json()["choices"][0]["message"]["content"])Streaming and async
For chat interfaces, stream the reply so text appears as it is generated. Usage is reported at the end of the stream:
stream = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Tell a six-line story about a lighthouse."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
print()
Remember that a streamed request occupies its concurrency slot until the stream ends. A full key allows 8 at once, a trial key 2.
For web servers or bots, use the async client so calls do not block each other:
import asyncio
import os
from openai import AsyncOpenAI
client = AsyncOpenAI(
base_url="https://api.gapgptapi.com/v1",
api_key=os.environ["AI_API_KEY"],
)
gate = asyncio.Semaphore(6)
async def ask(text):
async with gate:
resp = await client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": text}],
max_tokens=300,
)
return resp.choices[0].message.content
async def main():
answers = await asyncio.gather(*(ask(f"Give me idea number {i}") for i in range(1, 5)))
for a in answers:
print(a)
asyncio.run(main())
Chat applications also need memory. The API does not remember earlier requests, so you keep the conversation and send it again on every call:
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.gapgptapi.com/v1",
api_key=os.environ["AI_API_KEY"],
)
history = [{"role": "system", "content": "You are a concise assistant."}]
def chat(text, keep=12):
history.append({"role": "user", "content": text})
window = [history[0]] + history[1:][-keep:]
resp = client.chat.completions.create(model="uncensored", messages=window)
answer = resp.choices[0].message.content
history.append({"role": "assistant", "content": answer})
return answer
print(chat("Name a city by the sea."))
print(chat("Describe its harbor in one sentence."))
The window keeps the system message plus the last twelve messages. Every message you resend is billed again as input, so a shorter window is a cheaper window. The context limit is 100,000 tokens, which a chat rarely approaches, so the reason to trim is cost rather than space. If a user asks something that depends on an old message, raise keep or store a short summary in the system message.
Reading failures without guessing
When a call fails, print the status code before anything else. A 401 means the key is wrong or was regenerated. A 404 usually means the base URL is missing /v1. A 429 is a limit and carries the code rate_limited or concurrency. A 400 points at the request body, for example a misspelled parameter. Log X-Request-Id from the response for the failing call, and keep the request body next to it so you can reproduce the problem.
Errors, limits and retries
Every gateway has limits, and you should write for them from the start. On this service a full key allows 8 concurrent requests and 300 per minute, and a trial key 2 and 60. Past that the API answers HTTP 429 with the code rate_limited (per minute) or concurrency (too many at once). Temporary overload also returns 429, with a Retry-After: 5 header. The maximum request body is 8 MB.
The OpenAI SDK retries 429s twice by default with a short backoff. Raise it with max_retries and catch what remains:
import os
import openai
client = openai.OpenAI(
base_url="https://api.gapgptapi.com/v1",
api_key=os.environ["AI_API_KEY"],
max_retries=4,
)
try:
resp = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "ping"}],
)
except openai.RateLimitError:
print("Rate limited. Slow down and try again.")
except openai.APIStatusError as e:
print("API error:", e.status_code)
Failed or refused requests are not charged, so retrying does not cost you twice. Each response carries an X-Request-Id; log it so you can quote it later.
Cost and balance from Python
Price is $0.15 per 1M input tokens and $0.50 per 1M output tokens, from prepaid credit. The usage field in each response lets you compute the exact cost of a call:
def cost_usd(usage):
return usage.prompt_tokens * 0.15 / 1_000_000 + usage.completion_tokens * 0.50 / 1_000_000
print(round(cost_usd(resp.usage), 6))
A call with 1,200 input and 300 output tokens comes to $0.00018 + $0.00015 = $0.00033. To see your balance, read the X-Balance-USD header or call GET /v1/balance. Top-ups run from $20 to $500 in crypto, and the pricing page lists the bonus tiers.
When you want a bigger project, such as a companion app, read the Character.ai API alternative for developers. All parameters that pass through, including tools, response_format, temperature, top_p, stop and seed, are in the docs.
Habits that carry over to any gateway
- Configuration, not constants. Read base URL, key and model from environment variables, so switching providers is an edit in one place.
- One key per app. On this service you can regenerate a key whenever you like, and the old key stops working at once. Accounts that have topped up can hold up to 5 labeled keys.
- Never log the key. Log request ids instead.
- Treat the model id as provider-specific. A name that works on one gateway may be wrong on another.
- Check the provider's data and content rules. Here prompts are not used for training, and sexual content involving minors is never allowed.
Moving an existing project over
If your code already uses the OpenAI SDK, you may not need to edit it at all. The Python and Node SDKs read the environment variables OPENAI_BASE_URL and OPENAI_API_KEY when you create a client without arguments:
export OPENAI_BASE_URL="https://api.gapgptapi.com/v1"
export OPENAI_API_KEY="paste-your-key-here"
python your_script.py
Then search the project for hard-coded model names and replace them with uncensored. That is the full migration for most scripts. Libraries built on top of the SDK, such as agent frameworks, usually accept the same two values in their own settings. The model is text only, so any code path that calls image, audio or embedding endpoints needs a different provider for those parts.
Tool calling and the Responses endpoint
Both features use the standard OpenAI shapes. Tool calling lets the model ask your code to run a function. You declare the function, check the reply for tool_calls, run it and send the result back with role tool:
import json
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.gapgptapi.com/v1",
api_key=os.environ["AI_API_KEY"],
)
tools = [{
"type": "function",
"function": {
"name": "roll_dice",
"description": "Roll a die with the given number of sides",
"parameters": {
"type": "object",
"properties": {"sides": {"type": "integer"}},
"required": ["sides"],
},
},
}]
messages = [{"role": "user", "content": "Roll a 20-sided die for my character."}]
first = client.chat.completions.create(model="uncensored", messages=messages, tools=tools)
call = first.choices[0].message.tool_calls[0]
args = json.loads(call.function.arguments)
messages.append(first.choices[0].message)
messages.append({"role": "tool", "tool_call_id": call.id, "content": "17"})
final = client.chat.completions.create(model="uncensored", messages=messages, tools=tools)
print(args, final.choices[0].message.content)
Check that tool_calls is not empty before you index into it; a model may answer in plain text instead. The service also accepts POST /v1/responses, which you can call with client.responses.create(model="uncensored", input="..."), and lists the model on GET /v1/models.
More guides
- GapGPT API Alternative: What to Compare
- Character.ai API Alternative: Uncensored & Developer-Friendly
Frequently Asked Questions
| Question | Answer |
|---|---|
| Is this the official Character.ai API? | No, we are an independent provider of an uncensored model. We are not affiliated with Character.ai. |
| What crypto do you accept? | We accept USDT (TRC20) and USDC (Base) for top-ups. |
| Do you use my data for training? | No, your prompts are not used for training. |
| How long does my credit last? | Your credit never expires. |
Final Verdict for NSFW and Creative Use Cases
For developers who need raw, uncensored text generation, this API is a strong alternative. It combines OpenAI compatibility with transparent pricing and privacy. You get a dedicated model that does not filter lawful adult content. The crypto-only payment model keeps costs low and predictable. It is built for creators who want control.
The technical specs are robust. The 100k context window handles long conversations. The token pricing is fair. The privacy policy is clear. If you are building the next generation of roleplay apps, this is the foundation you need. Start with the trial key and see the difference yourself.
Common questions
Is gapgptapi.com the same as GapGPT?
No. This is a separate service and is not affiliated with GapGPT. For GapGPT itself, use the base URL and model names from their documentation.
Which Python package do I need?
The official openai package. Install it with pip, then set base_url, api_key and the model id when you create the client.
What base URL and model do I use here?
Use https://api.gapgptapi.com/v1 as the base URL and uncensored as the model id, with your key as the Bearer token.
How do I handle rate limit errors?
Expect HTTP 429 with the code rate_limited or concurrency. Retry with a backoff, honor Retry-After, and keep concurrency within 8 on a full key or 2 on a trial key.
Get your key in seconds
Sign up, copy your key, update your base URL. That’s it.