---
title: "Deploying LangChain to Fly.io"
description: "Deploying a minimal LangChain application to Fly.io, using Flask, requires a small Python project that accepts a place and asks an OpenAI-backed model for three places to eat there. The example uses LangChain’s OpenAI wrapper, PromptTemplate, temperature 0.9, and a default Berlin value, while Flask routes requests at / or / and renders the model’s split response in HTML. Local setup includes a virtual environment, pinned Flask, gunicorn, langchain, openai, and python-dotenv dependencies, with OPENAI_API_KEY stored in a local .env file; production uses gunicorn rather than Flask’s development server. Fly launch configures the app name, organization, and deployment region, and fly deploy builds and publishes an image before provisioning machines. The article concludes that more complex, user-dependent requests require LangChain agents and tools, such as Google Places API, because language models lack real-time data and internet browsing."
---

# Deploying LangChain to Fly.io

[Fly.io](https://yomu.fyi/company/fly-io) · May 8, 2023

**Type:** Tutorial

## Summary

Deploying a minimal LangChain application to Fly.io, using Flask, requires a small Python project that accepts a place and asks an OpenAI-backed model for three places to eat there. The example uses LangChain’s OpenAI wrapper, PromptTemplate, temperature 0.9, and a default Berlin value, while Flask routes requests at / or / and renders the model’s split response in HTML. Local setup includes a virtual environment, pinned Flask, gunicorn, langchain, openai, and python-dotenv dependencies, with OPENAI\_API\_KEY stored in a local .env file; production uses gunicorn rather than Flask’s development server. Fly launch configures the app name, organization, and deployment region, and fly deploy builds and publishes an image before provisioning machines. The article concludes that more complex, user-dependent requests require LangChain agents and tools, such as Google Places API, because language models lack real-time data and internet browsing.

## Context

The article explains how to deploy a minimal LangChain application to Fly.io. The application accepts a place, defaulting to Berlin, and generates three dining suggestions through an OpenAI language model.

## Approach / What changed

The implementation combines Flask routes with LangChain’s OpenAI wrapper and PromptTemplate. It uses a Python virtual environment, pinned dependencies, an OPENAI\_API\_KEY environment variable, gunicorn for production, and flyctl commands including fly launch and fly deploy.

## Takeaways

- The Flask application serves both the root route and /, formats the place into “What are the 3 best places to eat in {place}?”, and passes the generated response to the template after splitting it on blank lines.
- The example pins Flask 2.2.3, gunicorn 20.1.0, langchain 0.0.148, openai 0.27.4, and python-dotenv 1.0.0; OPENAI\_API\_KEY is required for the OpenAI wrapper.
- For requests involving current ratings or opening hours, the article points to LangChain agents and tools such as Google Places API, since language models do not provide real-time data or internet browsing.

**Tags:** [Flask](https://yomu.fyi/topic/flask), [Fly.io](https://yomu.fyi/topic/fly-io), [LangChain](https://yomu.fyi/topic/langchain), [Python](https://yomu.fyi/topic/python)

- Source: [Fly.io](https://fly.io/blog/deploying-langchain-to-fly-io)
- Source URL: https://fly.io/blog/deploying-langchain-to-fly-io
- Ingested by Yomu: 2026-09-02T16:00:45.965Z

[Read original post](https://fly.io/blog/deploying-langchain-to-fly-io)
