Get request & usage metadata for a generation
curl --request GET \
--url https://openrouter.ai/api/v1/generation \
--header 'Authorization: Bearer <token>'import requests
url = "https://openrouter.ai/api/v1/generation"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://openrouter.ai/api/v1/generation', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://openrouter.ai/api/v1/generation",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://openrouter.ai/api/v1/generation"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://openrouter.ai/api/v1/generation")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://openrouter.ai/api/v1/generation")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"data": {
"api_type": "completions",
"app_id": 12345,
"cache_discount": null,
"cancelled": false,
"created_at": "2024-07-15T23:33:19.433273+00:00",
"external_user": "user-123",
"finish_reason": "stop",
"generation_time": 1200,
"http_referer": "https://openrouter.ai/",
"id": "gen-3bhGkxlo4XFrqiabUM7NDtwDzWwG",
"is_byok": false,
"latency": 1250,
"model": "sao10k/l3-stheno-8b",
"moderation_latency": 50,
"native_finish_reason": "stop",
"native_tokens_cached": 3,
"native_tokens_completion": 25,
"native_tokens_completion_images": 0,
"native_tokens_prompt": 10,
"native_tokens_reasoning": 5,
"num_input_audio_prompt": 0,
"num_media_completion": 0,
"num_media_prompt": 1,
"num_search_results": 5,
"origin": "https://openrouter.ai/",
"provider_name": "Infermatic",
"provider_responses": null,
"request_id": "req-1727282430-aBcDeFgHiJkLmNoPqRsT",
"router": "openrouter/auto",
"session_id": null,
"streamed": true,
"tokens_completion": 25,
"tokens_prompt": 10,
"total_cost": 0.0015,
"upstream_id": "chatcmpl-791bcf62-080e-4568-87d0-94c72e3b4946",
"upstream_inference_cost": 0.0012,
"usage": 0.0015,
"user_agent": "Mozilla/5.0"
}
}{
"error": {
"code": 401,
"message": "Missing Authentication header"
}
}{
"error": {
"code": 402,
"message": "Insufficient credits. Add more using https://openrouter.ai/credits"
}
}{
"error": {
"code": 404,
"message": "Resource not found"
}
}{
"error": {
"code": 429,
"message": "Rate limit exceeded"
}
}{
"error": {
"code": 500,
"message": "Internal Server Error"
}
}{
"error": {
"code": 502,
"message": "Provider returned error"
}
}{
"error": {
"code": 524,
"message": "Request timed out. Please try again later."
}
}{
"error": {
"code": 529,
"message": "Provider returned error"
}
}Generations
Get request & usage metadata for a generation
GET
/
generation
Get request & usage metadata for a generation
curl --request GET \
--url https://openrouter.ai/api/v1/generation \
--header 'Authorization: Bearer <token>'import requests
url = "https://openrouter.ai/api/v1/generation"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://openrouter.ai/api/v1/generation', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://openrouter.ai/api/v1/generation",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://openrouter.ai/api/v1/generation"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://openrouter.ai/api/v1/generation")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://openrouter.ai/api/v1/generation")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"data": {
"api_type": "completions",
"app_id": 12345,
"cache_discount": null,
"cancelled": false,
"created_at": "2024-07-15T23:33:19.433273+00:00",
"external_user": "user-123",
"finish_reason": "stop",
"generation_time": 1200,
"http_referer": "https://openrouter.ai/",
"id": "gen-3bhGkxlo4XFrqiabUM7NDtwDzWwG",
"is_byok": false,
"latency": 1250,
"model": "sao10k/l3-stheno-8b",
"moderation_latency": 50,
"native_finish_reason": "stop",
"native_tokens_cached": 3,
"native_tokens_completion": 25,
"native_tokens_completion_images": 0,
"native_tokens_prompt": 10,
"native_tokens_reasoning": 5,
"num_input_audio_prompt": 0,
"num_media_completion": 0,
"num_media_prompt": 1,
"num_search_results": 5,
"origin": "https://openrouter.ai/",
"provider_name": "Infermatic",
"provider_responses": null,
"request_id": "req-1727282430-aBcDeFgHiJkLmNoPqRsT",
"router": "openrouter/auto",
"session_id": null,
"streamed": true,
"tokens_completion": 25,
"tokens_prompt": 10,
"total_cost": 0.0015,
"upstream_id": "chatcmpl-791bcf62-080e-4568-87d0-94c72e3b4946",
"upstream_inference_cost": 0.0012,
"usage": 0.0015,
"user_agent": "Mozilla/5.0"
}
}{
"error": {
"code": 401,
"message": "Missing Authentication header"
}
}{
"error": {
"code": 402,
"message": "Insufficient credits. Add more using https://openrouter.ai/credits"
}
}{
"error": {
"code": 404,
"message": "Resource not found"
}
}{
"error": {
"code": 429,
"message": "Rate limit exceeded"
}
}{
"error": {
"code": 500,
"message": "Internal Server Error"
}
}{
"error": {
"code": 502,
"message": "Provider returned error"
}
}{
"error": {
"code": 524,
"message": "Request timed out. Please try again later."
}
}{
"error": {
"code": 529,
"message": "Provider returned error"
}
}Authorizations
API key as bearer token in Authorization header
Query Parameters
The generation ID
Minimum string length:
1Example:
"gen-1234567890"
Response
Returns the request metadata for this generation
Generation response
Generation data
Show child attributes
Show child attributes
⌘I