Documentation

Call NexoRouter from Replit with Python in the NexoRouter documentation.

Call NexoRouter from Replit with Python

This guide runs a first Chat Completions request from a new Replit Python repl using the OpenAI SDK and a Replit secret.

What you need

  • A NexoRouter account with prepaid balance.
  • An API key from Dashboard -> API Keys.
  • A Replit account.

Do not put the API key in main.py, the chat, or a screenshot.

1. Create the repl

  1. Open Replit and create a new Python repl.
  2. Name it something like nexorouter-first-call.
  3. Confirm the workspace has a main.py file.

2. Install the OpenAI SDK

In the Replit Shell:

pip install openai

If the project uses requirements.txt, add:

openai

Then run pip install -r requirements.txt.

3. Store the API key as a secret

In Replit Secrets, add:

NEXOROUTER_API_KEY=your_nexorouter_key

The OpenAI SDK reads this at runtime. Do not commit secrets or paste them into main.py.

4. Add main.py

Replace main.py with:

import os
from openai import OpenAI

api_key = os.environ.get("NEXOROUTER_API_KEY")
if not api_key:
    raise SystemExit("Set the Replit secret NEXOROUTER_API_KEY first.")

client = OpenAI(
    api_key=api_key,
    base_url="https://api.nexorouter.com/v1",
)

response = client.chat.completions.create(
    model="kimi-k2.6",
    messages=[
        {"role": "user", "content": "Reply with one sentence: NexoRouter is connected from Replit."}
    ],
)

print(response.choices[0].message.content)

Use another exact catalog ID such as gpt-5.5 or gpt-5.6-luna only after it appears in Models.

5. Run the file

Use the Run button if it is visible.

If Run is hidden, open Shell and run:

python main.py

On some Replit workspaces the command is python3 main.py.

6. Verify

  • The Shell prints one assistant sentence.
  • Usage Logs shows the model ID, tokens, cost, and request ID.
  • A missing secret raises the NEXOROUTER_API_KEY error above.
  • model_not_found means the ID is wrong or the key's model scope excludes it.
  • insufficient_quota means the prepaid balance cannot cover the request.