By Narasimha Badrinath
When you’re building AI applications, the right tooling makes all the difference. LangChain has been a go-to framework for years, and its rich ecosystem of integrations helps developers move from idea to production very quickly.
With langchain-gradient, the official integration from DigitalOcean for langchain, you can pair DigitalOcean’s Gradient AI’s serverless interface with Langchain’s agent’s, tools, and chaining.
In this guide, you’ll learn why langchain-gradient helps developers improve their agent workflow, how to connect Gradient’s serverless inference to LangChain in minutes, and how to use invoke and stream with concise examples.
The new langchan-gradient integration can improve your workflows in a number of ways:
LangChain has their own documentation on the integration, and there’s also a PyPI package project to help make the integration seamless.
You can also watch a short walkthrough with code examples that shows the integration in action.
To run langchain-gradient, you’ll need to get your key from the DigitalOcean Cloud console first
Export your key as an environment variable:
export DIGITALOCEAN_INFERENCE_KEY="your_key_here"
To install the pacakage, run the following command:
pip install langchain-gradient
import os
from langchain_gradient import ChatGradient
llm = ChatGradient(
model="llama3.3-70b-instruct",
api_key=os.getenv("DIGITALOCEAN_INFERENCE_KEY"),
)
result = llm.invoke(
"Summarize the plot of the movie 'Inception' in two sentences, and then explain its ending."
)
print(result)
from langchain_gradient import ChatGradient
llm = ChatGradient(
model="llama3.3-70b-instruct",
api_key=os.getenv("DIGITALOCEAN_INFERENCE_KEY"),
)
for chunk in llm.stream("Give me three fun facts about octopuses."):
print(chunk, end="", flush=True)
This prints tokens as they arrive, which is perfect for CLIs, notebooks, or chat UIs.
LangChain is a framework for building applications powered by large language models. It provides standard abstractions (chains, tools, agents) and a large ecosystem of integrations to help developers compose end-to-end LLM apps quickly.
It’s the official DigitalOcean integration that lets LangChain apps call Gradient AI’s serverless inference endpoints using a LangChain-compatible ChatGradient client.
You can select from multiple Gradient-hosted models (e.g., Llama variants). Choose a model ID from Gradient’s documentation and pass it to ChatGradient via the model parameter.
Create a model access key in the DigitalOcean Cloud console (Agent Platform → Serverless Inference), then export it as DIGITALOCEAN_INFERENCE_KEY and pass it to ChatGradient.
Yes. Use llm.stream(…) to receive tokens incrementally—ideal for CLIs, notebooks, and chat UIs. Use llm.invoke(…) for simple single-shot calls.
langchain-gradient makes it fast and practical to go from idea to production. With drop-in client, familiar LangChain abstractions, and GPU-accelerated serverless inference on DigitalOcean, you can prototype quickly, stream results in real time, and scale without refactoring. The integration is open-source, flexible, and keeps pace with the latest LangChain and Gradient updates, so you always stay productive.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Get simple AI infrastructure starting at $2.99/GPU/hr on-demand. Try GPU Droplets now!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.