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="")