Foundry Local SDK

1.0.0 · active · verified Thu Apr 16

Foundry Local SDK for Python provides a control-plane interface to Foundry Local, a unified on-device AI runtime that enables local generative AI inference. It allows developers to interact with locally run models, perform chat completions, and manage local AI resources without network latency or per-token costs. The current version is 1.0.0, and it has moved to General Availability, suggesting a stable, but potentially evolving, release cadence.

Common errors

Warnings

Install

Imports

Quickstart

Initializes the Foundry Local client and performs a simple chat completion using a locally available model. Before running, ensure the Foundry Local runtime is installed and running, and a model (e.g., `phi3-mini-4k-instruct`) has been downloaded via the `foundry` CLI.

from foundry import FoundryLocal
import os

# Ensure the Foundry Local runtime is installed and running.
# For example, download the 'phi3-mini-4k-instruct' model via the Foundry Local CLI:
# foundry download phi3-mini-4k-instruct

try:
    client = FoundryLocal()
    # You might need to explicitly download a model if not already present.
    # client.download_model("phi3-mini-4k-instruct") # Uncomment and run once if needed

    print("FoundryLocal client initialized. Attempting chat completion...")
    response = client.chat.completions.create(
        model="phi3-mini-4k-instruct", # Replace with a model you have downloaded
        messages=[
            {"role": "user", "content": "What is the capital of France?"}
        ],
        max_tokens=50
    )
    print("Response:", response.choices[0].message.content)
except Exception as e:
    print(f"An error occurred: {e}")
    print("Please ensure the Foundry Local runtime is installed, running, and the specified model is downloaded.")

view raw JSON →