ChatGroq Class — langchain Architecture
Architecture documentation for the ChatGroq class in chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 1b7e9480_5f92_34b0_9c64_8fda809e3204["ChatGroq"] d009a608_c505_bd50_7200_0de8a69ba4b7["BaseChatModel"] 1b7e9480_5f92_34b0_9c64_8fda809e3204 -->|extends| d009a608_c505_bd50_7200_0de8a69ba4b7 fcfa55b0_4a86_fa31_a156_3c38c76a0a9b["AIMessage"] 1b7e9480_5f92_34b0_9c64_8fda809e3204 -->|extends| fcfa55b0_4a86_fa31_a156_3c38c76a0a9b 0d6da130_abcc_62f0_04a9_cdc0d475679f["chat_models.py"] 1b7e9480_5f92_34b0_9c64_8fda809e3204 -->|defined in| 0d6da130_abcc_62f0_04a9_cdc0d475679f de6aac96_7ca8_c92b_61ad_958b2c91d34a["build_extra()"] 1b7e9480_5f92_34b0_9c64_8fda809e3204 -->|method| de6aac96_7ca8_c92b_61ad_958b2c91d34a 530a48cf_e53c_a33d_a3a9_882cf7e03ba1["validate_environment()"] 1b7e9480_5f92_34b0_9c64_8fda809e3204 -->|method| 530a48cf_e53c_a33d_a3a9_882cf7e03ba1 01ad9a02_35b2_cec7_c9a7_3c80d9f8b0d6["_set_model_profile()"] 1b7e9480_5f92_34b0_9c64_8fda809e3204 -->|method| 01ad9a02_35b2_cec7_c9a7_3c80d9f8b0d6 e92e3240_2ab7_3aaf_4a9e_228c36eae5ee["lc_secrets()"] 1b7e9480_5f92_34b0_9c64_8fda809e3204 -->|method| e92e3240_2ab7_3aaf_4a9e_228c36eae5ee 6b0fc9b7_b293_c782_76f8_2fce84aedeb9["is_lc_serializable()"] 1b7e9480_5f92_34b0_9c64_8fda809e3204 -->|method| 6b0fc9b7_b293_c782_76f8_2fce84aedeb9 dd0cb1d0_42d9_a4c9_e7f4_8bd53a4a6f02["_llm_type()"] 1b7e9480_5f92_34b0_9c64_8fda809e3204 -->|method| dd0cb1d0_42d9_a4c9_e7f4_8bd53a4a6f02 efc58457_36b7_1671_e973_81e75aeae104["_get_ls_params()"] 1b7e9480_5f92_34b0_9c64_8fda809e3204 -->|method| efc58457_36b7_1671_e973_81e75aeae104 0d605ea6_f14c_26eb_2661_8f3466eb3e37["_should_stream()"] 1b7e9480_5f92_34b0_9c64_8fda809e3204 -->|method| 0d605ea6_f14c_26eb_2661_8f3466eb3e37 6fc01bff_17eb_0bdd_89e8_4c2e505ce3a9["_generate()"] 1b7e9480_5f92_34b0_9c64_8fda809e3204 -->|method| 6fc01bff_17eb_0bdd_89e8_4c2e505ce3a9 e3d4db04_8b89_ab57_ab88_0a6e42b16d29["_agenerate()"] 1b7e9480_5f92_34b0_9c64_8fda809e3204 -->|method| e3d4db04_8b89_ab57_ab88_0a6e42b16d29 4945335b_e43f_ecd0_0adc_376820d80b2d["_stream()"] 1b7e9480_5f92_34b0_9c64_8fda809e3204 -->|method| 4945335b_e43f_ecd0_0adc_376820d80b2d
Relationship Graph
Source Code
libs/partners/groq/langchain_groq/chat_models.py lines 85–1260
class ChatGroq(BaseChatModel):
r"""Groq Chat large language models API.
To use, you should have the
environment variable `GROQ_API_KEY` set with your API key.
Any parameters that are valid to be passed to the groq.create call
can be passed in, even if not explicitly saved on this class.
Setup:
Install `langchain-groq` and set environment variable
`GROQ_API_KEY`.
```bash
pip install -U langchain-groq
export GROQ_API_KEY="your-api-key"
```
Key init args — completion params:
model:
Name of Groq model to use, e.g. `llama-3.1-8b-instant`.
temperature:
Sampling temperature. Ranges from `0.0` to `1.0`.
max_tokens:
Max number of tokens to generate.
reasoning_format:
The format for reasoning output. Groq will default to `raw` if left
undefined.
- `'parsed'`: Separates reasoning into a dedicated field while keeping the
response concise. Reasoning will be returned in the
`additional_kwargs.reasoning_content` field of the response.
- `'raw'`: Includes reasoning within think tags (e.g.
`<think>{reasoning_content}</think>`).
- `'hidden'`: Returns only the final answer content. Note: this only
suppresses reasoning content in the response; the model will still perform
reasoning unless overridden in `reasoning_effort`.
See the [Groq documentation](https://console.groq.com/docs/reasoning#reasoning)
for more details and a list of supported models.
model_kwargs:
Holds any model parameters valid for create call not
explicitly specified.
Key init args — client params:
timeout:
Timeout for requests.
max_retries:
Max number of retries.
api_key:
Groq API key. If not passed in will be read from env var `GROQ_API_KEY`.
base_url:
Base URL path for API requests, leave blank if not using a proxy
or service emulator.
custom_get_token_ids:
Optional encoder to use for counting tokens.
See full list of supported init args and their descriptions in the params
section.
Instantiate:
```python
from langchain_groq import ChatGroq
model = ChatGroq(
model="llama-3.1-8b-instant",
temperature=0.0,
max_retries=2,
# other params...
)
```
Invoke:
```python
messages = [
("system", "You are a helpful translator. Translate the user sentence to French."),
("human", "I love programming."),
]
model.invoke(messages)
```
```python
Extends
Source
Frequently Asked Questions
What is the ChatGroq class?
ChatGroq is a class in the langchain codebase, defined in libs/partners/groq/langchain_groq/chat_models.py.
Where is ChatGroq defined?
ChatGroq is defined in libs/partners/groq/langchain_groq/chat_models.py at line 85.
What does ChatGroq extend?
ChatGroq extends BaseChatModel, AIMessage.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free