Articles → LANGCHAIN → Call The Huggingface API In Langchain

Call The Huggingface API In Langchain






Install Python Packages




pip install -U huggingface_hub ipywidgets




  1. huggingface_hub
  2. ipywidgets

Example


from huggingface_hub import InferenceClient

client = InferenceClient(
    api_key="your_api_key"
)

response = client.chat_completion(
    model="meta-llama/Llama-3.1-8B-Instruct",
    messages=[
        {
            "role": "user",
            "content": "Explain Artificial Intelligence in simple words."
        }
    ],
    max_tokens=200
)

print(response.choices[0].message.content)



Output


Picture showing the output of calling the hugging face api





Posted By  -  Karan Gupta
 
Posted On  -  Friday, May 15, 2026

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250