Responses
Responses
Warning
This API is experimental and subject to changes based upon our experience as we integrate additional providers. Use with caution.
any_llm.responses(model, input_data, *, tools=None, tool_choice=None, max_output_tokens=None, temperature=None, top_p=None, stream=None, api_key=None, api_base=None, timeout=None, user=None, **kwargs)
Create a response using the OpenAI-style Responses API.
This follows the OpenAI Responses API shape and returns the aliased
any_llm.types.responses.Response
type. If stream=True
, an iterator of
any_llm.types.responses.ResponseStreamEvent
items is returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
str
|
Model identifier in format 'provider/model' (e.g., 'openai/gpt-4o') |
required |
input_data
|
Any
|
The input payload accepted by provider's Responses API. For OpenAI-compatible providers, this is typically a list mixing text, images, and tool instructions, or a dict per OpenAI spec. |
required |
tools
|
Optional[List[Union[dict[str, Any], Callable[..., Any]]]]
|
Optional tools for tool calling (Python callables or OpenAI tool dicts) |
None
|
tool_choice
|
Optional[Union[str, dict[str, Any]]]
|
Controls which tools the model can call |
None
|
max_output_tokens
|
Optional[int]
|
Maximum number of output tokens to generate |
None
|
temperature
|
Optional[float]
|
Controls randomness in the response (0.0 to 2.0) |
None
|
top_p
|
Optional[float]
|
Controls diversity via nucleus sampling (0.0 to 1.0) |
None
|
stream
|
Optional[bool]
|
Whether to stream response events |
None
|
api_key
|
Optional[str]
|
API key for the provider |
None
|
api_base
|
Optional[str]
|
Base URL for the provider API |
None
|
timeout
|
Optional[Union[float, int]]
|
Request timeout in seconds |
None
|
user
|
Optional[str]
|
Unique identifier for the end user |
None
|
**kwargs
|
Any
|
Additional provider-specific parameters |
{}
|
Returns:
Type | Description |
---|---|
Response | Iterator[ResponseStreamEvent]
|
Either a |
Response | Iterator[ResponseStreamEvent]
|
|
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the selected provider does not support the Responses API. |
Source code in src/any_llm/api.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
|
any_llm.aresponses(model, input_data, *, tools=None, tool_choice=None, max_output_tokens=None, temperature=None, top_p=None, stream=None, api_key=None, api_base=None, timeout=None, user=None, **kwargs)
async
Create a response using the OpenAI-style Responses API.
This follows the OpenAI Responses API shape and returns the aliased
any_llm.types.responses.Response
type. If stream=True
, an iterator of
any_llm.types.responses.ResponseStreamEvent
items is returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
str
|
Model identifier in format 'provider/model' (e.g., 'openai/gpt-4o') |
required |
input_data
|
Any
|
The input payload accepted by provider's Responses API. For OpenAI-compatible providers, this is typically a list mixing text, images, and tool instructions, or a dict per OpenAI spec. |
required |
tools
|
Optional[List[Union[dict[str, Any], Callable[..., Any]]]]
|
Optional tools for tool calling (Python callables or OpenAI tool dicts) |
None
|
tool_choice
|
Optional[Union[str, dict[str, Any]]]
|
Controls which tools the model can call |
None
|
max_output_tokens
|
Optional[int]
|
Maximum number of output tokens to generate |
None
|
temperature
|
Optional[float]
|
Controls randomness in the response (0.0 to 2.0) |
None
|
top_p
|
Optional[float]
|
Controls diversity via nucleus sampling (0.0 to 1.0) |
None
|
stream
|
Optional[bool]
|
Whether to stream response events |
None
|
api_key
|
Optional[str]
|
API key for the provider |
None
|
api_base
|
Optional[str]
|
Base URL for the provider API |
None
|
timeout
|
Optional[Union[float, int]]
|
Request timeout in seconds |
None
|
user
|
Optional[str]
|
Unique identifier for the end user |
None
|
**kwargs
|
Any
|
Additional provider-specific parameters |
{}
|
Returns:
Type | Description |
---|---|
Response | Iterator[ResponseStreamEvent]
|
Either a |
Response | Iterator[ResponseStreamEvent]
|
|
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the selected provider does not support the Responses API. |
Source code in src/any_llm/api.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
|