Phi 4
By Microsoft. 14.7 billion parameters, a context window of 16,384 tokens and the licence mit.
Facts
- Released
- 2024-12-11 the day the repository was first published on Hugging Face Hugging Face, read
- Licence
- mit the licence the model card declares Hugging Face, read
- Open weights
- Yes the weights are published in this Hugging Face repository Hugging Face, read
- Parameters
- 14.7 billion counted from the safetensors weight files Hugging Face, read
- Active parameters
- Unknown
- Knowledge cutoff
- 2024-06-30 the knowledge cutoff OpenRouter lists OpenRouter, read
- Context window
- 16,384 tokens the maximum position embeddings in the model configuration model configuration, read
- 16,384 tokens the context length OpenRouter lists OpenRouter, read
- Longest output
- 14,745 tokens the largest output OpenRouter's first provider allows OpenRouter, read
- Tool calling
- No the chat template in the tokenizer configuration has no place for tool definitions Hugging Face, read
- No OpenRouter does not list tools among the supported parameters OpenRouter, read
- Structured output
- Yes OpenRouter lists structured outputs among the supported parameters OpenRouter, read
- Reasoning controls
- Unknown
- Inputs and outputs
- text in, text out Hugging Face, read
- Good for
- No source names a use.
Prices
| Provider | Input | Output | Context | As of | Source |
|---|---|---|---|---|---|
| DeepInfra through OpenRouter | 0.070 USD | 0.140 USD | 16,384 | OpenRouter endpoints, read | |
| Kilo Gateway direct | 0.070 USD | 0.140 USD | 16,384 | older than 30 days; check the provider | models.dev, read |
| OpenRouter direct | 0.070 USD | 0.140 USD | 16,384 | older than 30 days; check the provider | models.dev, read |
Run it on your own hardware
Weights are the sizes of the files a source lists, or an estimate from the parameter count where none does. Memory is an estimate: weights plus KV cache plus 512 MiB and 5 percent of the weights for runtime buffers. Check it against your hardware.
| Quantization | Weights | Memory at 8,192 tokens | Memory at 32,768 tokens |
|---|---|---|---|
| Q2_K | 5.2 GiB | 7.5 GiB | Beyond its context |
| Q3_K_S | 6.1 GiB | 8.4 GiB | Beyond its context |
| Q3_K_M | 6.9 GiB | 9.3 GiB | Beyond its context |
| Q3_K_L | 7.4 GiB | 9.8 GiB | Beyond its context |
| Q4_K_S | 7.9 GiB | 10.3 GiB | Beyond its context |
| Q4_K_M | 8.4 GiB | 10.9 GiB | Beyond its context |
| Q5_K_S | 9.5 GiB | 12.0 GiB | Beyond its context |
| Q5_K_M | 9.9 GiB | 12.4 GiB | Beyond its context |
| Q6_K | 11.2 GiB | 13.8 GiB | Beyond its context |
| Q8_0 | 14.5 GiB | 17.3 GiB | Beyond its context |
Start it with a local runtime
- Ollama
ollama run hf.co/MaziyarPanahi/phi-4-GGUF:Q4_K_S - LM Studio
lms get MaziyarPanahi/phi-4-GGUF lms server start - llama.cpp server
llama-server -hf MaziyarPanahi/phi-4-GGUF:Q4_K_S --jinja - vLLM
vllm serve microsoft/phi-4 - SGLang
sglang serve --model-path microsoft/phi-4 --port 30000
Use it from your harness
Set up for Kilo Gateway with the model microsoft/phi-4. Each endpoint page has the same setup for its own address.
OpenCode
Put this in opencode.json in your project folder:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"kilo": {
"npm": "@ai-sdk/openai-compatible",
"name": "Kilo Gateway",
"options": {
"baseURL": "https://api.kilo.ai/api/gateway",
"apiKey": "{env:KILO_API_KEY}"
},
"models": {
"microsoft/phi-4": {
"name": "Phi 4",
"limit": {
"context": 16384,
"output": 14745
}
}
}
}
}
}- OpenCode reads any OpenAI-compatible address through the @ai-sdk/openai-compatible package, and an address that speaks the Responses API through @ai-sdk/openai.
From OpenCode documentation, read .
Pi
Put this in ~/.pi/agent/models.json:
{
"providers": {
"kilo": {
"baseUrl": "https://api.kilo.ai/api/gateway",
"api": "openai-completions",
"apiKey": "$KILO_API_KEY",
"models": [
{
"id": "microsoft/phi-4"
}
]
}
}
}- The apiKey field can name an environment variable as $NAME.
From Pi documentation, read .
Codex
Codex speaks only the Responses API, and Kilo Gateway documents no Responses address. A gateway that offers one can sit in between.
- Codex speaks the Responses API only: responses is the one supported wire API of a custom provider. Ollama and LM Studio are built in and start with --oss.
From Codex documentation, read .
Claude Code
Claude Code sends Anthropic Messages requests, and Kilo Gateway documents no such address. A gateway that translates to that API can sit in between.
- Claude Code sends Anthropic Messages requests to ANTHROPIC_BASE_URL. Anthropic says it does not support routing Claude Code to models other than Claude through any gateway, so some features may not work with another model.
From Claude Code documentation, read .
Other ways to reach it
- OpenRouter, model
microsoft/phi-4 - Ollama, model
hf.co/MaziyarPanahi/phi-4-GGUF:Q4_K_S
Published results
These are results other people published. Baltor did not run them and does not rank models by them.
- Results the maker published on the model card published by microsoft Hugging Face, read
Sources of this page
Paid links
No link in this directory is a paid link or an ad, and no listing is paid for. The order and the contents of every list come from the sources named on this page.