Пример Python
Установка
Section titled “Установка”pip install openaiОбычный запрос
Section titled “Обычный запрос”from openai import OpenAIimport os
client = OpenAI( api_key=os.environ["ROUTEAPI_KEY"], base_url="https://www.routeapi.ai/v1",)
response = client.chat.completions.create( model="gpt-4o", messages=[{"role": "user", "content": "Опиши RouteAPI одним предложением"}],)
print(response.choices[0].message.content)Потоковый запрос
Section titled “Потоковый запрос”stream = client.chat.completions.create( model="gpt-4o", stream=True, messages=[{"role": "user", "content": "Опиши RouteAPI по пунктам"}],)
for chunk in stream: delta = chunk.choices[0].delta.content if delta: print(delta, end="")