Phi-3 api
★★★★ 4.1 CE

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

Verified today·4 sources checked

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.

How to build on it

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.

Honest limits
  • 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
View sources

Build with the Phi-3 API

Your first Phi-3 API request

ollama run phi4 / Azure chat completionsbash
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

AspectDetailNotes
Open weightsDownload microsoft/phi-4 from Hugging FaceMIT license; self-host commercially
Local runtimesOllama (ollama run phi4), transformers, llama.cpp / GGUFRuns on a single GPU or a laptop
Hosted authapi-key credential or Authorization: Bearer <key>Azure AI Foundry serverless
Hosted endpoint/chat/completions appended to the base URLOpenAI-compatible route
Prerequisites (hosted)Foundry project + a chat-completions model deploymentAdd Phi-4 to your Foundry resource
SDKOpenAI SDK (max compatibility) or Azure AI Inference SDKFoundry direct models via Chat Completions
Free dev pathGitHub Models for prototypingFree tier before Azure deployment

Core access modes and features

CapabilityHowPurpose
Local run (Ollama)ollama run phi4One-command local inference, no key
transformerspipeline('text-generation', 'microsoft/phi-4')Python self-host with full control
Hosted chatPOST {base}/chat/completionsManaged inference on Azure AI Foundry
OpenAI compatibilityOpenAI SDK against the Foundry endpointReuse existing OpenAI-shaped code
Streamingstream=True on chat completionsStream tokens as generated
Fine-tuningLoRA / full fine-tune on your dataAdapt the small model to a narrow task cheaply
Quantized runGGUF via llama.cpp / OllamaRun on CPU or modest GPUs
Context limit16k tokensShort-context tasks; chunk long inputs

Limits, license and deployment rules

LimitDetailNotes
Context16k tokensSmallest of the set; chunk long inputs
ModalityText onlyUse Phi-4-multimodal for image/audio
LicenseMIT (commercial use allowed)No usage restriction on the open weights
Self-host boundYour hardware (single GPU / laptop)No per-token fee; 14B fits modest VRAM quantized
Hosted prereqFoundry project + model deploymentAdd Phi-4 chat-completions deployment first
Hosted quotasAzure AI Foundry serverless quotasPer resource / region
Knowledge cutoffJune 2024Add retrieval for recent facts

Runtimes, fine-tuning and developer fit

AspectDetailNotes
Local SDKsOllama, Hugging Face transformers, llama.cppNo API key for local runs
Hosted SDKsOpenAI SDK or Azure AI Inference SDKAgainst the Foundry chat-completions endpoint
Fine-tuningCheap LoRA / full fine-tune on a small modelCommon reason to choose Phi over a frontier API
FootprintRuns on a single GPU or laptop (quantized)On-device / edge / air-gapped deployments
VariantsPhi-4-multimodal (image/audio), Phi-4 reasoningPick a variant for modality or reasoning
Best forNarrow, private, short-context tasksNot long-document, agentic or frontier work
API pricing (hosted)$0.13/1M in, $0.50/1M outIndependent 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

Verified by ComparEdgeMethod: Vendor docs, official pages, and selected independent sources
SourceWhat was checkedLast checked
Microsoft PhiOfficial product pageJuly 10, 2026
Artificial AnalysisIndependent referenceJuly 10, 2026
Hugging FaceMicrosoft Phi 4July 10, 2026
Microsoft LearnHow To Deploy Models Phi 4July 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.