EN ▾
Open account

Get an OpenAI-Style API Key and Swap Providers

An OpenAI-style API is defined by its request format, not by who runs it. Get a key from a compatible provider, change one URL, and your existing code keeps working.

Updated

A glowing cable being moved between two server sockets, illustrating a provider swap by changing one URL

Key points

  1. Any OpenAI SDK works with a compatible provider once the base URL and key are changed.
  2. Keep the base URL, key and model name in environment variables so a switch is a config change.
  3. Test with GET /v1/models first, then a short chat completion.
  4. You can regenerate the key at any time on the API key page, and the old one stops working at once.

Two meanings of getting the API

When people type "get open ai api" they usually mean one of two things. Some want an official key from OpenAI, which you create in your account on OpenAI's own platform, with billing set up there. Others want an API that speaks the same protocol, so existing code and tools keep working, but with a different provider, price or content policy. This article covers the second case and shows how to make the switch painless.

The protocol is what matters. A client sends a POST request with a JSON body containing a model name and a list of messages, plus an Authorization: Bearer header. Any server that accepts that request and returns the same JSON shape is OpenAI-compatible, and any OpenAI SDK can talk to it.

Step 1: create the account and key

  1. Sign up with Google, or with an email and password.
  2. Open the API key page. New users can claim $0.50 of trial credit with one click. It needs no card, is valid for 7 days and is limited to one per person.
  3. Copy the key. Treat it like a password: keep it out of source control and out of front-end code.

The key page also lets you regenerate (reissue) the key whenever you want. The old key stops working immediately, and you never need to contact support to replace one. After your first top-up, an account can hold up to 5 keys with labels, so each app or teammate gets its own and you can revoke one without touching the others.

Step 2: make the endpoint configurable

The cleanest way to stay portable is to read three values from the environment instead of hardcoding them: the key, the base URL and the model name. Then moving to another provider means editing a config file, not code.

export API_KEY="paste-your-key-here"
export API_BASE_URL="https://api.uncensoredaiopen.com/v1"
export API_MODEL="uncensored"

In Python, the official SDK reads them like this:

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["API_KEY"],
    base_url=os.environ.get("API_BASE_URL", "https://api.uncensoredaiopen.com/v1"),
)
MODEL = os.environ.get("API_MODEL", "uncensored")

reply = client.chat.completions.create(
    model=MODEL,
    messages=[{"role": "user", "content": "Reply with the single word: ready"}],
    max_tokens=10,
)
print(reply.choices[0].message.content)

In Node the pattern is the same:

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.API_KEY,
  baseURL: process.env.API_BASE_URL ?? "https://api.uncensoredaiopen.com/v1",
});

const reply = await client.chat.completions.create({
  model: process.env.API_MODEL ?? "uncensored",
  messages: [{ role: "user", content: "Reply with the single word: ready" }],
});
console.log(reply.choices[0].message.content);

Step 3: test before you trust

Two quick calls tell you almost everything. The first confirms the key and the base URL, and the second confirms the model responds.

# 1. List models: a 200 response means the key and URL are right
curl -s https://api.uncensoredaiopen.com/v1/models \
  -H "Authorization: Bearer $API_KEY"

# 2. Send a short chat request and show the response headers
curl -si https://api.uncensoredaiopen.com/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"uncensored","messages":[{"role":"user","content":"Say hi"}],"max_tokens":20}'

In the second response, look at X-Request-Id (quote it if you ever contact support), X-Balance-USD (your remaining credit), and the two rate-limit headers, X-RateLimit-Limit-Requests and X-RateLimit-Limit-Concurrency. A 401 means the key is wrong or has been regenerated. A 404 usually means the base URL is missing its /v1 suffix.

What to check when you swap providers

