Making Your First Request
Discover how to make your first API request with OpenRouter, including obtaining and securely managing your API key, constructing requests compatible with OpenAI APIs, switching models by changing a single parameter, and interpreting response data essential for cost management and debugging. This lesson helps you confidently initiate multi-provider AI model calls using consistent code.
In the last lesson, we established why OpenRouter is a strategic choice that solves ecosystem fragmentation by acting as a unified routing layer. Now, we move from theory to practice.
This lesson walks through the fundamental mechanics of making your first API call. We will get an API key, construct a request, send it to two different providers with a single line of code change, and learn how to interpret the response.
Getting your API key
Before you can make any requests, you need to authenticate your application. This is done using an API key. You can create a new key from your OpenRouter settings page. Once you create a key, its full value is only shown once. Copy it immediately and store it securely, as you would a password.
For security and operational hygiene, follow these best practices when managing your keys:
Assign descriptive names: Name your keys clearly to track their usage (e.g.,
prod-text-generation-v1-2024-q3).Set ...