Phi 4 API: toman pricing and code
microsoft/phi-4
jsonYou are billed for the usage the request actually reported. Prices follow the market.Pricing and top-ups
Phi 4 example: JSON output against a schema
The example is picked from this model's own capabilities. Drop in your key and it runs as is.
from openai import OpenAI
import json
client = OpenAI(base_url="https://api.uttapen.ir/v1", api_key="sk-up-…")
schema = {
"name": "ticket",
"schema": {
"type": "object",
"properties": {
"category": {"type": "string", "enum": ["fani", "mali", "forush"]},
"priority": {"type": "integer", "minimum": 1, "maximum": 5},
"summary": {"type": "string"},
},
"required": ["category", "priority", "summary"],
"additionalProperties": False,
},
"strict": True,
}
resp = client.chat.completions.create(
model="microsoft/phi-4",
messages=[{"role": "user", "content": "Ticket: "For two days I cannot download my invoice and I was charged twice.""}],
response_format={"type": "json_schema", "json_schema": schema},
)
print(json.loads(resp.choices[0].message.content))import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.uttapen.ir/v1", apiKey: "sk-up-…" });
const resp = await client.chat.completions.create({
model: "microsoft/phi-4",
messages: [{ role: "user", content: "Ticket: "For two days I cannot download my invoice and I was charged twice."" }],
response_format: {
type: "json_schema",
json_schema: {
name: "ticket",
strict: true,
schema: {
type: "object",
properties: {
category: { type: "string", enum: ["fani", "mali", "forush"] },
priority: { type: "integer", minimum: 1, maximum: 5 },
summary: { type: "string" },
},
required: ["category", "priority", "summary"],
additionalProperties: false,
},
},
},
});
console.log(JSON.parse(resp.choices[0].message.content));curl https://api.uttapen.ir/v1/chat/completions \
-H "Authorization: Bearer sk-up-…" \
-H "Content-Type: application/json" \
-d '{
"model": "microsoft/phi-4",
"messages": [{"role": "user", "content": "Classify the ticket and give it a priority from 1 to 5."}],
"response_format": {"type": "json_object"}
}'What is Phi 4 good for?
The id for Phi 4 in our API is "microsoft/phi-4", served from Microsoft. Context is 16,384 tokens; past that you have to summarise the history yourself. A single response can run to 14,745 tokens. On price it sits in the "very cheap" band — cheaper than 17 and dearer than 389 of the other paid models in the catalogue.
What it can do beyond plain text: it returns schema-valid JSON through response_format, ready to hand to your code. All of it works through the standard parameters of the official OpenAI SDK — no custom client, no wrapper.
Pricing is 20,309 toman per 1M input tokens and 40,618 per 1M output tokens. A 1,000-word round trip on Phi 4 lands near 79 toman. You are always charged for the usage the request actually reported, never for the estimate, and a failed request costs nothing.
The closest alternative with the same capabilities from a different provider is Command R7B (12-2024): Phi 4 works out roughly 1.1× more expensive, and its context window is smaller. Both run on the same key and the same code, so trying the other one is a single string change.
To make the figure concrete: 100,000 toman of credit buys roughly 1,266 thousand-word requests on Phi 4, and every 1,000 toman is about 12,658 words of round trip. A job with one million input tokens and one million output tokens comes to 60,926 toman in total. Filling this model's 16,384-token window costs 333 toman on the input side alone, which is the real reason to keep conversation history short.
Its nearest relative in the catalogue is "microsoft/wizardlm-2-8x22b", and choosing between those two is where most people hesitate. On a thousand-word request this variant works out 5.9× cheaper (79 against 468 toman). The context windows differ too: 16,384 against 65,535 tokens. Maximum answer length differs as well: 14,745 against 8,000 tokens. On parameters, this one takes logit_bias, min_p, structured_outputs.
Microsoft has 2 models in our catalogue; the cheapest is Phi 4 at 79 toman per thousand words and the dearest WizardLM-2 8x22B at 468. Among the less common parameters it accepts logit_bias, min_p, repetition_penalty, top_k — all through the standard request body. It does not support include_reasoning, reasoning, tool_choice, tools, which most models here do, so test before switching if your code relies on them. By context size the nearest option from another provider is Reka Edge at 16,384 tokens.
Good fits: high-volume work such as classification, tagging and bulk summarising, extracting data against a fixed schema.
[Microsoft Research](/microsoft) Phi-4 is designed to perform well in complex reasoning tasks and can operate efficiently in situations with limited memory or where quick responses are needed. At 14 billion...
Three real jobs, priced on this model
Each figure is derived from the prices above and moves when they do.
| Job | Tokens | Cost |
|---|---|---|
| One chat turn with a medium history | 1,500 in + 400 out | 47 toman |
| Summarising a ten-page document | 4,000 in + 600 out | 106 toman |
| Classifying a thousand short rows | 120,000 in + 20,000 out | 3,249 toman |
Frequently asked
- How do I call Phi 4 from Iran?
- Sign up with your mobile number, top the wallet up in toman, create an API key, then in the official OpenAI SDK point base_url at https://api.uttapen.ir/v1 and set model to "microsoft/phi-4". Nothing else in your code changes.
- What does Phi 4 cost in toman?
- 20,309 toman per 1M input tokens and 40,618 toman per 1M output tokens; a 1,000-word request is around 79 toman. You pay for the usage that request actually reported, and a failed request costs nothing.
- How much input does Phi 4 take?
- Up to 16,384 tokens per request, roughly 12k words. A single answer can reach 14,745 tokens.
- Can I stream Phi 4's output?
- Yes — with stream=true you get SSE events as the tokens are produced. This model has no tool calling and no image input, so pick a different one if you need either.