Langchain SDK
Since Langchain already provides multi-provider abstraction and chaining capabilities, DeepintShield adds enterprise features like governance, semantic caching, MCP tools, observability, etc, on top of your existing setup.
Endpoint: /langchain
Install with the LangChain extra:
pip install "deepintshield[langchain]"from deepintshield import DeepintShieldfrom langchain_core.messages import HumanMessage
shield = DeepintShield(virtual_key="sk-bf-your-virtual-key")llm = shield.langchain(model="gpt-4o-mini") # pre-wired ChatOpenAI
response = llm.invoke([HumanMessage(content="Hello!")])print(response.content)from langchain_openai import ChatOpenAIfrom langchain_core.messages import HumanMessage
llm = ChatOpenAI( model="gpt-4o-mini", openai_api_base="https://app.deepintshield.com/langchain", openai_api_key="sk-bf-your-virtual-key", default_headers={"x-bf-vk": "sk-bf-your-virtual-key"},)
response = llm.invoke([HumanMessage(content="Hello!")])print(response.content)import { ChatOpenAI } from "@langchain/openai";
const llm = new ChatOpenAI({ model: "gpt-4o-mini", configuration: { baseURL: "https://app.deepintshield.com/langchain", defaultHeaders: { "x-bf-vk": "sk-bf-your-virtual-key" }, }, openAIApiKey: "sk-bf-your-virtual-key",});
const response = await llm.invoke("Hello!");console.log(response.content);Provider/Model Usage Examples
Section titled “Provider/Model Usage Examples”Your existing Langchain provider switching works unchanged through DeepintShield:
from langchain_openai import ChatOpenAIfrom langchain_anthropic import ChatAnthropicfrom langchain_google_genai import ChatGoogleGenerativeAIfrom langchain_core.messages import HumanMessage
base_url = "http://localhost:8080/langchain"
# OpenAI models via Langchainopenai_llm = ChatOpenAI( model="gpt-4o-mini", openai_api_base=base_url)
# Anthropic models via Langchainanthropic_llm = ChatAnthropic( model="claude-3-sonnet-20240229", anthropic_api_url=base_url)
# Google models via Langchaingoogle_llm = ChatGoogleGenerativeAI( model="gemini-1.5-flash", google_api_base=base_url)
# All work the same wayopenai_response = openai_llm.invoke([HumanMessage(content="Hello GPT!")])anthropic_response = anthropic_llm.invoke([HumanMessage(content="Hello Claude!")])google_response = google_llm.invoke([HumanMessage(content="Hello Gemini!")])import { ChatOpenAI } from "@langchain/openai";import { ChatAnthropic } from "@langchain/anthropic";import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
const baseURL = "http://localhost:8080/langchain";
// OpenAI models via Langchainconst openaiLlm = new ChatOpenAI({ model: "gpt-4o-mini", configuration: { baseURL }});
// Anthropic models via Langchainconst anthropicLlm = new ChatAnthropic({ model: "claude-3-sonnet-20240229", clientOptions: { baseURL }});
// Google models via Langchainconst googleLlm = new ChatGoogleGenerativeAI({ model: "gemini-1.5-flash", baseURL});
// All work the same wayconst openaiResponse = await openaiLlm.invoke("Hello GPT!");const anthropicResponse = await anthropicLlm.invoke("Hello Claude!");const googleResponse = await googleLlm.invoke("Hello Gemini!");Adding Custom Headers
Section titled “Adding Custom Headers”Add DeepintShield-specific headers for governance and tracking. Different LangChain provider classes support different methods for adding custom headers:
ChatOpenAI
Section titled “ChatOpenAI”Use default_headers parameter for OpenAI models:
from langchain_openai import ChatOpenAIfrom langchain_core.messages import HumanMessage
llm = ChatOpenAI( model="gpt-4o-mini", openai_api_base="http://localhost:8080/langchain", default_headers={ "x-bf-vk": "your-virtual-key", })
response = llm.invoke([HumanMessage(content="Hello!")])print(response.content)ChatAnthropic
Section titled “ChatAnthropic”Use default_headers parameter for Anthropic models:
from langchain_anthropic import ChatAnthropicfrom langchain_core.messages import HumanMessage
llm = ChatAnthropic( model="claude-3-sonnet-20240229", anthropic_api_url="http://localhost:8080/langchain", default_headers={ "x-bf-vk": "your-virtual-key", # Virtual key for governance })
response = llm.invoke([HumanMessage(content="Hello!")])print(response.content)ChatGoogleGenerativeAI
Section titled “ChatGoogleGenerativeAI”Use additional_headers parameter for Google/Gemini models:
from langchain_google_genai import ChatGoogleGenerativeAIfrom langchain_core.messages import HumanMessage
llm = ChatGoogleGenerativeAI( model="gemini-2.5-flash", google_api_base="http://localhost:8080/langchain", additional_headers={ "x-bf-vk": "your-virtual-key", # Virtual key for governance })
response = llm.invoke([HumanMessage(content="Hello!")])print(response.content)ChatBedrockConverse
Section titled “ChatBedrockConverse”For Bedrock models, there are two approaches:
Method 1: Using the client’s event system (after initialization)
from langchain_aws import ChatBedrockConversefrom langchain_core.messages import HumanMessage
llm = ChatBedrockConverse( model="us.anthropic.claude-haiku-4-5-20251001-v1:0", region_name="us-west-2", endpoint_url="http://localhost:8080/langchain", aws_access_key_id="dummy-access-key", aws_secret_access_key="dummy-secret-key", max_tokens=2000)
def add_bifrost_headers(request, **kwargs): """Add custom headers to Bedrock requests""" request.headers.add_header("x-bf-vk", "your-virtual-key")
# Register header injection for all Bedrock operationsllm.client.meta.events.register_first( "before-sign.bedrock-runtime.*", add_bifrost_headers)
response = llm.invoke([HumanMessage(content="Hello!")])print(response.content)Method 2: Pre-configuring a boto3 client
from langchain_aws import ChatBedrockConversefrom langchain_core.messages import HumanMessageimport boto3
# Create and configure boto3 clientbedrock_client = boto3.client( service_name="bedrock-runtime", region_name="us-west-2", endpoint_url="http://localhost:8080/langchain", aws_access_key_id="dummy-access-key", aws_secret_access_key="dummy-secret-key")
def add_bifrost_headers(request, **kwargs): """Add custom headers to Bedrock requests""" request.headers.add_header("x-bf-vk", "your-virtual-key")
# Register header injection before creating LLMbedrock_client.meta.events.register_first( "before-sign.bedrock-runtime.*", add_bifrost_headers)
# Pass the configured client to ChatBedrockConversellm = ChatBedrockConverse( model="us.anthropic.claude-haiku-4-5-20251001-v1:0", client=bedrock_client, max_tokens=2000)
response = llm.invoke([HumanMessage(content="Hello!")])print(response.content)ChatOpenAI
Section titled “ChatOpenAI”Use defaultHeaders in configuration for OpenAI models:
import { ChatOpenAI } from "@langchain/openai";
const llm = new ChatOpenAI({ model: "gpt-4o-mini", configuration: { baseURL: "http://localhost:8080/langchain", defaultHeaders: { "x-bf-vk": "your-virtual-key", // Virtual key for governance } }});
const response = await llm.invoke("Hello!");console.log(response.content);ChatAnthropic
Section titled “ChatAnthropic”Use defaultHeaders in clientOptions for Anthropic models:
import { ChatAnthropic } from "@langchain/anthropic";
const llm = new ChatAnthropic({ model: "claude-3-sonnet-20240229", clientOptions: { baseURL: "http://localhost:8080/langchain", defaultHeaders: { "x-bf-vk": "your-virtual-key", // Virtual key for governance } }});
const response = await llm.invoke("Hello!");console.log(response.content);ChatGoogleGenerativeAI
Section titled “ChatGoogleGenerativeAI”Use additionalHeaders for Google/Gemini models:
import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
const llm = new ChatGoogleGenerativeAI({ model: "gemini-2.5-flash", baseURL: "http://localhost:8080/langchain", additionalHeaders: { "x-bf-vk": "your-virtual-key", // Virtual key for governance }});
const response = await llm.invoke("Hello!");console.log(response.content);Using Direct Keys
Section titled “Using Direct Keys”Pass API keys directly to bypass DeepintShield’s key management. You can pass any provider’s API key since DeepintShield only looks for Authorization or x-api-key headers. This requires the Allow Direct API keys option to be enabled in DeepintShield configuration.
Learn more: See Key Management for enabling direct API key usage.
from langchain_openai import ChatOpenAIfrom langchain_anthropic import ChatAnthropicfrom langchain_core.messages import HumanMessage
# Using OpenAI key directlyopenai_llm = ChatOpenAI( model="gpt-4o-mini", openai_api_base="http://localhost:8080/langchain", default_headers={ "Authorization": "Bearer sk-your-openai-key" })
# Using Anthropic key for Claude modelsanthropic_llm = ChatAnthropic( model="claude-3-sonnet-20240229", anthropic_api_url="http://localhost:8080/langchain", default_headers={ "x-api-key": "sk-ant-your-anthropic-key" })
# Using Azure with direct Azure keyfrom langchain_openai import AzureChatOpenAI
azure_llm = AzureChatOpenAI( deployment_name="gpt-4o-aug", api_key="your-azure-api-key", azure_endpoint="http://localhost:8080/langchain", api_version="2024-05-01-preview", max_tokens=100, default_headers={ "x-bf-azure-endpoint": "https://your-resource.openai.azure.com", })
openai_response = openai_llm.invoke([HumanMessage(content="Hello GPT!")])anthropic_response = anthropic_llm.invoke([HumanMessage(content="Hello Claude!")])azure_response = azure_llm.invoke([HumanMessage(content="Hello from Azure!")])import { ChatOpenAI } from "@langchain/openai";import { ChatAnthropic } from "@langchain/anthropic";
// Using OpenAI key directlyconst openaiLlm = new ChatOpenAI({ model: "gpt-4o-mini", configuration: { baseURL: "http://localhost:8080/langchain", defaultHeaders: { "Authorization": "Bearer sk-your-openai-key" } }});
// Using Anthropic key for Claude modelsconst anthropicLlm = new ChatAnthropic({ model: "claude-3-sonnet-20240229", clientOptions: { baseURL: "http://localhost:8080/langchain", defaultHeaders: { "x-api-key": "sk-ant-your-anthropic-key" } }});
// Using Azure with direct Azure keyimport { AzureChatOpenAI } from "@langchain/openai";
const azureLlm = new AzureChatOpenAI({ deploymentName: "gpt-4o-aug", apiKey: "your-azure-api-key", azureOpenAIEndpoint: "http://localhost:8080/langchain", apiVersion: "2024-05-01-preview", maxTokens: 100, configuration: { defaultHeaders: { "x-bf-azure-endpoint": "https://your-resource.openai.azure.com", } }});
const openaiResponse = await openaiLlm.invoke("Hello GPT!");const anthropicResponse = await anthropicLlm.invoke("Hello Claude!");const azureResponse = await azureLlm.invoke("Hello from Azure!");Reasoning/Thinking Models
Section titled “Reasoning/Thinking Models”Control extended reasoning capabilities for models that support thinking/reasoning modes.
Azure OpenAI Models
Section titled “Azure OpenAI Models”For Azure OpenAI reasoning models, use ChatOpenAI with the reasoning parameter and Azure-specific headers:
from langchain_openai import ChatOpenAIfrom langchain_core.messages import HumanMessage
# Azure OpenAI with reasoning controlllm = ChatOpenAI( model="azure/gpt-5.1", # Azure deployment name base_url="http://localhost:8080/langchain", api_key="dummy-key", reasoning={ "effort": "high", # "minimal" | "low" | "medium" | "high" "summary": "detailed" # "auto" | "concise" | "detailed" }, default_headers={ "authorization": "Bearer your-azure-api-key", "x-bf-azure-endpoint": "https://your-resource.openai.azure.com" })
response = llm.invoke([HumanMessage(content="Solve this complex problem...")])import { ChatOpenAI } from "@langchain/openai";
// Azure OpenAI with reasoning controlconst llm = new ChatOpenAI({ model: "azure/gpt-5.1", // Azure deployment name configuration: { baseURL: "http://localhost:8080/langchain", defaultHeaders: { "authorization": "Bearer your-azure-api-key", "x-bf-azure-endpoint": "https://your-resource.openai.azure.com" } }, openAIApiKey: "dummy-key", reasoning: { effort: "high", summary: "detailed" }});
const response = await llm.invoke("Solve this complex problem...");OpenAI Models
Section titled “OpenAI Models”For OpenAI reasoning models, use ChatOpenAI with the reasoning parameter:
from langchain_openai import ChatOpenAIfrom langchain_core.messages import HumanMessage
# OpenAI with reasoning controlllm = ChatOpenAI( model="gpt-5", base_url="http://localhost:8080/langchain", api_key="dummy-key", max_tokens=2000, reasoning={ "effort": "high", "summary": "detailed" })
response = llm.invoke([HumanMessage(content="Solve this complex problem...")])import { ChatOpenAI } from "@langchain/openai";
const llm = new ChatOpenAI({ model: "gpt-5", configuration: { baseURL: "http://localhost:8080/langchain" }, openAIApiKey: "dummy-key", reasoning: { effort: "high", summary: "detailed" }});
const response = await llm.invoke("Solve this complex problem...");Bedrock Models (Anthropic & Nova)
Section titled “Bedrock Models (Anthropic & Nova)”Both Anthropic Claude and Amazon Nova models support reasoning/thinking capabilities via Bedrock. Use ChatBedrockConverse with model-specific configuration formats.
Anthropic Claude Models
Section titled “Anthropic Claude Models”from langchain_aws import ChatBedrockConversefrom langchain_core.messages import HumanMessage
# Bedrock Claude with reasoning controlllm = ChatBedrockConverse( model="us.anthropic.claude-opus-4-5-20251101-v1:0", region_name="dummy-region", endpoint_url="http://localhost:8080/langchain", aws_access_key_id="dummy-access-key", aws_secret_access_key="dummy-secret-key", max_tokens=2000, additional_model_request_fields={ # Anthropic format "reasoning_config": { "type": "enabled", "budget_tokens": 1500, # Control thinking token budget } })
response = llm.invoke([HumanMessage(content="Reason through this problem...")])Amazon Nova Models
Section titled “Amazon Nova Models”from langchain_aws import ChatBedrockConversefrom langchain_core.messages import HumanMessage
# Bedrock Nova with reasoning controlllm = ChatBedrockConverse( model="global.amazon.nova-2-lite-v1:0", region_name="dummy-region", endpoint_url="http://localhost:8080/langchain", aws_access_key_id="dummy-access-key", aws_secret_access_key="dummy-secret-key", max_tokens=2000, additional_model_request_fields={ # Nova format "reasoningConfig": { "type": "enabled", "maxReasoningEffort": "high", # "low" | "medium" | "high" } })
response = llm.invoke([HumanMessage(content="Reason through this problem...")])Google/Vertex AI Models
Section titled “Google/Vertex AI Models”For Google Gemini 2.5 models (Pro, Flash) and Gemini 3, use ChatGoogleGenerativeAI with the thinking_budget parameter:
from langchain_google_genai import ChatGoogleGenerativeAIfrom langchain_core.messages import HumanMessage
# Gemini with thinking budget controlllm = ChatGoogleGenerativeAI( model="gemini/gemini-2.5-flash", # or "vertex/gemini-2.5-flash" base_url="http://localhost:8080/langchain", api_key="dummy-key", max_tokens=4000, thinking_budget=1024, # 0=disable, -1=dynamic, >0=constrained token budget include_thoughts=True, # Include reasoning in response)
response = llm.invoke([HumanMessage(content="Reason through this problem...")])Embeddings
Section titled “Embeddings”LangChain’s OpenAIEmbeddings class can be used to generate embeddings through DeepintShield:
from langchain_openai import OpenAIEmbeddings
# Create embeddings instanceembeddings = OpenAIEmbeddings( model="text-embedding-3-small", base_url="http://localhost:8080/langchain", api_key="dummy-key")
# Embed a single queryquery_embedding = embeddings.embed_query("What is machine learning?")
# Embed multiple documentsdoc_embeddings = embeddings.embed_documents([ "Machine learning is a subset of AI", "Deep learning uses neural networks", "NLP helps computers understand text"])Cross-Provider Embeddings
Section titled “Cross-Provider Embeddings”For embedding models from other providers (Cohere, Bedrock, Gemini, etc.), you can use GoogleGenerativeAIEmbeddings from the langchain_google_genai package. This module sends text strings directly and works across multiple providers:
from langchain_google_genai import GoogleGenerativeAIEmbeddings
# Works with any provider's embedding modelsembeddings = GoogleGenerativeAIEmbeddings( model="cohere/cohere-embed-v4.0", # or bedrock/..., gemini/..., etc. base_url="http://localhost:8080/langchain", api_key="dummy-key")
query_embedding = embeddings.embed_query("What is machine learning?")doc_embeddings = embeddings.embed_documents([ "Machine learning is a subset of AI", "Deep learning uses neural networks"])Supported Features
Section titled “Supported Features”The Langchain integration supports all features that are available in both the Langchain SDK and DeepintShield core functionality. Your existing Langchain chains and workflows work seamlessly with DeepintShield’s enterprise features. 😄
Next Steps
Section titled “Next Steps”- Governance Features - Virtual keys and team management
- Semantic Caching - Intelligent response caching
- Configuration - Provider setup and API key management