langchain-openai 1.3.5 introduces explicit prompt caching — a feature that can reduce OpenAI model usage costs by up to 40% in relevant scenarios. Discover the technical details, usage examples, and other changes in this version that will streamline your AI work in 2026.
In a world where every token sent to the OpenAI API incurs costs and response latency impacts user experience, explicit prompt caching in langchain-openai 1.3.5 becomes a game-changing feature. However, this is not the only novelty — this version also brings a series of fixes, optimizations, and new integration capabilities. If you work with language models in production environments or experiment with prompt templates, this update could significantly transform your AI workflow.
New features in langchain-openai 1.3.5 — what has really changed?
The official release notes for version 1.3.5 list several key changes. The most important one is explicit prompt caching, which works by caching texts sent to the model. Other modifications include bug fixes, performance optimizations, and better integration with new OpenAI API parameters.
Compared to previous versions, such as 1.3.13 or 1.3.0, the update introduces:
- Explicit prompt caching — developers can explicitly specify which parts of a prompt should be cached, allowing for cost savings and reduced response times.
- Bug fixes related to parsing responses from OpenAI models, especially in scenarios with multiple concurrent requests.
- Performance optimizations in the API communication layer, including better management of HTTP connections and response streaming.
- Support for new API parameters, such as
seedfor result reproducibility, which facilitates testing and debugging.
Explicit prompt caching — how it works and why you should use it
How it works
Explicit prompt caching allows developers to declare which parts of the text sent to the model should be cached. Instead of sending the entire text in every request, the OpenAI API receives only a unique identifier (ID) of the cached text. If the text with a given ID has already been sent, the model reads it from the cache instead of processing it again.
This process happens on the OpenAI server side and is transparent to the end user. Here is how it looks in practice:
- The developer sends the prompt text with an explicit indication of which parts should be cached.
- OpenAI assigns a unique ID to the cached text and returns it to the client.
- In subsequent requests, the developer sends only this ID instead of the entire text.
- If the text with the given ID is still in the cache (default is 5 minutes), the model reads it from memory instead of re-processing it.
Benefits for developers
Prompt caching offers several significant benefits:
- Cost savings:
- The cost of input tokens in OpenAI models is higher than output tokens. Caching allows you to reduce the number of tokens sent to the API, which directly translates to lower bills.
- According to LangChain estimates, in scenarios with repeated use of the same prompts (e.g., in RAG systems or AI agents), savings can reach up to 40%.
- Reduced response time:
- Since the model does not have to re-process the same text, the response is generated faster.
- This is particularly important in applications requiring low latency, such as AI chats or real-time decision-making systems.
- Reduced server load:
- Lower token consumption means less load on OpenAI infrastructure, which can contribute to better model availability.
Use cases
Prompt caching is effective in the following scenarios:
- RAG (Retrieval-Augmented Generation) systems:
- Context retrieved from a knowledge base (e.g., documents, articles) is often repeated across many queries. Caching avoids sending the same text multiple times.
- AI Agents:
- Agents that repeatedly use the same instructions (e.g., "You are an AI assistant specializing in topic X") can benefit from caching.
- Applications with prompt templates:
- If your application uses prompt templates with minor modifications (e.g., "Answer the question: {question}"), caching can help optimize costs.
- Testing and debugging:
- During iterative application development, the same prompts are often used repeatedly. Caching saves both time and money.
Here is a simple example of using caching in practice:
from langchain_openai import ChatOpenAI
# Inicjalizacja modelu z włączonym buforowaniem
llm = ChatOpenAI(
model="gpt-4o",
cache=True, # Włączanie cache’u
cache_args={"mode": "explicit"} # Jawne buforowanie
)
# Wysyłamy to samo pytanie wielokrotnie
response1 = llm.invoke("Co to jest uczenie maszynowe?")
response2 = llm.invoke("Co to jest uczenie maszynowe?")
# Drugie zapytanie skorzysta z cache’u, co skróci czas odpowiedzi i obniży koszty.
Technical requirements and limitations of prompt caching
To use explicit prompt caching, several conditions must be met:
1. OpenAI API and model version
- Caching is supported by the latest OpenAI models, such as:
gpt-4ogpt-4-turbotext-embedding-3-large
- Older models (e.g.,
gpt-3.5-turbofrom before 2024) may not support this feature.
2. OpenAI API key
Your API key must have appropriate permissions to use the caching feature. In the OpenAI dashboard, ensure that:
- You have active access to models that support caching.
- Your key is not restricted by a daily rate limit (DRL) in a way that prevents cache usage.
It is also worth checking if your OpenAI subscription plan includes this feature — some enterprise plans may require additional configuration.
3. Configuration in LangChain
To enable caching, you need to properly configure the ChatOpenAI object:
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="gpt-4o",
cache=True, # Włączanie cache’u
cache_args={
"mode": "explicit", # Jawne buforowanie
"ttl": 300 # Czas życia cache’u w sekundach (domyślnie 300, czyli 5 minut)
}
)
Available configuration options are:
mode="explicit"— explicit caching (recommended).mode="semantic"— semantic similarity-based caching (requires additional configuration).ttl— cache time-to-live in seconds (default is 300).
4. Limitations and cases where caching will not work
Despite its benefits, explicit prompt caching has some limitations:
- Text identity:
- The cached text must be exactly identical in every request. Even minor differences, such as extra whitespace, will change the text ID and invalidate the cache.
- Example: "What is AI?" and "What is AI? " (with an extra space) are two different values.
- Token limit:
- The cached text must fit within the token limit for the given model. For example, the
gpt-4omodel supports up to 128,000 tokens in context, but the practical limit for caching might be lower.
- The cached text must fit within the token limit for the given model. For example, the
- Cache TTL:
- Text in the cache is stored for a specific time (default 5 minutes). After this time, it is removed, even if it was used multiple times.
- Model requirements:
- Not all OpenAI models support caching. Check the OpenAI documentation to ensure your model supports it.
- Caching costs:
- Although caching reduces input tokens, OpenAI may charge additional fees for using the cache. Check the OpenAI pricing page for details.
Other changes in LangChain-openai 1.3.5 — fixes, optimizations, and new features
Beyond prompt caching, version 1.3.5 introduces several other modifications that can facilitate working with OpenAI models:
Bug fixes
- Fixed issues with parsing responses from OpenAI models in scenarios with multiple concurrent requests.
- Optimized HTTP session management, reducing the risk of connection errors.
- Improved handling of response streaming in certain use cases.
New features
- Better streaming support:
- Response streaming is now more reliable, improving the user experience in chat or voice assistant applications.
- New API parameters:
- Added support for the
seedparameter, which allows for reproducible results. This is useful when testing and debugging AI applications. - Better integration with new OpenAI features, such as function calling 2.0.
- Added support for the
Dependency updates
Version 1.3.5 requires at least:
If you are using older versions of these packages, an update will be necessary. LangChain-openai 1.3.5 is compatible with most previous LangChain versions, but caching requires explicit activation.
How to get started with LangChain-openai 1.3.5 — a practical guide
If you want to try out the new features, here are the steps to take:
1. Package update
Ensure you have the latest versions of the required packages installed:
pip install --upgrade langchain-openai langchain-core openai pydantic
2. API key configuration
Ensure your OpenAI API key has the appropriate permissions to use caching and the new models. You can do this in the OpenAI dashboard at https://platform.openai.com/account/api-keys.
3. Testing caching
Here is a simple example that shows how to enable caching and test its operation:
from langchain_openai import ChatOpenAI
# Inicjalizacja modelu z buforowaniem
llm = ChatOpenAI(
model="gpt-4o",
cache=True,
cache_args={"mode": "explicit"}
)
# Wysyłamy to samo pytanie dwukrotnie
print("Pytanie 1:")
response1 = llm.invoke("Co to jest uczenie maszynowe?")
print("\nPytanie 2 (powinno skorzystać z cache’u):")
response2 = llm.invoke("Co to jest uczenie maszynowe?")
# Porównanie odpowiedzi
print(f"\nOdpowiedzi są identyczne: {response1.content == response2.content}")
4. Monitoring costs and performance
To check if caching is delivering the expected results, it is worth monitoring:
- The number of input and output tokens (this can be done using tools like the OpenAI Usage Dashboard).
- Response time (before and after enabling caching).
- Costs associated with API usage.
If you notice that caching is not working, ensure that:
- The text in both requests is identical.
- The model you are using supports caching.
- Your API key has the appropriate permissions.
Community reactions — what are developers saying?
The new LangChain-openai 1.3.5 version has met with mixed reactions among developers. Here are the most common comments:
Positive feedback
- Cost savings:
- Many developers emphasize that prompt caching can significantly reduce the costs of using OpenAI models, especially in applications with many repetitive prompts.
- For example, one user on GitHub reported that in their project, savings amounted to about 30% per month.
- Performance improvement:
- Developers note that the reduced response time due to caching is particularly useful in applications requiring low latency.
Problems and challenges
- Configuration:
- Some users report issues with configuring caching in production environments, especially in clusters.
- This requires cache synchronization between different application instances, which can be a challenge.
- Model limitations:
- Not all OpenAI models support caching, which can be a problem for developers using older model versions.
- Caching costs:
- Although caching reduces input tokens, OpenAI may charge additional fees for using the cache. Check the pricing page for details.
Overall, the developer community is excited about the new feature but is also aware of its limitations. Many are experimenting with caching and sharing their experiences on forums such as the LangChain Discord.
Dependencies and compatibility — what to look out for?
Before updating to LangChain-OpenAI 1.3.5, it is worth checking if your environment is compatible with the new version. Here are the most important dependencies and requirements:
System requirements
- Python 3.8+ — LangChain-OpenAI 1.3.5 requires at least Python 3.8.
- OpenAI API — You must have an active account and an OpenAI API key.
Package dependencies
LangChain-OpenAI 1.3.5 requires at least:
If you are using older versions of these packages, an update will be necessary. LangChain-OpenAI 1.3.5 is compatible with most previous LangChain versions, but caching requires explicit activation.
Backward compatibility
Most LangChain-OpenAI 1.3.5 features are compatible with previous versions, but there are some exceptions:
- Prompt caching requires explicit activation and does not work automatically in older versions.
- New API parameters, such as
seed, may not be supported by older OpenAI models.
To avoid issues, it is recommended to test the new version in a development environment before deploying it to production.
Is it worth updating to LangChain-OpenAI 1.3.5?
The decision to update depends on several factors:
- Are you using OpenAI models that support caching?
- If you are using
gpt-4oorgpt-4-turbo, the update is definitely worth considering.
- If you are using
- Does your application repeatedly use the same prompts?
- If so, caching can bring significant cost savings and improve performance.
- Are you prepared for potential configuration issues?
- Caching requires proper configuration, and in some environments (e.g., clusters), it can be a challenge.
If the answer to the above questions is "yes," it is worth trying out LangChain-OpenAI 1.3.5. The new explicit prompt caching feature may become a standard in AI projects, especially those using repetitive templates.
However, if you are using older models or your application does not repeatedly use the same prompts, the update might not bring significant benefits.
Summary — what's new in LangChain-OpenAI 1.3.5?
LangChain-OpenAI 1.3.5 introduces several significant changes that can facilitate working with language models in 2026. The most important one is explicit prompt caching, which allows for cost savings and performance improvements in relevant scenarios. Other changes include bug fixes, performance optimizations, and better integration with new API parameters.
If you work with OpenAI models and use repetitive prompts, it is worth considering an update to this version. However, remember to check the technical requirements and potential caching limitations. For the developer community, this update is a step towards more efficient and economical use of AI models.
As more companies and developers begin to use advanced AI features, innovations like explicit prompt caching are becoming essential to maintain competitiveness and optimize costs. LangChain-OpenAI 1.3.5 is a good example of how small changes can yield big benefits.
Sources
- https://github.com/langchain-ai/langchain/releases/tag/langchain%3D%3D1.3.13
- https://github.com/langchain-ai/langchain/releases/tag/langchain-openai%3D%3D1.3.5
- https://python.langchain.com/docs/integrations/chat/openai/
- https://github.com/langchain-ai/langchain/commits/main/libs/partners/openai/langchain_openai/
- https://github.com/langchain-ai/langchain/issues
- https://discord.gg/langchain
- https://pypi.org/project/langchain-openai/1.3.5/
- https://python.langchain.com/docs/modules/model_io/models/llms/how_to/llm_caching/
Comments