SambaNova の Responses API (POST /v1/responses) は、OpenAI Responses API 標準と互換性があります。OpenAI Responses API 向けに構築された既存のクライアントや SDK は、コードを変更することなく SambaNova のエンドポイントに接続できます。このエンドポイントは、エージェント型・ツール対応・コーディング指向の連携向けに設計されています。Responses API は、既存の Chat Completions API を補完するものであり、置き換えるものではありません。
from sambanova import SambaNovaclient = SambaNova( base_url="your-sambanova-base-url", api_key="your-sambanova-api-key")response = client.responses.create( model="gpt-oss-120b", input="Explain the difference between supervised and unsupervised learning in two sentences.")print(response.output[0].content[0].text)# orprint(response.output_text)
from openai import OpenAIclient = OpenAI( base_url="your-sambanova-base-url", api_key="your-sambanova-api-key")response = client.responses.create( model="gpt-oss-120b", input="Explain the difference between supervised and unsupervised learning in two sentences.")print(response.output[0].content[0].text)# orprint(response.output_text)
from sambanova import SambaNovaclient = SambaNova( base_url="your-sambanova-base-url", api_key="your-sambanova-api-key")stream = client.responses.create( model="gpt-oss-120b", input="Write a short poem about speed.", stream=True)for event in stream: if event.type == "response.output_text.delta": print(event.delta, end="", flush=True)
from openai import OpenAIclient = OpenAI( base_url="your-sambanova-base-url", api_key="your-sambanova-api-key")stream = client.responses.create( model="gpt-oss-120b", input="Write a short poem about speed.", stream=True)for event in stream: if event.type == "response.output_text.delta": print(event.delta, end="", flush=True)
from sambanova import SambaNovaclient = SambaNova( base_url="your-sambanova-base-url", api_key="your-sambanova-api-key")tools = [ { "type": "function", "name": "get_weather", "description": "Get the current weather for a city.", "parameters": { "type": "object", "properties": { "city": { "type": "string", "description": "The city name, e.g. San Francisco" } }, "required": ["city"] } }]response = client.responses.create( model="gpt-oss-120b", input=[{"role": "user", "content": "What is the weather in Bogotá?"}], tools=tools)for item in response.output: if item.type == "function_call": print(f"Tool: {item.name}, Arguments: {item.arguments}")
from openai import OpenAIclient = OpenAI( base_url="your-sambanova-base-url", api_key="your-sambanova-api-key")tools = [ { "type": "function", "name": "get_weather", "description": "Get the current weather for a city.", "parameters": { "type": "object", "properties": { "city": { "type": "string", "description": "The city name, e.g. San Francisco" } }, "required": ["city"] } }]response = client.responses.create( model="gpt-oss-120b", input=[{"role": "user", "content": "What is the weather in Bogotá?"}], tools=tools)# Print the function_call items returned by the modelfor item in response.output: if item.type == "function_call": print(f"Tool: {item.name}, Arguments: {item.arguments}")
import jsondef get_weather(city: str) -> dict: # Replace with a real weather API call return {"city": city, "temperature_celsius": 18, "condition": "Cloudy"}# Find the function_call item in the responsetool_call = next(item for item in response.output if item.type == "function_call")args = json.loads(tool_call.arguments)result = get_weather(args["city"])# Submit the tool result in a follow-up requestfollow_up = client.responses.create( model="gpt-oss-120b", input=[ {"role": "user", "content": "What is the weather in Bogotá?"}, tool_call, { "type": "function_call_output", "call_id": tool_call.call_id, "output": json.dumps(result) } ], tools=tools)print(follow_up.output[0].content[0].text)
import jsondef get_weather(city: str) -> dict: # Replace with a real weather API call return {"city": city, "temperature_celsius": 18, "condition": "Cloudy"}# Find the function_call item in the responsetool_call = next(item for item in response.output if item.type == "function_call")args = json.loads(tool_call.arguments)result = get_weather(args["city"])# Submit the tool result in a follow-up requestfollow_up = client.responses.create( model="gpt-oss-120b", input=[ {"role": "user", "content": "What is the weather in Bogotá?"}, tool_call, { "type": "function_call_output", "call_id": tool_call.call_id, "output": json.dumps(result) } ], tools=tools)print(follow_up.output[0].content[0].text)
Responses API はステートレスです。複数ターンにわたってコンテキストを維持するには、後続の各リクエストの input 配列に、新しいユーザーメッセージと併せて過去のすべての出力アイテムを含めてください。
from sambanova import SambaNovaclient = SambaNova( base_url="your-sambanova-base-url", api_key="your-sambanova-api-key")# First turnresponse_1 = client.responses.create( model="gpt-oss-120b", input=[{"role": "user", "content": "What is the capital of Colombia?"}])assistant_message = response_1.output[0]# Second turn – include prior output itemsresponse_2 = client.responses.create( model="gpt-oss-120b", input=[ {"role": "user", "content": "What is the capital of Colombia?"}, assistant_message, {"role": "user", "content": "What is its approximate population?"} ])print(response_2.output[0].content[0].text)
from openai import OpenAIclient = OpenAI( base_url="your-sambanova-base-url", api_key="your-sambanova-api-key")# First turnresponse_1 = client.responses.create( model="gpt-oss-120b", input=[{"role": "user", "content": "What is the capital of Colombia?"}])assistant_message = response_1.output[0]# Second turn – include prior output itemsresponse_2 = client.responses.create( model="gpt-oss-120b", input=[ {"role": "user", "content": "What is the capital of Colombia?"}, assistant_message, {"role": "user", "content": "What is its approximate population?"} ])print(response_2.output[0].content[0].text)