{"id":2982,"library":"langchain-groq","title":"Groq Integration for LangChain","description":"langchain-groq is an integration package that connects Groq's ultra-fast inference API with the LangChain framework. It allows developers to leverage Groq's LPU-powered language models, such as Llama 3 and Mixtral, within their LangChain applications for fast and efficient LLM inference. The library is actively maintained, with frequent updates often aligning with new features or fixes in the broader LangChain ecosystem.","status":"active","version":"1.1.2","language":"en","source_language":"en","source_url":"https://github.com/langchain-ai/langchain/tree/master/libs/partners/groq","tags":["LangChain","LLM","Groq","AI","Chatbot","Fast Inference"],"install":[{"cmd":"pip install langchain-groq","lang":"bash","label":"Install `langchain-groq`"}],"dependencies":[{"reason":"Required for core LangChain functionalities and abstractions.","package":"langchain-core","optional":false},{"reason":"The official Groq Python SDK for API communication.","package":"groq","optional":false}],"imports":[{"note":"Used to interact with Groq's chat models for fast inference.","symbol":"ChatGroq","correct":"from langchain_groq import ChatGroq"}],"quickstart":{"code":"import os\nfrom langchain_groq import ChatGroq\nfrom langchain_core.messages import HumanMessage, SystemMessage\n\n# Ensure your Groq API key is set as an environment variable\n# os.environ[\"GROQ_API_KEY\"] = \"your_groq_api_key_here\"\n# Or pass it directly to the ChatGroq constructor (not recommended for production)\n\ngroq_api_key = os.environ.get(\"GROQ_API_KEY\")\n\nif not groq_api_key:\n    print(\"Error: GROQ_API_KEY environment variable not set.\")\nelse:\n    llm = ChatGroq(\n        model=\"llama-3.3-70b-versatile\",\n        temperature=0.0,\n        max_retries=2,\n        api_key=groq_api_key\n    )\n\n    messages = [\n        SystemMessage(content=\"You are a helpful assistant that translates English to French.\"),\n        HumanMessage(content=\"I love programming.\"),\n    ]\n\n    # Invoke the model\n    response = llm.invoke(messages)\n    print(\"\\n--- Invoke Response ---\")\n    print(f\"Content: {response.content}\")\n\n    # Stream the response\n    print(\"\\n--- Streaming Response ---\")\n    for chunk in llm.stream(messages):\n        print(chunk.content, end=\"\")\n    print()","lang":"python","description":"This quickstart demonstrates how to initialize and use the `ChatGroq` model within LangChain. It shows both a single `invoke` call and streaming capabilities. Ensure your `GROQ_API_KEY` is set as an environment variable."},"warnings":[{"fix":"Set `GROQ_API_KEY` in your environment or pass it explicitly to the `ChatGroq` constructor (e.g., `ChatGroq(api_key=...)`).","message":"The `GROQ_API_KEY` environment variable must be set for authentication with the Groq API. Failure to do so will result in authentication errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Refer to the official Groq documentation for a list of available models and their supported capabilities. Common models include 'llama-3.3-70b-versatile' and 'mixtral-8x7b-32768'.","message":"Using an unsupported or incorrect `model` name when initializing `ChatGroq` will lead to runtime errors. Additionally, certain features like `reasoning_format` or vision input require specific Groq models.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the official LangChain v1.0 upgrade guide. Update import statements (e.g., `from langchain_core.prompts import ChatPromptTemplate`), use the `invoke` method consistently, and adopt the `Runnable` interface for chains and agents.","message":"As a LangChain partner package, `langchain-groq` relies on `langchain-core`. The LangChain v1.0 update introduced significant breaking changes to `langchain-core`'s API, including changes to import paths, agent initialization, and the universal `Runnable` interface. Old patterns from `langchain` v0.x will not work.","severity":"breaking","affected_versions":"Users upgrading from `langchain` v0.x to `langchain-groq` with `langchain-core` v1.x and higher."},{"fix":"Verify image URL accessibility and size constraints according to Groq API specifications.","message":"If utilizing vision capabilities with supported Groq models, ensure that image URLs provided are publicly accessible, return the image directly without redirects, and do not exceed 20MB in size.","severity":"gotcha","affected_versions":"All versions supporting vision models"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}