Using Phi-2 on Replicate API

Implementation guide · Phi-2 · Microsoft Research

ServerlessOpen Source

Replicate API exposes Phi-2 through model ID lucataco/phi-2. Use the setup steps, sourced pricing, capabilities, and official provider links below to validate this route before deployment.

Last refreshed 2026-05-19. Next refresh: weekly.

Quick Start

  1. 1
    Create an account at Replicate API and generate an API key.
  2. 2
    Use the Replicate API SDK or REST API to call lucataco/phi-2 — see the documentation for request format.
  3. 3
    You'll be billed $0.05/1M input, $0.25/1M output tokens. See full pricing.

Code Examples

Install
pip install replicate
API key
REPLICATE_API_TOKEN
Model ID
lucataco/phi-2

Replicate uses "owner/model-name" format (e.g. "meta/meta-llama-3-8b-instruct") for the latest version, or "owner/model-name:version-sha" to pin to a specific version. The REST endpoint splits owner and model-name into the path: /v1/models/{owner}/{model-name}/predictions.

import replicate

# reads REPLICATE_API_TOKEN from env
# lucataco/phi-2 format: "owner/model-name" (latest version) or "owner/model-name:version-hash"
output = replicate.run(
    "lucataco/phi-2",
    input={"prompt": "Hello"}
)
# Output is a list or generator depending on the model
print("".join(output))

Pricing on Replicate API

TypePrice (per 1M)
Input tokens$0.05
Output tokens$0.25

Capabilities

Structured Outputs

About Phi-2

Phi-2 is a compact language model by Microsoft endowed with 2.7 billion parameters and part of their Phi series. It shows formidable capabilities in reasoning and language understanding, outshining much larger models, even those with up to 25 times more parameters. Phi-2's training utilized a vast and diverse dataset of 1.4 trillion tokens, incorporating high-quality synthetic data and curated web content to bolster its common sense reasoning and general knowledge. Interestingly, despite lacking fine-tuning via reinforcement learning from human feedback (RLHF), it exhibits enhanced safety features and reduced bias.

Model Specs

Released2023-12-12
Parameters2.7B
Context2k
ArchitectureDecoder Only

Provider

Replicate API

Replicate

San Francisco, California, United States