---
last_updated: 2026-11-20
source_url: https://opper.ai/microsoft/phi-4
title: "Phi-4 by Microsoft"
description: "Phi-4 by Microsoft: 14-billion parameter open-weight language model excelling at mathematical reasoning and complex problem-solving with 16K context window."
---

# Phi-4

By [Microsoft](https://opper.ai/microsoft).

Released 12 Dec 2024, 241 days after [WizardLM-2 8x22B](https://opper.ai/microsoft/wizardlm-2-8x22b) · [Announcement](https://huggingface.co/microsoft/phi-4) · [All Microsoft releases](https://opper.ai/model-releases/microsoft)

Phi-4 is a 14 billion parameter dense decoder-only transformer trained on 9.8 trillion tokens, designed for reasoning-intensive tasks where smaller model size is critical. It exceeds its teacher model on STEM-focused benchmarks, achieving 84.8 on MMLU and 80.4 on MATH, and supports a 16,384 token context window.

Built with a data-quality-first approach, Phi-4 strategically incorporates synthetic training data rather than relying solely on organic web content or code. It excels at math problem-solving, code generation, and multi-step reasoning, optimized for memory and compute-constrained environments.

The model is trained primarily on English text with multilingual capability (about 8% multilingual data), and follows a chat instruction format. It is fully open-weight and available on Hugging Face, making it accessible for commercial and research applications.

## Available routes

Phi-4 runs on 1 route through the Opper gateway. Prices are per 1M tokens. Its route also sells flex processing: the same model at another price, picked per request with service_tier. [How service tiers work](https://docs.opper.ai/build/gateway/service-tiers). Its routes and prices, live from the catalogue, are public JSON with no API key needed at https://api.opper.ai/v3/models?q=deepinfra%2Fmicrosoft%2Fphi-4.

| Provider | Model id | Region | Zero data retention | Training | Input | Output | Cache read |
| --- | --- | --- | --- | --- | --- | --- | --- |
| [DeepInfra](https://opper.ai/provider/deepinfra) | `deepinfra/microsoft/phi-4` | US (United States) | Yes | No | $0.07 | $0.14 | Input price |
| [DeepInfra](https://opper.ai/provider/deepinfra), Flex | `deepinfra:flex/microsoft/phi-4` | US (United States) | Yes | No | $0.06 | $0.11 | $0.06 |

## Key info

- Model id: `deepinfra/microsoft/phi-4`
- Input: Text
- Output: Text
- Features: Tools
- Context window: 16K
- Max output: 16K
- Input price: $0.07 per 1M tokens
- Output price: $0.14 per 1M tokens
- Released: 12 Dec 2024
- US residency available
- Zero data retention on pay-as-you-go
- No training by default

## Data handling per route

Each route hosting Phi-4 has its own privacy posture, residency, and GDPR terms. Postures are maintained by Opper with a last-verification timestamp.

### DeepInfra — United States

Zero data retention: nothing is logged, held for abuse monitoring or used for training. No training on customer data. US; SCCs.

- Zero data retention: Yes. Nothing is logged, held for abuse monitoring or used for training.
- Training: No training on customer data.
- Logging: None
- Abuse monitoring: No classifier
- Transfer mechanism: SCCs

Verified by Opper on 2026-10-19.

## Benchmarks

Independent benchmark scores via [Artificial Analysis](https://artificialanalysis.ai) ([view on AA](https://artificialanalysis.ai/models/phi-4)). Indices and domain scores are out of 100, Omniscience runs from −100 to 100, Briefcase is an Elo rating, and the other evaluation scores are the share of tasks solved.

- Global rank: #436 of 520 LLMs on the [LLM leaderboard](https://opper.ai/llm-leaderboard)
- Tier: Efficient
- Output speed: 40 tok/s
- Intelligence Index (previous version): 5.9

### Coding

- LiveCodeBench: 23%

### Agentic & knowledge work

- Terminal-Bench Hard: 4%
- τ²-Bench Telecom: 0%

### Science & reasoning

- Humanity's Last Exam: 4%
- GPQA Diamond: 57%
- Long-context reasoning: 0%

### Knowledge

- MMLU-Pro: 71%

### Math & instruction following

- AIME 2025: 18%
- IFBench: 24%

## Get started

Call Phi-4 through the Opper gateway with one API key. Opper is drop-in compatible with the OpenAI, Anthropic and Google AI SDKs.

Phi-4 is a premium model on Opper. Sign up needs no credit card: you get an API key straight away and the free models work in the playground and the API. Add a card to use premium models, pay-as-you-go with no minimum.

### Set it up with your agent

Paste this into a coding agent like Claude Code, Cursor or Codex and it will wire up Opper for you:

```text
Use curl to download, read and follow: https://skills.opper.ai Call Phi-4
```

### Or call it directly

OpenAI:

```javascript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.OPPER_API_KEY,
  baseURL: "https://api.opper.ai/v3/compat",
});

const completion = await client.chat.completions.create({
  model: "deepinfra/microsoft/phi-4",
  messages: [{ role: "user", content: "Hello" }],
});
console.log(completion.choices[0].message.content);
```

Anthropic:

```javascript
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  apiKey: process.env.OPPER_API_KEY,
  baseURL: "https://api.opper.ai/v3/compat",
});

const message = await client.messages.create({
  model: "deepinfra/microsoft/phi-4",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hello" }],
});
console.log(message.content);
```

Gemini:

```javascript
import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI({
  apiKey: process.env.OPPER_API_KEY,
  httpOptions: { baseUrl: "https://api.opper.ai/v3/compat" },
});

const response = await ai.models.generateContent({
  model: "deepinfra/microsoft/phi-4",
  contents: "Hello",
});
console.log(response.text);
```

cURL:

```bash
curl https://api.opper.ai/v3/compat/chat/completions \
  -H "Authorization: Bearer $OPPER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepinfra/microsoft/phi-4",
    "messages": [{ "role": "user", "content": "Hello" }]
  }'
```

## Use Phi-4 in your apps

Pick your tool to see how to run it on Phi-4 through Opper.

- [Claude Code](https://opper.ai/apps/claude-code/phi-4)
- [Claude Cowork](https://opper.ai/apps/claude-cowork/phi-4)
- [Codex](https://opper.ai/apps/codex/phi-4)
- [DeepSeek Harness](https://opper.ai/apps/deepseek-harness/phi-4)
- [GitHub Copilot CLI](https://opper.ai/apps/github-copilot-cli/phi-4)
- [Aider](https://opper.ai/apps/aider/phi-4)
- [Goose](https://opper.ai/apps/goose/phi-4)
- [Droid](https://opper.ai/apps/droid/phi-4)
- [OpenCode](https://opper.ai/apps/opencode/phi-4)
- [Pi](https://opper.ai/apps/pi/phi-4)
- [OpenClaw](https://opper.ai/apps/openclaw/phi-4)
- [Hermes](https://opper.ai/apps/hermes/phi-4)
- [Copilot for Obsidian](https://opper.ai/apps/obsidian-copilot/phi-4)
- [OmniRoute](https://opper.ai/apps/omniroute/phi-4)
- [Cursor](https://opper.ai/apps/cursor/phi-4)
- [Cline](https://opper.ai/apps/cline/phi-4)
- [Continue](https://opper.ai/apps/continue/phi-4)
- [Kilo Code](https://opper.ai/apps/kilo-code/phi-4)
- [GitHub Copilot](https://opper.ai/apps/github-copilot/phi-4)
- [Zed](https://opper.ai/apps/zed/phi-4)
- [JetBrains AI Assistant](https://opper.ai/apps/jetbrains-ai-assistant/phi-4)
- [Voidleap Code](https://opper.ai/apps/voidleap-code/phi-4)
- [n8n](https://opper.ai/apps/n8n/phi-4)
- [LibreChat](https://opper.ai/apps/librechat/phi-4)
- [Open WebUI](https://opper.ai/apps/open-webui/phi-4)
- [See all apps](https://opper.ai/apps)

## Other models from Microsoft

- [Multilingual E5 Large](https://opper.ai/microsoft/multilingual-e5-large)
- [Multilingual E5 Large Instruct](https://opper.ai/microsoft/multilingual-e5-large-instruct)
- [WizardLM-2 8x22B](https://opper.ai/microsoft/wizardlm-2-8x22b)
- [Microsoft Decision 1.1](https://opper.ai/microsoft/microsoft-decision-1-1)
- [Microsoft Decision 1](https://opper.ai/microsoft/microsoft-decision-1)
- [Azure Neural HD TTS](https://opper.ai/microsoft/azure-neural-hd-tts)
