
Phi-3 API: Access, Rate Limits & SDKs 2026
Phi-4 is open weights, so there is no single API but two runtimes: self-host the MIT 14B weights, or call Microsoft's OpenAI-compatible Azure AI Foundry endpoint.
Phi-3 API verdict
Phi-4 is an open-weights model, so there is no single API.
There are runtimes. The free path is self-hosting the MIT-licensed 14B weights, downloaded from Hugging Face as microsoft/phi-4.
Choose Phi-4's access path by where you want the model to run. For private, on-device, edge or cost-controlled use, self-host the MIT weights. Options are ollama run phi4 for a one-command start, a transformers pipeline for full control, or GGUF through llama.cpp on modest hardware, with no key and no token bill. You can also fine-tune cheaply for a narrow task. For a managed endpoint, deploy Phi-4 on Azure AI Foundry and call its OpenAI-compatible /chat/completions with the OpenAI SDK, which suits teams already on Azure. Either way, design around the 16k context by chunking long inputs, and around text-only input. Reach for a larger open model or a frontier API when you need long context, multimodality or frontier reasoning.
- There is no first-party Phi API endpoint. You either self-host the open weights or use Microsoft's Azure AI Foundry serverless hosting.
- The hosted path needs Azure setup: a Foundry project and a Phi-4 chat-completions model deployment before you can call /chat/completions.
- The context window is 16k tokens, so long inputs must be chunked, and it is text-only, so use Phi-4-multimodal for image or audio.
- Self-hosted throughput depends entirely on your hardware. The published 34.9 tokens a second is a median hosted figure, not a guarantee.
- Open weights
- microsoft/phi-4 (MIT)
- Local run
- ollama run phi4
- Hosted
- Azure AI Foundry serverless
- Compat
- OpenAI SDK /chat/completions
- Context
- 16k tokens
Build with the Phi-3 API
# Pull and run the 14B model locally, no API key
ollama run phi4 "Explain backpropagation in two sentences"- Cost levers: self-host the MIT weights (no token fee); GGUF quantization for modest hardware; fine-tune for a narrow task instead of a bigger model.
- Handle: 401 (Invalid Azure api-key / Bearer token), 404 (No Phi-4 deployment in the Foundry project).
Real Phi-3 code from the official docs. The raw cURL hello-world is the code block above; full limits and endpoints are in the tables on this page.
Your first Phi-3 API request
ollama run phi4 "Write a short poem about APIs"
# or, hosted on Azure AI Foundry (OpenAI-compatible):
curl https://<resource>.services.ai.azure.com/models/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${AZURE_API_KEY}" \
-d '{"model":"Phi-4","messages":[{"role":"user","content":"Hello, Phi"}]}'How to authenticate with the Phi-3 API
| Aspect | Detail | Notes |
|---|---|---|
| Open weights | Download microsoft/phi-4 from Hugging Face | MIT license; self-host commercially |
| Local runtimes | Ollama (ollama run phi4), transformers, llama.cpp / GGUF | Runs on a single GPU or a laptop |
| Hosted auth | api-key credential or Authorization: Bearer <key> | Azure AI Foundry serverless |
| Hosted endpoint | /chat/completions appended to the base URL | OpenAI-compatible route |
| Prerequisites (hosted) | Foundry project + a chat-completions model deployment | Add Phi-4 to your Foundry resource |
| SDK | OpenAI SDK (max compatibility) or Azure AI Inference SDK | Foundry direct models via Chat Completions |
| Free dev path | GitHub Models for prototyping | Free tier before Azure deployment |
Core access modes and features
| Capability | How | Purpose |
|---|---|---|
| Local run (Ollama) | ollama run phi4 | One-command local inference, no key |
| transformers | pipeline('text-generation', 'microsoft/phi-4') | Python self-host with full control |
| Hosted chat | POST {base}/chat/completions | Managed inference on Azure AI Foundry |
| OpenAI compatibility | OpenAI SDK against the Foundry endpoint | Reuse existing OpenAI-shaped code |
| Streaming | stream=True on chat completions | Stream tokens as generated |
| Fine-tuning | LoRA / full fine-tune on your data | Adapt the small model to a narrow task cheaply |
| Quantized run | GGUF via llama.cpp / Ollama | Run on CPU or modest GPUs |
| Context limit | 16k tokens | Short-context tasks; chunk long inputs |
Limits, license and deployment rules
| Limit | Detail | Notes |
|---|---|---|
| Context | 16k tokens | Smallest of the set; chunk long inputs |
| Modality | Text only | Use Phi-4-multimodal for image/audio |
| License | MIT (commercial use allowed) | No usage restriction on the open weights |
| Self-host bound | Your hardware (single GPU / laptop) | No per-token fee; 14B fits modest VRAM quantized |
| Hosted prereq | Foundry project + model deployment | Add Phi-4 chat-completions deployment first |
| Hosted quotas | Azure AI Foundry serverless quotas | Per resource / region |
| Knowledge cutoff | June 2024 | Add retrieval for recent facts |
Runtimes, fine-tuning and developer fit
| Aspect | Detail | Notes |
|---|---|---|
| Local SDKs | Ollama, Hugging Face transformers, llama.cpp | No API key for local runs |
| Hosted SDKs | OpenAI SDK or Azure AI Inference SDK | Against the Foundry chat-completions endpoint |
| Fine-tuning | Cheap LoRA / full fine-tune on a small model | Common reason to choose Phi over a frontier API |
| Footprint | Runs on a single GPU or laptop (quantized) | On-device / edge / air-gapped deployments |
| Variants | Phi-4-multimodal (image/audio), Phi-4 reasoning | Pick a variant for modality or reasoning |
| Best for | Narrow, private, short-context tasks | Not long-document, agentic or frontier work |
| API pricing (hosted) | $0.13/1M in, $0.50/1M out | Independent cross-reference; self-host is infra-only |
Phi-3 API FAQ
How do I call Phi-4 via API?
Two ways. Self-host the open weights: download microsoft/phi-4 from Hugging Face and run it locally with Ollama, through ollama run phi4, a Hugging Face transformers pipeline, or llama.cpp, with no API key. Or use Microsoft's hosted Azure AI Foundry serverless endpoint: deploy Phi-4 in a Foundry project, then POST to /chat/completions with an api-key or Authorization: Bearer header, callable from the OpenAI SDK.
Is Phi-4 OpenAI-compatible?
On the hosted path, yes. Azure AI Foundry exposes Phi-4 through an OpenAI-compatible chat-completions route, with /chat/completions appended to the base URL and api-key or Bearer auth. Microsoft recommends the OpenAI SDK when maximum OpenAI compatibility or lowest latency is required. Locally, you use the runtime's own interface, whether Ollama's API, transformers, or llama.cpp.
Can I run Phi-4 locally, and is it free?
Yes. Phi-4 is open weights under the MIT license, so the 14-billion-parameter model is free to download and run on your own hardware. A single GPU or even a laptop works when quantized to GGUF, with no per-token fee and no usage restriction, since commercial use is allowed. This is the model's main appeal: private, local, cheap inference and easy fine-tuning.
What are the limits of the Phi-4 API?
The model's own limits apply on every path. The context window is 16k tokens, the smallest of the leading set, so chunk long inputs. Input is text-only, so use the separate Phi-4-multimodal variant for image or audio. Self-hosting is bounded only by your hardware. The hosted Azure path adds a Foundry project and model-deployment prerequisite, plus Azure AI Foundry serverless quotas.
Should I self-host Phi-4 or use the hosted endpoint?
Self-host when you want privacy, on-device or edge deployment, no token bill, or cheap fine-tuning, since the MIT weights run on modest hardware. Use the Azure AI Foundry hosted endpoint when you want a managed, OpenAI-compatible API without operating infrastructure, especially if you are already on Azure. The hosted output price, at $0.50 per 1M, is on the expensive side for the model's size, which further favours self-hosting at volume.
Sources & verification
| Source | What was checked | Last checked |
|---|---|---|
| Microsoft Phi | Official product page | July 10, 2026 |
| Artificial Analysis | Independent reference | July 10, 2026 |
| Hugging Face | Microsoft Phi 4 | July 10, 2026 |
| Microsoft Learn | How To Deploy Models Phi 4 | July 10, 2026 |
Every fact on this Phi-3 page is tied to a named source and a verification date. Freshness-sensitive figures trace to the sources above; verify against the vendor before relying on them.
Explore Phi-3
Every page on Phi-3 in one place, you are on api.
