Spaces:
Running
Running
Download test_openrouter.py from H3y-sam/Telegram-Bot: direct link, hf CLI and curl.
- Browser
- Download file 685 Bytes
-
https://huggingface.co/spaces/H3y-sam/Telegram-Bot/resolve/main/test_openrouter.py
- Command line
-
hf download hf://spaces/H3y-sam/Telegram-Bot/test_openrouter.py
-
curl -L -o test_openrouter.py https://huggingface.co/spaces/H3y-sam/Telegram-Bot/resolve/main/test_openrouter.py
685 Bytes
| import httpx | |
| import asyncio | |
| import os | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| API_KEY = os.getenv('OPENROUTER_API_KEY') | |
| async def test(): | |
| url = 'https://openrouter.ai/api/v1/chat/completions' | |
| headers = { | |
| 'Authorization': f'Bearer {API_KEY}', | |
| 'Content-Type': 'application/json' | |
| } | |
| payload = { | |
| 'model': 'google/gemini-2.0-flash-lite-preview-02-05:free', | |
| 'messages': [{'role': 'user', 'content': 'Hello'}] | |
| } | |
| async with httpx.AsyncClient() as client: | |
| resp = await client.post(url, headers=headers, json=payload) | |
| print(f'Status: {resp.status_code}') | |
| print(f'Response: {resp.text}') | |
| asyncio.run(test()) | |