You can use LangChain Python SDK to interact with FriendliAI.
This makes migration of existing applications already using LangChain particularly easy.
How to Use
Before you start, ensure you’ve already obtained the API_KEY from the Friendli Suite > Personal Settings > API Keys.
FriendliAI is fully compatible with OpenAI, so you can use the langchain-openai package by pointing it at the FriendliAI baseURL.
Instantiation
Now you can instantiate the model object and generate chat completions.
Choose the example for your endpoint type:
Runnable Interface
FriendliAI supports both synchronous and asynchronous runnable methods to generate a response.
Synchronous Methods
Asynchronous Methods
Chaining
You can chain the model with a prompt template.
Prompt templates convert raw user input to better input to the LLM.
To get the string value instead of the message, add an output parser to the chain.
Describe tools and their parameters, and let the model return a tool to invoke with the input arguments.
Tool calling is extremely useful for enhancing the model’s capability to provide more comprehensive and actionable responses.
Use the @tool decorator to define a tool.
If you set parse_docstring=True, the tool will parse the docstring to extract the information of arguments.
Now models can generate a tool calling response.
Use the tool call results to generate a message.
For more information on how to use tools, check out the LangChain documentation. Last modified on September 9, 2026