1. Before You Call an LLM
Every LLM comes from a different company. OpenAI makes GPT, Anthropic makes Claude, Google makes Gemini, Mistral AI makes Mistral, and Groq runs open models.
To use any of them from your code, you need two things:
- Its package: the Python library you download with
pip install. - Its API key: your secret password to that company's model.
So for every company you use, you download its package and get its API key. Here they are:
CompanyInstall the packageGet the API keyDocumentation
Code
Calling Geminicallinggemini.py · 17 linesShow code
First install the package:
pip install google-genai python-dotenv1 2 3 4 5 6 7 8 9 10 11 12 13 14 | import os from dotenv import load_dotenv from google import genai load_dotenv() client = genai.Client(api_key=os.getenv("GOOGLE_API_KEY")) response = client.models.generate_content( model="gemini-2.5-flash", contents="What is the capital of India?", ) print(response.text) |
Calling Groqcallinggroq.py · 18 linesShow code
First install the package:
pip install groq python-dotenv1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | import os from dotenv import load_dotenv from groq import Groq load_dotenv() client = Groq(api_key=os.getenv("GROQ_API_KEY")) response = client.chat.completions.create( model="openai/gpt-oss-20b", messages=[{"role": "user", "content": "What is the capital of India?"}], ) print(response.choices[0].message.content) # Models that work on the free plan: # openai/gpt-oss-20b |
Calling Mistralcallingmistral.py · 19 linesShow code
First install the package:
pip install mistralai python-dotenv1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | import os from dotenv import load_dotenv from mistralai.client import Mistral load_dotenv() client = Mistral(api_key=os.getenv("MISTRAL_API_KEY")) response = client.chat.complete( model="open-mistral-nemo", messages=[{"role": "user", "content": "What is the capital of India?"}], ) print(response.choices[0].message.content) # Models that work on our plan: # open-mistral-nemo # ministral-3b-latest |