---
title: Microsoft: Phi 4 API | Text Generation | ModelsLab
description: Build with Microsoft: Phi 4 API by Microsoft. Text generation, chat, code, and reasoning. Pay-per-use. Free tier.
url: https://modelslab.com/models/microsoft/microsoft-phi-4/api.md
canonical: https://modelslab.com/models/microsoft/microsoft-phi-4/api.md
type: product
component: Playground/LLM/Index
generated_at: 2026-04-15T04:00:28.969461Z
---

Microsoft: Phi 4
---

 [LLMs.txt](https://modelslab.com/models/open_router/microsoft-phi-4/llms.txt) [.md](https://modelslab.com/models/microsoft/microsoft-phi-4.md)

microsoft-phi-4 microsoft Closed Source Model $0.102500 / call

Microsoft: Phi 4
---

Choose a prompt below to get started or type your own message

 Explain quantum computing in simple terms

 Write a Python function to sort a list

 Create a marketing email for a SaaS product

 Compare REST vs GraphQL APIs

Send

### Microsoft: Phi 4

microsoft microsoft-phi-4

Copy model ID

PricingInput $0.065 / 1M tokens

Output $0.14 / 1M tokens

API EndpointsOpenAI Compatible

`https://modelslab.com/api/v7/llm/chat/completions`Endpoint

Anthropic Compatible

`https://modelslab.com/api/v7/llm/v1/messages`Messages

`https://modelslab.com/api/v7/llm/v1/messages/count_tokens`Count Tokens

`https://modelslab.com/api/v7/llm/v1/models`Models

Use with Claude Code

cURL Example

ParametersSystem MessageYou are a helpful AI assistant specialized in providing accurate and detailed responses.

Temperature0.7

Max Tokens1000

Top P0.9

Frequency Penalty0

Presence Penalty0

Model Info

Support

Related Models
---

Discover similar models you might be interested in

 [View all LLM Models](https://modelslab.com/models?feature=llmaster)

[NH](https://modelslab.com/models/open_router/nousresearch-hermes-2-pro-llama-3-8b)[Open Router](https://modelslab.com/models/open_router)

 [NousResearch: Hermes 2 Pro - Llama-3 8B

Closed Source Model](https://modelslab.com/models/open_router/nousresearch-hermes-2-pro-llama-3-8b)

[QQ](https://modelslab.com/models/open_router/qwen-qwen3-30b-a3b)[Open Router](https://modelslab.com/models/open_router)

 [Qwen: Qwen3 30B A3B

Closed Source Model](https://modelslab.com/models/open_router/qwen-qwen3-30b-a3b)

[Q7](https://modelslab.com/models/together_ai/Qwen-Qwen2.5-7B-Instruct-Turbo)[Together AI](https://modelslab.com/models/together_ai)

 [Qwen2.5 7B Instruct Turbo

Closed Source Model](https://modelslab.com/models/together_ai/Qwen-Qwen2.5-7B-Instruct-Turbo)

[AC](https://modelslab.com/models/open_router/anthropic-claude-3.5-haiku)[Open Router](https://modelslab.com/models/open_router)

 [Anthropic: Claude 3.5 Haiku

Closed Source Model](https://modelslab.com/models/open_router/anthropic-claude-3.5-haiku)

[AN](https://modelslab.com/models/open_router/amazon-nova-micro-v1)[Open Router](https://modelslab.com/models/open_router)

 [Amazon: Nova Micro 1.0

Closed Source Model](https://modelslab.com/models/open_router/amazon-nova-micro-v1)

[GG](https://modelslab.com/models/open_router/google-gemini-3.1-pro-preview-customtools)[Open Router](https://modelslab.com/models/open_router)

 [Google: Gemini 3.1 Pro Preview Custom Tools

Closed Source Model](https://modelslab.com/models/open_router/google-gemini-3.1-pro-preview-customtools)

[QQ](https://modelslab.com/models/open_router/qwen-qwq-32b)[Open Router](https://modelslab.com/models/open_router)

 [Qwen: QwQ 32B

Closed Source Model](https://modelslab.com/models/open_router/qwen-qwq-32b)

[CV](https://modelslab.com/models/together_ai/deepcogito-cogito-v2-1-671b)[Together AI](https://modelslab.com/models/together_ai)

 [Cogito v2.1 671B

Closed Source Model](https://modelslab.com/models/together_ai/deepcogito-cogito-v2-1-671b)

[QQ](https://modelslab.com/models/open_router/qwen-qwen3-235b-a22b-2507)[Open Router](https://modelslab.com/models/open_router)

 [Qwen: Qwen3 235B A22B Instruct 2507

Closed Source Model](https://modelslab.com/models/open_router/qwen-qwen3-235b-a22b-2507)

[NN](https://modelslab.com/models/open_router/nvidia-nemotron-3-nano-30b-a3b)[Open Router](https://modelslab.com/models/open_router)

 [NVIDIA: Nemotron 3 Nano 30B A3B

Closed Source Model](https://modelslab.com/models/open_router/nvidia-nemotron-3-nano-30b-a3b)

[GG](https://modelslab.com/models/open_router/google-gemma-3-12b-it-free)[Open Router](https://modelslab.com/models/open_router)

 [Google: Gemma 3 12B (free)

Closed Source Model](https://modelslab.com/models/open_router/google-gemma-3-12b-it-free)

[OG](https://modelslab.com/models/open_router/openai-gpt-5.1)[Open Router](https://modelslab.com/models/open_router)

 [OpenAI: GPT-5.1

Closed Source Model](https://modelslab.com/models/open_router/openai-gpt-5.1)

[QQ](https://modelslab.com/models/open_router/qwen-qwen2.5-vl-32b-instruct)[Open Router](https://modelslab.com/models/open_router)

 [Qwen: Qwen2.5 VL 32B Instruct

Closed Source Model](https://modelslab.com/models/open_router/qwen-qwen2.5-vl-32b-instruct)

[AA](https://modelslab.com/models/arcee_ai/arcee_ai-arcee-spotlight)[ModelsLab](https://modelslab.com/models/arcee_ai)

 [Arcee AI Spotlight

Closed Source Model](https://modelslab.com/models/arcee_ai/arcee_ai-arcee-spotlight)

[L3](https://modelslab.com/models/meta/nvidia-Llama-3.1-Nemotron-70B-Instruct-HF)[ModelsLab](https://modelslab.com/models/meta)

 [Llama 3.1 Nemotron 70B Instruct HF

Closed Source Model](https://modelslab.com/models/meta/nvidia-Llama-3.1-Nemotron-70B-Instruct-HF)

[OG](https://modelslab.com/models/open_router/openai-gpt-4.1-nano)[Open Router](https://modelslab.com/models/open_router)

 [OpenAI: GPT-4.1 Nano

Closed Source Model](https://modelslab.com/models/open_router/openai-gpt-4.1-nano)

[QQ](https://modelslab.com/models/open_router/qwen-qwen3-coder-plus)[Open Router](https://modelslab.com/models/open_router)

 [Qwen: Qwen3 Coder Plus

Closed Source Model](https://modelslab.com/models/open_router/qwen-qwen3-coder-plus)

[AC](https://modelslab.com/models/open_router/anthropic-claude-opus-4.1)[Open Router](https://modelslab.com/models/open_router)

 [Anthropic: Claude Opus 4.1

Closed Source Model](https://modelslab.com/models/open_router/anthropic-claude-opus-4.1)

About Microsoft: Phi 4
---

\[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...

### Technical Specifications

Model IDmicrosoft-phi-4CategoryLLM ModelsTaskText GenerationPrice$0.102500 per million tokensAddedFebruary 20, 2026

### Key Features

- Chat completion and multi-turn conversation API
- Streaming response with token-by-token output
- Function calling and tool use support
- System prompts and role-based messaging
- JSON mode and structured output

### Quick Start

Integrate Microsoft: Phi 4 into your application with a single API call. Get your API key from the [pricing page](https://modelslab.com/pricing) to get started.

PythonJavaScriptcURLPHP

```
<code>import requests
import json

url = "https://modelslab.com/api/v7/llm/chat/completions"

headers = {
    "Content-Type": "application/json"
}

data = {
        "model_id": "microsoft-phi-4",
        "messages": [
            {
                "role": "user",
                "content": "Hello!"
            }
        ],
        "max_tokens": 1000,
        "key": "YOUR_API_KEY"
    }

try:
    response = requests.post(url, headers=headers, json=data)
    response.raise_for_status()  # Raises an HTTPError for bad responses (4XX or 5XX)
    result = response.json()
    print("API Response:")
    print(json.dumps(result, indent=2))
except requests.exceptions.HTTPError as http_err:
    print(f"HTTP error occurred: {http_err} - {response.text}")
except Exception as err:
    print(f"Other error occurred: {err}")</code>
```

View the [full API documentation](https://modelslab.com/models/microsoft/microsoft-phi-4/api) for SDKs, code examples in Python, JavaScript, and more.

### Pricing

Microsoft: Phi 4 API costs $0.102500 per million tokens. Pay only for what you use with no minimum commitments. [View pricing plans](https://modelslab.com/pricing)

### Use Cases

- AI chatbots and virtual assistants
- Code generation and developer tools
- Content writing and copywriting automation
- Data analysis, summarization, and extraction

[Browse LLM Models](https://modelslab.com/models?feature=llmaster) [More from Microsoft](https://modelslab.com/models/open_router) [View Pricing](https://modelslab.com/pricing)

Microsoft: Phi 4 FAQ
---

### What is Microsoft: Phi 4?

\[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...

### How do I use the Microsoft: Phi 4 API?

You can integrate Microsoft: Phi 4 into your application with a single API call. Sign up on ModelsLab to get your API key, then use the model ID "microsoft-phi-4" in your API requests. We provide SDKs for Python, JavaScript, and cURL examples in the API documentation.

### How much does Microsoft: Phi 4 cost?

Microsoft: Phi 4 costs $0.102500 per million tokens. ModelsLab uses pay-per-use pricing with no minimum commitments. A free tier is available to get started.

### What is the Microsoft: Phi 4 model ID?

The model ID for Microsoft: Phi 4 is "microsoft-phi-4". Use this ID in your API requests to specify this model.

### Does Microsoft: Phi 4 have a free tier?

Yes, ModelsLab offers a free tier that lets you try Microsoft: Phi 4 and other AI models. Sign up to get free API credits and start building immediately.

---

*This markdown version is optimized for AI agents and LLMs.*

**Links:**
- [Website](https://modelslab.com)
- [API Documentation](https://docs.modelslab.com)
- [Blog](https://modelslab.com/blog)

---
*Generated by ModelsLab - 2026-04-15*