Compatibility covers the request shape, not every feature. Run through this list before you cut over.

  • Model name. Each provider has its own identifiers. Here it is uncensored, and there is just one model.
  • Endpoints you call. This API supports POST /v1/chat/completions, POST /v1/responses and GET /v1/models. Images, audio, embeddings and fine-tuning are not offered.
  • Features. Streaming over SSE, tool calling, JSON mode and the usual sampling parameters (temperature, top_p, stop, seed, penalties) are passed through.
  • Context window. 100,000 tokens, prompt plus completion. Longer inputs need trimming.
  • Limits. A full key allows 8 concurrent requests and 300 per minute. A trial key allows 2 and 60.
  • Behaviour. Different models answer differently, so rerun your own prompt tests rather than assuming equal output.

Handle 429 properly

Rate limits are the most common surprise after a switch. Over a limit the API returns HTTP 429 with the error code rate_limited (too many requests per minute) or concurrency (too many at once). On temporary overload it also returns 429, with a Retry-After: 5 header. A streamed request holds its concurrency slot until the stream ends, so long streams count against the cap for their whole duration.

import os, time
from openai import OpenAI, RateLimitError

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

def ask(prompt, retries=4):
    for attempt in range(retries):
        try:
            r = client.chat.completions.create(
                model="uncensored",
                messages=[{"role": "user", "content": prompt}],
            )
            return r.choices[0].message.content
        except RateLimitError:
            time.sleep(5 * (attempt + 1))
    raise RuntimeError("still rate limited after retries")

For a fuller pre-launch review, including logging and spend monitoring, see the production checklist.

Common errors after the switch

Most first-day problems come from a short list. Match the symptom to the cause before you start debugging your own code.

SymptomLikely causeFix
401 UnauthorizedWrong key, an extra space, or a key that was regeneratedCopy the current key from the API key page and check the Authorization header
404 Not FoundBase URL missing the /v1 suffix, or a typo in the pathUse the full base URL exactly as shown on this page
429 with rate_limitedMore than the allowed requests per minuteSlow down or batch; retry after a pause
429 with concurrencyToo many requests in flight, including open streamsLimit parallel calls to 8 on a full key or 2 on a trial key
Model not foundA model name left over from the old providerSet the model to uncensored
Request rejected as too largeBody over 8 MB, or a prompt beyond the 100,000-token windowTrim or split the input

A subtle one deserves its own mention: hardcoded model names. Search your codebase for the old model identifier, since it often hides in a helper function, a test or a default argument. Moving it into the environment variable from step 2 prevents a repeat the next time you change providers.

If an error is still unclear, note the X-Request-Id header from the failing response and send it through the support page.

Check answer quality after the switch

A working request does not prove the answers are good enough. Pick 10 to 20 real prompts from your own product, including the awkward ones, and run them through the new endpoint with the same system prompt. Read the replies next to the old ones and note where tone, length or formatting changed.

Differences are normal. Each model has its own habits, so a system prompt tuned for one provider may need small edits for another. Adjust temperature first, since a value that felt right before can read as too loose or too flat on a new model. Then check anything your code parses, such as JSON output, and use JSON mode when a program reads the reply.

Finally, log the usage block for the whole test run. Multiply the totals by the rates in the next section and you have a cost forecast based on your own traffic rather than a guess. Keep the old provider configured until those numbers and the answers both look right.

Cost of the switch

There is no setup fee or subscription. You prepay credit and pay $0.15 per 1M input tokens and $0.50 per 1M output tokens. A test request with 200 tokens in and 100 out costs $0.00003 plus $0.00005, so $0.00008. The $0.50 trial covers over 6,000 of them, which is plenty for a migration test. When you are ready to continue, read the pricing page and the docs.

Questions and answers

Can I use the official OpenAI SDK with another provider?

Yes. Both the Python and Node SDKs accept a custom base URL, so you set it to the provider's endpoint and use that provider's key.

Do I have to rewrite my code to switch?

Usually no. Change the base URL, key and model name, then retest your prompts. Only calls to unsupported endpoints, such as embeddings or images, need another solution.

What if my key leaks?

Regenerate it on the API key page. The old key stops working at once, and no support ticket is needed.

Is this the official OpenAI API?

No. It is an independent OpenAI-compatible service serving one open-weight model, not the official API of OpenAI or any other vendor.

Your key is one form away

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

Start with trial credit

Email and password, key on screen right away.