Загрузка данных


// 1. Добавляем URL прокси перед основным URL
const proxy = "https://cors-anywhere.herokuapp.com/";
const apiUrl = "https://openrouter.ai/api/v1/chat/completions";

async function makeRequest() {
  try {
    const response = await fetch(proxy + apiUrl, { // Склеиваем прокси и API
      method: "POST",
      headers: {
        "Authorization": "Bearer YOUR_API_KEY",
        "Content-Type": "application/json",
        // При использовании cors-anywhere иногда нужно добавить этот заголовок:
        "X-Requested-With": "XMLHttpRequest" 
      },
      body: JSON.stringify({
        "model": "google/gemini-3-flash-preview",
        "messages": [
          { "role": "user", "content": "How many r's are in the word 'strawberry'?" }
        ],
        "include_reasoning": true
      })
    });

    const result = await response.json();
    console.log(result.choices[0].message);
  } catch (error) {
    console.error("Ошибка:", error);
  }
}

makeRequest();