Your first request from code
Two values change, and that's all. By the end you'll have a real answer and seen its trace in the panel.
If you've used OpenAI's API, you know nearly all of this already. IranRouter speaks the same API, so just two values change: the address and the key.
base_url: https://iranrouter.com/v1 api_key: ir-...
Any SDK, library or tool that works with OpenAI reaches every model with those two values.
With curl
The fastest test, since nothing needs installing:
curl https://iranrouter.com/v1/chat/completions \ -H "Authorization: Bearer ir-..." \ -H "Content-Type: application/json" \ -d '{ "model": "deepseek/deepseek-v4-flash", "messages": [{"role": "user", "content": "Hello! Introduce yourself in one sentence."}], "max_tokens": 100 }'
In the response, the text is in choices[0].message.content. The usage part has the token counts and cost_rial, the final charge for this request.
With Python
from openai import OpenAI client = OpenAI( api_key="ir-...", base_url="https://iranrouter.com/v1", ) resp = client.chat.completions.create( model="deepseek/deepseek-v4-flash", messages=[{"role": "user", "content": "Hello!"}], max_tokens=100, ) print(resp.choices[0].message.content)
With Node.js
import OpenAI from "openai"; const client = new OpenAI({ apiKey: process.env.IRANROUTER_KEY, baseURL: "https://iranrouter.com/v1", }); const resp = await client.chat.completions.create({ model: "deepseek/deepseek-v4-flash", messages: [{ role: "user", content: "Hello!" }], }); console.log(resp.choices[0].message.content);
Send a real request0 of 3 steps
- Run one of the three samples above with your key.
- If you get a 401, look for a stray space or newline in the key.
- If you get a 402, top up the wallet or pick a free model.
Make sure it went through IranRouter
Go to Usage & logs. That request should be there with the model, tokens and cost. If it isn't, it didn't pass through here; most likely base_url didn't change.
You can also ask for the balance without opening the panel:
curl https://iranrouter.com/v1/credits -H "Authorization: Bearer ir-..."
If your tool only reads environment variables
Most tools know these two variables, so sometimes you touch no code at all:
export OPENAI_BASE_URL="https://iranrouter.com/v1" export OPENAI_API_KEY="ir-..."
OPENAI_API_BASE instead of OPENAI_BASE_URL. If it won't connect, set both.What you learned
- Only the address and key change.
usage.cost_rialis the charge for that request.- Next: choosing a model by the numbers.
Keep your place
Sign in to the panel and each lesson and your path are saved, so you continue from the same spot on any device.