Large Language Models#

This module covers the practical usage of large language models (LLMs).

LLMs incur a cost. For the May 2025 batch, use aipipe.org as a proxy. Emails with @ds.study.iitm.ac.in get a $1 per calendar month allowance. (Don’t exceed that.)

Read the AI Pipe documentation to learn how to use it. But in short:

  1. Replace OPENAI_BASE_URL, i.e. https://api.openai.com/v1 with https://aipipe.org/openrouter/v1... or https://aipipe.org/openai/v1...
  2. Replace OPENAI_API_KEY with the AIPIPE_TOKEN
  3. Replace model names, e.g. gpt-4.1-nano, with openai/gpt-4.1-nano

For example, let’s use Gemini 2.0 Flash Lite via OpenRouter for chat completions and Text Embedding 3 Small via OpenAI for embeddings:

curl https://aipipe.org/openrouter/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $AIPIPE_TOKEN" \
  -d '{
    "model": "google/gemini-2.0-flash-lite-001",
    "messages": [{ "role": "user", "content": "What is 2 + 2?"} }]
  }'

curl https://aipipe.org/openai/v1/embeddings \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $AIPIPE_TOKEN" \
  -d '{ "model": "text-embedding-3-small", "input": "What is 2 + 2?" }'

Or using llm:

llm keys set openai --value $AIPIPE_TOKEN

export OPENAI_BASE_URL=https://aipipe.org/openrouter/v1
llm 'What is 2 + 2?' -m openrouter/google/gemini-2.0-flash-lite-001

export OPENAI_BASE_URL=https://aipipe.org/openai/v1
llm embed -c 'What is 2 + 2' -m 3-small

For a 50% discount (but slower speed), use Flex processing by adding service_tier: "flex" to your JSON request.

AI Pipe#

Anyone with a study.iitm.ac.in email can get a free API key from aipipe.org and use up to $2 per calendar month for this course. Don’t exceed that.

To use it, read the documentation. Specifically:

  1. Use https://aipipe.org/openai/v1/... instead of https://api.openai.com/v1/... as the OPENAI_BASE_URL
  2. Use the token from https://aipipe.org/login as the OPENAI_API_KEY