examples/openrouter-llm-example/README.md
This example demonstrates how to use OpenRouter with langchaingo. OpenRouter provides a unified API to access various LLM models through a single endpoint.
OpenRouter is an AI routing service that provides:
export OPENROUTER_API_KEY="your-api-key-here"
OpenRouter uses an OpenAI-compatible API, so you can use the OpenAI client with a custom base URL:
llm, err := openai.New(
openai.WithModel("meta-llama/llama-3.2-3b-instruct:free"),
openai.WithBaseURL("https://openrouter.ai/api/v1"),
openai.WithToken(apiKey),
)
OpenRouter provides access to many models including:
meta-llama/llama-3.2-3b-instruct:free, google/gemma-2-9b-it:freego run openrouter_llm_example.go