mirror of
https://github.com/wassname/openrouter-python-sdk-retry-errors.git
synced 2026-07-31 12:30:30 +08:00
1.2 KiB
1.2 KiB
# Synchronous Example
from openrouter import OpenRouter, models
import os
with OpenRouter(
bearer_auth=os.getenv("OPENROUTER_BEARER_AUTH", ""),
) as open_router:
res = open_router.chat.complete(messages=[
{
"role": models.ChatCompletionUserMessageParamRole.USER,
"content": "Hello, how are you?",
},
], stream=False, temperature=1, top_p=1)
# Handle response
print(res)
The same SDK client can also be used to make asynchronous requests by importing asyncio.
# Asynchronous Example
import asyncio
from openrouter import OpenRouter, models
import os
async def main():
async with OpenRouter(
bearer_auth=os.getenv("OPENROUTER_BEARER_AUTH", ""),
) as open_router:
res = await open_router.chat.complete_async(messages=[
{
"role": models.ChatCompletionUserMessageParamRole.USER,
"content": "Hello, how are you?",
},
], stream=False, temperature=1, top_p=1)
# Handle response
print(res)
asyncio.run(main())