archastro.platform.v1.resources.ai
1# Copyright (c) 2026 ArchAstro Inc. Licensed under the MIT License. 2# This file is auto-generated by @archastro/sdk-generator. Do not edit. 3# Content hash: a1da119e9408 4 5from __future__ import annotations 6 7from collections.abc import AsyncIterator, Iterator 8from typing import ( 9 Any, 10 Literal, 11 Required, 12 TypedDict, 13) 14 15from pydantic import BaseModel, Field 16 17from ...runtime.http_client import HttpClient, SyncHttpClient 18from ...types.ai import ( 19 AIChatStreamDone, 20 AIChatStreamError, 21 AIChatStreamMessageComplete, 22 AIChatStreamMessageDelta, 23 AIChatStreamThinkingDelta, 24 AIChatStreamToolCallDelta, 25 AIChatStreamToolResult, 26 AICompletionResult, 27 AIEvaluationResult, 28 AIImageResult, 29) 30 31 32class StreamCreateInputMessagesItemToolCallsItem(TypedDict, total=False): 33 arguments: Required[dict[str, Any]] 34 "Arguments the model wants to pass to the tool, as a key-value map. Deserialize and validate these against the tool's input schema before executing." 35 id: Required[str] 36 "Unique identifier for this tool call, assigned by the model. Use this value as `id` when submitting the corresponding tool result." 37 name: Required[str] 38 'Name of the tool or function the model wants to invoke, e.g. `"web_search"` or `"run_code"`.' 39 thought_signature: str | None 40 "Opaque signature representing the model's internal reasoning that led to this tool call. `null` when the provider does not expose chain-of-thought data." 41 42 43class StreamCreateInputMessagesItemToolResultsItem(TypedDict, total=False): 44 content: str | None 45 "Plain-text output produced by the tool execution. `null` when the result is expressed entirely through `resolution`." 46 id: Required[str] 47 "ID of the tool call this result satisfies. Must match the `id` from the corresponding `AIToolCall`." 48 name: Required[str] 49 'Name of the tool or function that was executed, e.g. `"web_search"`. Must match the `name` from the corresponding `AIToolCall`.' 50 resolution: Any | None 51 "Structured result data from the tool execution. Shape varies by tool. `null` when the result is expressed as plain text in `content`." 52 53 54class StreamCreateInputMessagesItem(TypedDict, total=False): 55 content: str | None 56 "Plain-text content of the message. Present for `system`, `user`, and `assistant` messages. `null` when the message body is expressed through `content_parts` or `tool_calls`." 57 content_parts: list[dict[str, Any]] | None 58 'Multimodal content parts for the message, used when the body includes images or mixed media. Each part is a map with a `type` key (`"text"`, `"image_url"`, or `"image_data"`). `null` when `content` is set.' 59 resume_token: str | None 60 "Opaque token that can be passed on a subsequent request to resume this conversation from the current state. `null` when the provider does not support conversation resumption." 61 role: Required[str] 62 'The speaker role for this message. One of `"system"`, `"user"`, `"assistant"`, or `"tool"`.' 63 structured_output: Any | None 64 "Parsed structured data returned by the model when a JSON schema or structured-output mode was requested. Shape varies by the schema supplied at call time. `null` when structured output was not requested." 65 tool_calls: list[StreamCreateInputMessagesItemToolCallsItem] | None 66 "Tool calls requested by the model in an `assistant` message. Present only on assistant messages that invoke one or more tools. `null` on all other message roles." 67 tool_results: list[StreamCreateInputMessagesItemToolResultsItem] | None 68 "Tool execution results provided in a `tool` message. Each entry corresponds to a prior tool call by its `id`. `null` on all other message roles." 69 70 71class StreamCreateInputOptsToolsItemFunction(TypedDict, total=False): 72 description: str | None 73 "Human-readable description of what the function does. The model uses this to decide when to call the function. `null` if not provided." 74 name: Required[str] 75 'Unique name of the function that the model can invoke, e.g. `"get_weather"`.' 76 parameters: Required[dict[str, Any]] 77 'JSON Schema object describing the function\'s accepted parameters. Must be a valid JSON Schema of type `"object"`.' 78 79 80class StreamCreateInputOptsToolsItem(TypedDict): 81 function: StreamCreateInputOptsToolsItemFunction 82 "Callable function this tool exposes, including its name, description, and parameter schema." 83 type: str 84 'The tool type. Currently always `"function"`.' 85 86 87class StreamCreateInputOpts(TypedDict, total=False): 88 max_tokens: int | None 89 "Maximum number of tokens the model may generate. Omit for the model default." 90 model: Required[str] 91 'Model identifier, e.g. `"gpt-4o"` or `"claude-3-7-sonnet-latest"`.' 92 server_tools: list[dict[str, Any]] | None 93 'Server-managed tool declarations executed before the response. Each entry must include a `type` key; currently only `"search"` is supported.' 94 temperature: float | None 95 "Sampling temperature between `0.0` and `2.0`. Higher values produce more random output. Omit for the model default." 96 tool_choice: str | None 97 'Controls tool selection. One of `"auto"`, `"required"`, or `"none"`. Omit to let the model decide.' 98 tools: list[StreamCreateInputOptsToolsItem] | None 99 "OpenAI-compatible tool definitions available to the model. Omit when not using function calling." 100 101 102class StreamCreateInput(TypedDict, total=False): 103 "Stream a chat completion" 104 105 attribution: dict[str, Any] | None 106 "Optional caller tags recorded on the LLM-call accounting row. Allowed keys: `task_id` (max 64 chars), `work_id` (max 64), `agent_kind` (one of `worker`, `one_off`, `subagent`, `overseer`, `task_reviewer`, `interactive`, `daemon_job`), `agent_id` (max 64), `client` (max 32). Anything else is a 400." 107 context: dict[str, Any] | None 108 "Key-value map used to resolve template variables in message content. Omit if messages contain no templates." 109 messages: Required[list[StreamCreateInputMessagesItem]] 110 "Ordered list of conversation messages to send to the model." 111 opts: Required[StreamCreateInputOpts] 112 "Model and sampling configuration for this request." 113 session_id: str | None 114 "Optional UUID grouping this and other completions under one session in the Developers dashboard. Pass the same value across requests to link them; omit to auto-generate a per-request session." 115 116 117class CompletionCreateInputMessagesItemToolCallsItem(TypedDict, total=False): 118 arguments: Required[dict[str, Any]] 119 "Arguments the model wants to pass to the tool, as a key-value map. Deserialize and validate these against the tool's input schema before executing." 120 id: Required[str] 121 "Unique identifier for this tool call, assigned by the model. Use this value as `id` when submitting the corresponding tool result." 122 name: Required[str] 123 'Name of the tool or function the model wants to invoke, e.g. `"web_search"` or `"run_code"`.' 124 thought_signature: str | None 125 "Opaque signature representing the model's internal reasoning that led to this tool call. `null` when the provider does not expose chain-of-thought data." 126 127 128class CompletionCreateInputMessagesItemToolResultsItem(TypedDict, total=False): 129 content: str | None 130 "Plain-text output produced by the tool execution. `null` when the result is expressed entirely through `resolution`." 131 id: Required[str] 132 "ID of the tool call this result satisfies. Must match the `id` from the corresponding `AIToolCall`." 133 name: Required[str] 134 'Name of the tool or function that was executed, e.g. `"web_search"`. Must match the `name` from the corresponding `AIToolCall`.' 135 resolution: Any | None 136 "Structured result data from the tool execution. Shape varies by tool. `null` when the result is expressed as plain text in `content`." 137 138 139class CompletionCreateInputMessagesItem(TypedDict, total=False): 140 content: str | None 141 "Plain-text content of the message. Present for `system`, `user`, and `assistant` messages. `null` when the message body is expressed through `content_parts` or `tool_calls`." 142 content_parts: list[dict[str, Any]] | None 143 'Multimodal content parts for the message, used when the body includes images or mixed media. Each part is a map with a `type` key (`"text"`, `"image_url"`, or `"image_data"`). `null` when `content` is set.' 144 resume_token: str | None 145 "Opaque token that can be passed on a subsequent request to resume this conversation from the current state. `null` when the provider does not support conversation resumption." 146 role: Required[str] 147 'The speaker role for this message. One of `"system"`, `"user"`, `"assistant"`, or `"tool"`.' 148 structured_output: Any | None 149 "Parsed structured data returned by the model when a JSON schema or structured-output mode was requested. Shape varies by the schema supplied at call time. `null` when structured output was not requested." 150 tool_calls: list[CompletionCreateInputMessagesItemToolCallsItem] | None 151 "Tool calls requested by the model in an `assistant` message. Present only on assistant messages that invoke one or more tools. `null` on all other message roles." 152 tool_results: list[CompletionCreateInputMessagesItemToolResultsItem] | None 153 "Tool execution results provided in a `tool` message. Each entry corresponds to a prior tool call by its `id`. `null` on all other message roles." 154 155 156class CompletionCreateInputOptsToolsItemFunction(TypedDict, total=False): 157 description: str | None 158 "Human-readable description of what the function does. The model uses this to decide when to call the function. `null` if not provided." 159 name: Required[str] 160 'Unique name of the function that the model can invoke, e.g. `"get_weather"`.' 161 parameters: Required[dict[str, Any]] 162 'JSON Schema object describing the function\'s accepted parameters. Must be a valid JSON Schema of type `"object"`.' 163 164 165class CompletionCreateInputOptsToolsItem(TypedDict): 166 function: CompletionCreateInputOptsToolsItemFunction 167 "Callable function this tool exposes, including its name, description, and parameter schema." 168 type: str 169 'The tool type. Currently always `"function"`.' 170 171 172class CompletionCreateInputOpts(TypedDict, total=False): 173 max_tokens: int | None 174 "Maximum number of tokens the model may generate in the completion. Omit to use the model's default limit." 175 model: Required[str] 176 'Model identifier to use for the completion, e.g. `"gpt-4o"` or `"claude-3-7-sonnet-latest"`.' 177 server_tools: list[dict[str, Any]] | None 178 'Server-managed tool declarations executed before the response is returned. Each entry must include a `type` key; currently only `"search"` is supported.' 179 structured_output: dict[str, Any] | None 180 "Native structured-output configuration. Include a `schema` JSON Schema object and optional `name` and `strict` fields." 181 temperature: float | None 182 "Sampling temperature between `0.0` and `2.0`. Higher values produce more random output. Omit to use the model's default." 183 tool_choice: str | None 184 'Controls how the model selects tools. One of `"auto"`, `"required"`, or `"none"`. Omit to let the model decide.' 185 tools: list[CompletionCreateInputOptsToolsItem] | None 186 "OpenAI-compatible tool definitions available to the model. Omit when not using function calling." 187 188 189class CompletionCreateInput(TypedDict, total=False): 190 "Create a chat completion" 191 192 attribution: dict[str, Any] | None 193 "Optional caller tags recorded on the LLM-call accounting row. Allowed keys: `task_id` (max 64 chars), `work_id` (max 64), `agent_kind` (one of `worker`, `one_off`, `subagent`, `overseer`, `task_reviewer`, `interactive`, `daemon_job`), `agent_id` (max 64), `client` (max 32). Anything else is a 400." 194 context: dict[str, Any] | None 195 "Key-value map used to resolve template variables in message content. Omit if messages contain no templates." 196 messages: Required[list[CompletionCreateInputMessagesItem]] 197 "Ordered list of conversation messages to send to the model." 198 opts: Required[CompletionCreateInputOpts] 199 "Model and sampling configuration for this request." 200 session_id: str | None 201 "Optional UUID grouping this and other completions under one session in the Developers dashboard. Pass the same value across requests to link them; omit to auto-generate a per-request session." 202 203 204class EmbeddingSimilarityComparisonInput(TypedDict): 205 "Compare the embedding similarity of two texts" 206 207 text_a: str 208 "First text to embed and compare." 209 text_b: str 210 "Second text to embed and compare." 211 212 213class EvaluationEvaluationsInputImagesItem(TypedDict, total=False): 214 image_data: str | None 215 "Base64 image bytes; requires image_type." 216 image_type: str | None 217 "Image MIME type, such as image/png." 218 image_url: str | None 219 "Image URL; mutually exclusive with image_data." 220 type: Required[Literal["image"]] 221 222 223class EvaluationEvaluationsInput(TypedDict, total=False): 224 "Create an evaluation" 225 226 images: list[EvaluationEvaluationsInputImagesItem] | None 227 "Optional image content parts. Omitted or empty means no images. Requires model image support." 228 model: str | None 229 "Evaluation model identifier. Omit to use the platform default." 230 questions: Required[list[dict[str, Any] | dict[str, Any] | dict[str, Any]]] 231 "Nonempty list of boolean, choice, or score questions. Each question must include `id`, `type`, and `instructions`." 232 session_id: str | None 233 "Optional UUID grouping this evaluation under one session in the Developers dashboard. Generated when omitted." 234 state: Required[Any] 235 "Shared content the model judges. A string, JSON object, or JSON array. Every question in the request sees this same state." 236 237 238class ImageEditsInputImagesItem(TypedDict): 239 image_data: str 240 "The raw image content encoded as a base64 string (standard encoding, no line breaks)." 241 image_type: str 242 'MIME type of the image, e.g. `"image/png"` or `"image/jpeg"`. Must match the actual encoding of `image_data`.' 243 244 245class ImageEditsInput(TypedDict, total=False): 246 "Edit an image with a text prompt" 247 248 aspect_ratio: str | None 249 'Desired aspect ratio of the output, e.g. `"1:1"` or `"16:9"`. Not supported by all models; omit to use the model\'s default.' 250 background: str | None 251 "Background treatment for the output. Accepted values and behavior are model-dependent." 252 height: int | None 253 "Explicit output height in pixels. Takes precedence over `size` when both are provided. Not supported by all models." 254 image_size: str | None 255 'Output resolution tier for Gemini models, e.g. `"1K"`, `"2K"`, or `"4K"`. Ignored by non-Gemini models.' 256 images: Required[list[ImageEditsInputImagesItem]] 257 "One or more source images to edit. Each image must be supplied as a base64-encoded object." 258 model: str | None 259 "Model identifier to use for editing. Omit to use the platform default image model." 260 output_format: str | None 261 'Desired MIME type or format for the returned image. Common values: `"png"`, `"jpeg"`, `"webp"`. Defaults to the model\'s native format.' 262 prompt: Required[str] 263 "Natural-language description of the edit to apply to the source image(s)." 264 quality: str | None 265 "Quality preset for the output image. Accepted values and behavior are model-dependent." 266 session_id: str | None 267 "Optional session UUID for grouping provider attempts in usage records. Generated when omitted." 268 size: str | None 269 'Output dimensions as a WxH string, e.g. `"1024x1024"`. Applies to OpenAI-compatible models. Omit to use the model\'s default.' 270 style: str | None 271 "Style preset applied to the edit. Accepted values and behavior are model-dependent." 272 width: int | None 273 "Explicit output width in pixels. Takes precedence over `size` when both are provided. Not supported by all models." 274 275 276class ImageGenerationsInput(TypedDict, total=False): 277 "Generate an image from a text prompt" 278 279 aspect_ratio: str | None 280 'Desired aspect ratio of the output, e.g. `"1:1"` or `"16:9"`. Not supported by all models; omit to use the model\'s default.' 281 background: str | None 282 "Background treatment for the output. Accepted values and behavior are model-dependent." 283 height: int | None 284 "Explicit output height in pixels. Takes precedence over `size` when both are provided. Not supported by all models." 285 image_size: str | None 286 'Output resolution tier for Gemini models, e.g. `"1K"`, `"2K"`, or `"4K"`. Ignored by non-Gemini models.' 287 model: str | None 288 "Model identifier to use for generation. Omit to use the platform default image model." 289 n: int | None 290 "Number of images to generate. Defaults to `1`. Values greater than `1` are only supported by models that allow batch generation." 291 output_format: str | None 292 'Desired MIME type or format for the returned image. Common values: `"png"`, `"jpeg"`, `"webp"`. Defaults to the model\'s native format.' 293 prompt: Required[str] 294 "Natural-language description of the image to generate." 295 quality: str | None 296 "Quality preset for the output image. Accepted values and behavior are model-dependent." 297 session_id: str | None 298 "Optional session UUID for grouping provider attempts in usage records. Generated when omitted." 299 size: str | None 300 'Output dimensions as a WxH string, e.g. `"1024x1024"`. Applies to OpenAI-compatible models. Omit to use the model\'s default.' 301 style: str | None 302 "Style preset applied to the generated image. Accepted values and behavior are model-dependent." 303 width: int | None 304 "Explicit output width in pixels. Takes precedence over `size` when both are provided. Not supported by all models." 305 306 307class AiSessionTokenInput(TypedDict, total=False): 308 "Mint a principal-bound billing session token" 309 310 entitlement: Literal["llm_calls", "run_automation"] | None 311 restrictions: dict[str, Any] | None 312 ttl: int | None 313 user_id: Required[str] 314 315 316class ChatModelsResponseDataItem(BaseModel): 317 capabilities: list[Literal["image", "search", "temperature", "thinking"]] = Field( 318 ..., 319 description='Machine-readable model capabilities. `"image"` marks image-input chat, `"search"` marks built-in web search, `"temperature"` marks models that accept the temperature generation parameter, and `"thinking"` marks models with configurable reasoning. Empty when the catalog entry declares no special capabilities.', 320 ) 321 context_window: int | None = Field( 322 default=None, 323 description="Maximum context-window size in tokens this model accepts, when the platform publishes it. Use it to size prompt/history against the real window rather than a hardcoded default. `null` for entries whose window the platform does not report (e.g. legacy or mock model listings); clients should apply a conservative fallback in that case.", 324 ) 325 default: bool = Field( 326 ..., 327 description="`true` for the model the platform selects when an agent has no `default_model` configured, or for the system-wide fallback in image-generation contexts. Exactly one entry in any given model list carries this flag.", 328 ) 329 id: str = Field( 330 ..., 331 description='Provider-assigned model identifier used when specifying a model on API requests, e.g. `"claude-sonnet-4-6"` or `"gemini-2.5-flash"`.', 332 ) 333 input_media_formats: list[str] = Field( 334 ..., 335 description='MIME types accepted in chat `content_parts` image/file inputs for this model. For image-capable chat models this includes values such as `"image/png"`. Empty for text-only models.', 336 ) 337 name: str = Field( 338 ..., 339 description='Human-readable display label for this model, e.g. `"Claude Sonnet 4.6"` or `"Gemini 3.5 Flash (thinking)"`. Render this value directly in pickers rather than attempting to parse or transform `id`. Falls back to the `id` string when the catalog entry does not declare an explicit name.', 340 ) 341 output_media_formats: list[str] = Field( 342 ..., 343 description="MIME types this model can emit as media in chat responses. Empty for text-output models, including image-understanding models that only return text.", 344 ) 345 346 347class ChatModelsResponse(BaseModel): 348 """ 349 Successful response 350 """ 351 352 data: list[ChatModelsResponseDataItem] = Field( 353 ..., description="Array of available model objects. At least one entry is always present." 354 ) 355 356 357class EmbeddingSimilarityComparisonResponse(BaseModel): 358 """ 359 Successful response 360 """ 361 362 model: str = Field( 363 ..., description="Configured default embedding model key used for both texts." 364 ) 365 similarity_score: float = Field( 366 ..., 367 description="Cosine similarity from `-1.0` to `1.0`, computed as `1 - cosine_distance`.", 368 ) 369 370 371class EvaluationModelsResponseDataItem(BaseModel): 372 capabilities: list[Literal["image", "search", "temperature", "thinking"]] = Field( 373 ..., 374 description='Machine-readable model capabilities. `"image"` marks image-input chat, `"search"` marks built-in web search, `"temperature"` marks models that accept the temperature generation parameter, and `"thinking"` marks models with configurable reasoning. Empty when the catalog entry declares no special capabilities.', 375 ) 376 context_window: int | None = Field( 377 default=None, 378 description="Maximum context-window size in tokens this model accepts, when the platform publishes it. Use it to size prompt/history against the real window rather than a hardcoded default. `null` for entries whose window the platform does not report (e.g. legacy or mock model listings); clients should apply a conservative fallback in that case.", 379 ) 380 default: bool = Field( 381 ..., 382 description="`true` for the model the platform selects when an agent has no `default_model` configured, or for the system-wide fallback in image-generation contexts. Exactly one entry in any given model list carries this flag.", 383 ) 384 id: str = Field( 385 ..., 386 description='Provider-assigned model identifier used when specifying a model on API requests, e.g. `"claude-sonnet-4-6"` or `"gemini-2.5-flash"`.', 387 ) 388 input_media_formats: list[str] = Field( 389 ..., 390 description='MIME types accepted in chat `content_parts` image/file inputs for this model. For image-capable chat models this includes values such as `"image/png"`. Empty for text-only models.', 391 ) 392 name: str = Field( 393 ..., 394 description='Human-readable display label for this model, e.g. `"Claude Sonnet 4.6"` or `"Gemini 3.5 Flash (thinking)"`. Render this value directly in pickers rather than attempting to parse or transform `id`. Falls back to the `id` string when the catalog entry does not declare an explicit name.', 395 ) 396 output_media_formats: list[str] = Field( 397 ..., 398 description="MIME types this model can emit as media in chat responses. Empty for text-output models, including image-understanding models that only return text.", 399 ) 400 401 402class EvaluationModelsResponse(BaseModel): 403 """ 404 Successful response 405 """ 406 407 data: list[EvaluationModelsResponseDataItem] = Field( 408 ..., 409 description="Array of available evaluation model objects. At least one entry is always present.", 410 ) 411 412 413class ImageModelsResponseDataItem(BaseModel): 414 capabilities: list[Literal["image", "search", "temperature", "thinking"]] = Field( 415 ..., 416 description='Machine-readable model capabilities. `"image"` marks image-input chat, `"search"` marks built-in web search, `"temperature"` marks models that accept the temperature generation parameter, and `"thinking"` marks models with configurable reasoning. Empty when the catalog entry declares no special capabilities.', 417 ) 418 context_window: int | None = Field( 419 default=None, 420 description="Maximum context-window size in tokens this model accepts, when the platform publishes it. Use it to size prompt/history against the real window rather than a hardcoded default. `null` for entries whose window the platform does not report (e.g. legacy or mock model listings); clients should apply a conservative fallback in that case.", 421 ) 422 default: bool = Field( 423 ..., 424 description="`true` for the model the platform selects when an agent has no `default_model` configured, or for the system-wide fallback in image-generation contexts. Exactly one entry in any given model list carries this flag.", 425 ) 426 id: str = Field( 427 ..., 428 description='Provider-assigned model identifier used when specifying a model on API requests, e.g. `"claude-sonnet-4-6"` or `"gemini-2.5-flash"`.', 429 ) 430 input_media_formats: list[str] = Field( 431 ..., 432 description='MIME types accepted in chat `content_parts` image/file inputs for this model. For image-capable chat models this includes values such as `"image/png"`. Empty for text-only models.', 433 ) 434 name: str = Field( 435 ..., 436 description='Human-readable display label for this model, e.g. `"Claude Sonnet 4.6"` or `"Gemini 3.5 Flash (thinking)"`. Render this value directly in pickers rather than attempting to parse or transform `id`. Falls back to the `id` string when the catalog entry does not declare an explicit name.', 437 ) 438 output_media_formats: list[str] = Field( 439 ..., 440 description="MIME types this model can emit as media in chat responses. Empty for text-output models, including image-understanding models that only return text.", 441 ) 442 443 444class ImageModelsResponse(BaseModel): 445 """ 446 Successful response 447 """ 448 449 data: list[ImageModelsResponseDataItem] = Field( 450 ..., 451 description="Array of available image generation models, including their identifiers, human-readable names, and which one is the platform default.", 452 ) 453 454 455class AiSessionTokenResponse(BaseModel): 456 """ 457 Successful response 458 """ 459 460 expires_at: str 461 token: str 462 463 464class AiUsageResponseDataItem(BaseModel): 465 agent_id: str | None = Field( 466 default=None, 467 description="Agent ID for this group. Present only when grouped by `agent_id`.", 468 ) 469 agent_kind: str | None = Field( 470 default=None, 471 description="Agent kind for this group. Present only when grouped by `agent_kind`.", 472 ) 473 billed_usd: float | None = Field( 474 default=None, 475 description="Customer-billed cost for this group in USD. `null` when `priced` is `false`.", 476 ) 477 cache_read_tokens: int = Field(..., description="Summed cache-read tokens in this group.") 478 cache_write_tokens: int = Field(..., description="Summed cache-write tokens in this group.") 479 completion_tokens: int = Field( 480 ..., description="Summed completion (output) tokens in this group." 481 ) 482 hour: str | None = Field( 483 default=None, 484 description="Hour bucket (ISO 8601) for this group. Present only when grouped by `hour`.", 485 ) 486 model: str | None = Field( 487 default=None, 488 description="Model identifier for this group. Present only when grouped by `model`.", 489 ) 490 priced: bool = Field( 491 ..., 492 description="`true` when `billed_usd` was priced from the customer's active billing plan; `false` when the group could not be priced.", 493 ) 494 prompt_tokens: int = Field(..., description="Summed prompt (input) tokens in this group.") 495 requests: int = Field(..., description="Number of LLM calls in this group.") 496 task: str | None = Field( 497 default=None, 498 description="Caller task ID for this group. Present only when grouped by `task`.", 499 ) 500 501 502class AiUsageResponse(BaseModel): 503 """ 504 Successful response 505 """ 506 507 data: list[AiUsageResponseDataItem] = Field( 508 ..., 509 description="One row per group with request/token sums, the group key fields, `billed_usd`, and `priced`.", 510 ) 511 since: str = Field(..., description="Effective window start (ISO 8601).") 512 until: str = Field(..., description="Effective window end (ISO 8601).") 513 514 515class StreamCreateEventDone(TypedDict): 516 event: Literal["done"] 517 data: AIChatStreamDone 518 519 520class StreamCreateEventError(TypedDict): 521 event: Literal["error"] 522 data: AIChatStreamError 523 524 525class StreamCreateEventMessageComplete(TypedDict): 526 event: Literal["message_complete"] 527 data: AIChatStreamMessageComplete 528 529 530class StreamCreateEventMessageDelta(TypedDict): 531 event: Literal["message_delta"] 532 data: AIChatStreamMessageDelta 533 534 535class StreamCreateEventThinkingDelta(TypedDict): 536 event: Literal["thinking_delta"] 537 data: AIChatStreamThinkingDelta 538 539 540class StreamCreateEventToolCallDelta(TypedDict): 541 event: Literal["tool_call_delta"] 542 data: AIChatStreamToolCallDelta 543 544 545class StreamCreateEventToolResult(TypedDict): 546 event: Literal["tool_result"] 547 data: AIChatStreamToolResult 548 549 550StreamCreateEvent = ( 551 StreamCreateEventDone 552 | StreamCreateEventError 553 | StreamCreateEventMessageComplete 554 | StreamCreateEventMessageDelta 555 | StreamCreateEventThinkingDelta 556 | StreamCreateEventToolCallDelta 557 | StreamCreateEventToolResult 558) 559 560 561class AsyncStreamResource: 562 def __init__(self, http: HttpClient): 563 self._http = http 564 565 async def create(self, input: StreamCreateInput) -> AsyncIterator[StreamCreateEvent]: 566 """ 567 Stream a chat completion 568 Streams a chat completion over Server-Sent Events. Emits `thinking_delta` for 569 supported reasoning models, `message_delta`, `message_complete`, 570 `tool_call_*`, `tool_result`, and a terminal `done` (or `error`) event. Same 571 request shape as the non-streaming completion endpoint; the app must have the 572 `llm_calls` entitlement. 573 574 Args: 575 input: Request body. 576 input.attribution: Optional caller tags recorded on the LLM-call accounting row. Allowed keys: `task_id` (max 64 chars), `work_id` (max 64), `agent_kind` (one of `worker`, `one_off`, `subagent`, `overseer`, `task_reviewer`, `interactive`, `daemon_job`), `agent_id` (max 64), `client` (max 32). Anything else is a 400. 577 input.context: Key-value map used to resolve template variables in message content. Omit if messages contain no templates. 578 input.messages: Ordered list of conversation messages to send to the model. 579 input.opts: Model and sampling configuration for this request. 580 input.session_id: Optional UUID grouping this and other completions under one session in the Developers dashboard. Pass the same value across requests to link them; omit to auto-generate a per-request session. 581 582 Returns: 583 Server-Sent Events stream 584 """ 585 async for event in self._http.stream_sse( 586 "/api/v1/ai/chat/completions/stream", method="POST", body=input 587 ): 588 yield event 589 590 591class AsyncCompletionResource: 592 def __init__(self, http: HttpClient): 593 self._http = http 594 self.stream = AsyncStreamResource(http) 595 596 async def create(self, input: CompletionCreateInput) -> AICompletionResult: 597 """ 598 Create a chat completion 599 Sends a list of messages to the configured AI provider and returns a single 600 completion. Use this endpoint when you want direct, low-level access to the 601 underlying model without any workflow or agent orchestration. 602 The authenticated app must have the `llm_calls` entitlement enabled on its 603 plan. Requests that exceed the plan quota are rejected with `402`. Token 604 usage is recorded against the authenticated app and organization. 605 Supply `tools` and `tool_choice` to enable OpenAI-compatible function 606 calling. Use `server_tools` to activate platform-managed tools such as 607 search that run on the server side before the response is returned. 608 609 Args: 610 input: Request body. 611 input.attribution: Optional caller tags recorded on the LLM-call accounting row. Allowed keys: `task_id` (max 64 chars), `work_id` (max 64), `agent_kind` (one of `worker`, `one_off`, `subagent`, `overseer`, `task_reviewer`, `interactive`, `daemon_job`), `agent_id` (max 64), `client` (max 32). Anything else is a 400. 612 input.context: Key-value map used to resolve template variables in message content. Omit if messages contain no templates. 613 input.messages: Ordered list of conversation messages to send to the model. 614 input.opts: Model and sampling configuration for this request. 615 input.session_id: Optional UUID grouping this and other completions under one session in the Developers dashboard. Pass the same value across requests to link them; omit to auto-generate a per-request session. 616 617 Returns: 618 The completed AI response, including the generated message, finish reason, and token usage. 619 """ 620 return await self._http.request( 621 "/api/v1/ai/chat/completions", 622 method="POST", 623 body=input, 624 response_type=AICompletionResult, 625 ) 626 627 628class AsyncChatResource: 629 def __init__(self, http: HttpClient): 630 self._http = http 631 self.completions = AsyncCompletionResource(http) 632 633 async def models(self) -> ChatModelsResponse: 634 """ 635 List available AI models 636 Returns the set of AI models that can be used with the chat completion and 637 workflow endpoints. The list reflects models currently enabled for the 638 platform and includes each model's identifier and whether it is the default. 639 Use the `model` field from any entry in `data` as the value for 640 `opts.model` when calling the completions or workflows endpoint. 641 642 Returns: 643 Successful response 644 """ 645 return await self._http.request("/api/v1/ai/chat/models", response_type=ChatModelsResponse) 646 647 648class AsyncEmbeddingResource: 649 def __init__(self, http: HttpClient): 650 self._http = http 651 652 async def similarity_comparison( 653 self, input: EmbeddingSimilarityComparisonInput 654 ) -> EmbeddingSimilarityComparisonResponse: 655 """ 656 Compare the embedding similarity of two texts 657 Embeds both texts in one synchronous request using the platform's default 658 embedding model, then returns their cosine similarity. The score uses the 659 same `1 - cosine_distance` convention as context retrieval. A score near 660 `1.0` indicates similar vector direction; lower scores indicate less similar 661 text. This endpoint is intended for authenticated users interactively 662 exploring how the platform's retrieval similarity behaves. 663 664 Args: 665 input: Request body. 666 input.text_a: First text to embed and compare. 667 input.text_b: Second text to embed and compare. 668 669 Returns: 670 Successful response 671 """ 672 return await self._http.request( 673 "/api/v1/ai/embedding/similarity_comparison", 674 method="POST", 675 body=input, 676 response_type=EmbeddingSimilarityComparisonResponse, 677 ) 678 679 680class AsyncEvaluationResource: 681 def __init__(self, http: HttpClient): 682 self._http = http 683 684 async def evaluations(self, input: EvaluationEvaluationsInput) -> AIEvaluationResult: 685 """ 686 Create an evaluation 687 Sends a shared `state` and a list of typed questions to an evaluation 688 model and returns typed answers. This is not chat completion and not 689 JSON-schema structured output: there is no generated text. 690 Each question is a `boolean`, `choice`, or `score` object with its own 691 `id`. Answers carry that `id`, including a `refusal` answer containing 692 only `id` and `type` when the model declines to judge a question. 693 Image input, labelled score levels, and refusal answers are model-dependent. 694 Images are separate from `state` and use the chat completion image-part format. 695 Models without image support reject image input with `400 unsupported_capability`. 696 The authenticated app must have the `llm_calls` entitlement enabled on its 697 plan. Requests that exceed the plan quota are rejected with `402`. Token 698 usage is recorded against the authenticated app and organization. 699 700 Args: 701 input: Request body. 702 input.images: Optional image content parts. Omitted or empty means no images. Requires model image support. 703 input.model: Evaluation model identifier. Omit to use the platform default. 704 input.questions: Nonempty list of boolean, choice, or score questions. Each question must include `id`, `type`, and `instructions`. 705 input.session_id: Optional UUID grouping this evaluation under one session in the Developers dashboard. Generated when omitted. 706 input.state: Shared content the model judges. A string, JSON object, or JSON array. Every question in the request sees this same state. 707 708 Returns: 709 Typed boolean, choice, score, or refusal answers, plus model and usage. 710 """ 711 return await self._http.request( 712 "/api/v1/ai/evaluation/evaluations", 713 method="POST", 714 body=input, 715 response_type=AIEvaluationResult, 716 ) 717 718 async def models(self) -> EvaluationModelsResponse: 719 """ 720 List available evaluation models 721 Returns the set of evaluation models that can be used with the evaluations 722 endpoint. The list reflects models currently enabled for the platform and 723 includes each model's identifier and whether it is the default. 724 Use the `id` field from any entry in `data` as the `model` value when 725 calling the evaluations endpoint. 726 727 Returns: 728 Successful response 729 """ 730 return await self._http.request( 731 "/api/v1/ai/evaluation/models", 732 response_type=EvaluationModelsResponse, 733 ) 734 735 736class AsyncImageResource: 737 def __init__(self, http: HttpClient): 738 self._http = http 739 740 async def edits(self, input: ImageEditsInput) -> AIImageResult: 741 """ 742 Edit an image with a text prompt 743 Applies a text-guided edit to one or more source images and returns the 744 resulting image. Pass the source images as base64-encoded objects in the 745 `images` array alongside a `prompt` describing the desired modification. 746 The underlying provider is selected by the `model` parameter. Omit `model` 747 to use the platform default. Size, quality, style, and format options are 748 forwarded to the provider as-is; unsupported combinations for a given model 749 return a 422 error with the provider's error message. 750 This endpoint requires authentication. The request is billed against the 751 workspace associated with the authenticated user. 752 753 Args: 754 input: Request body. 755 input.aspect_ratio: Desired aspect ratio of the output, e.g. `"1:1"` or `"16:9"`. Not supported by all models; omit to use the model's default. 756 input.background: Background treatment for the output. Accepted values and behavior are model-dependent. 757 input.height: Explicit output height in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 758 input.image_size: Output resolution tier for Gemini models, e.g. `"1K"`, `"2K"`, or `"4K"`. Ignored by non-Gemini models. 759 input.images: One or more source images to edit. Each image must be supplied as a base64-encoded object. 760 input.model: Model identifier to use for editing. Omit to use the platform default image model. 761 input.output_format: Desired MIME type or format for the returned image. Common values: `"png"`, `"jpeg"`, `"webp"`. Defaults to the model's native format. 762 input.prompt: Natural-language description of the edit to apply to the source image(s). 763 input.quality: Quality preset for the output image. Accepted values and behavior are model-dependent. 764 input.session_id: Optional session UUID for grouping provider attempts in usage records. Generated when omitted. 765 input.size: Output dimensions as a WxH string, e.g. `"1024x1024"`. Applies to OpenAI-compatible models. Omit to use the model's default. 766 input.style: Style preset applied to the edit. Accepted values and behavior are model-dependent. 767 input.width: Explicit output width in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 768 769 Returns: 770 The resulting edited image, including base64 data or a URL depending on the model. 771 """ 772 return await self._http.request( 773 "/api/v1/ai/image/edits", 774 method="POST", 775 body=input, 776 response_type=AIImageResult, 777 ) 778 779 async def generations(self, input: ImageGenerationsInput) -> AIImageResult: 780 """ 781 Generate an image from a text prompt 782 Generates one or more images from a natural-language `prompt` using the 783 specified AI image model. The response contains the first generated image; 784 use `n` to request additional images (where supported by the model). 785 The underlying provider is selected by the `model` parameter. Omit `model` 786 to use the platform default. Size, quality, style, and format options are 787 forwarded to the provider as-is; unsupported combinations for a given model 788 return a 422 error with the provider's error message. 789 This endpoint requires authentication. The request is billed against the 790 workspace associated with the authenticated user. 791 792 Args: 793 input: Request body. 794 input.aspect_ratio: Desired aspect ratio of the output, e.g. `"1:1"` or `"16:9"`. Not supported by all models; omit to use the model's default. 795 input.background: Background treatment for the output. Accepted values and behavior are model-dependent. 796 input.height: Explicit output height in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 797 input.image_size: Output resolution tier for Gemini models, e.g. `"1K"`, `"2K"`, or `"4K"`. Ignored by non-Gemini models. 798 input.model: Model identifier to use for generation. Omit to use the platform default image model. 799 input.n: Number of images to generate. Defaults to `1`. Values greater than `1` are only supported by models that allow batch generation. 800 input.output_format: Desired MIME type or format for the returned image. Common values: `"png"`, `"jpeg"`, `"webp"`. Defaults to the model's native format. 801 input.prompt: Natural-language description of the image to generate. 802 input.quality: Quality preset for the output image. Accepted values and behavior are model-dependent. 803 input.session_id: Optional session UUID for grouping provider attempts in usage records. Generated when omitted. 804 input.size: Output dimensions as a WxH string, e.g. `"1024x1024"`. Applies to OpenAI-compatible models. Omit to use the model's default. 805 input.style: Style preset applied to the generated image. Accepted values and behavior are model-dependent. 806 input.width: Explicit output width in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 807 808 Returns: 809 The generated image, including base64 data or a URL depending on the model. 810 """ 811 return await self._http.request( 812 "/api/v1/ai/image/generations", 813 method="POST", 814 body=input, 815 response_type=AIImageResult, 816 ) 817 818 async def models(self) -> ImageModelsResponse: 819 """ 820 List available image generation models 821 Returns the list of image generation models available on the platform. 822 Exactly one entry in the list carries `default: true`, indicating the model 823 used when no `model` parameter is supplied to the generation or editing 824 endpoints. 825 This endpoint requires authentication and reflects the models enabled for 826 the authenticated user's workspace. 827 828 Returns: 829 Successful response 830 """ 831 return await self._http.request( 832 "/api/v1/ai/image/models", 833 response_type=ImageModelsResponse, 834 ) 835 836 837class AsyncAiResource: 838 def __init__(self, http: HttpClient): 839 self._http = http 840 self.chat = AsyncChatResource(http) 841 self.embedding = AsyncEmbeddingResource(http) 842 self.evaluation = AsyncEvaluationResource(http) 843 self.image = AsyncImageResource(http) 844 845 async def session_token(self, input: AiSessionTokenInput) -> AiSessionTokenResponse: 846 """ 847 Mint a principal-bound billing session token 848 849 Args: 850 input: Request body. 851 852 Returns: 853 Successful response 854 """ 855 return await self._http.request( 856 "/api/v1/ai/session_token", 857 method="POST", 858 body=input, 859 response_type=AiSessionTokenResponse, 860 ) 861 862 async def usage( 863 self, 864 *, 865 since: str | None = None, 866 until: str | None = None, 867 group_by: list[Literal["task", "model", "agent_kind", "agent_id", "hour"]] | None = None, 868 task: list[str] | None = None, 869 limit: int | None = None, 870 ) -> AiUsageResponse: 871 """ 872 Read the authenticated user's LLM usage 873 Returns the authenticated user's own LLM usage aggregated over a bounded 874 time window. Each row carries request and token sums plus the customer-billed 875 cost for the group. Cost is derived from the customer's active billing plan; 876 provider-reported cost is never returned. 877 Pass `group_by` one or more times to choose the grouping dimensions 878 (`task`, `model`, `agent_kind`, `agent_id`, `hour`). The window (`since` to 879 `until`) may span at most 31 days. Results are capped at `limit` groups. 880 881 Args: 882 since: Window start as an ISO 8601 timestamp (inclusive). Defaults to 7 days before `until`. 883 until: Window end as an ISO 8601 timestamp (inclusive). Defaults to now. 884 group_by: Grouping dimensions. Repeat for multiple dimensions (e.g. `group_by[]=task&group_by[]=model`). Defaults to `model`. 885 task: Restrict results to these caller task IDs. Omit to include every task. 886 limit: Maximum number of groups to return. Defaults to 50; maximum is 200. 887 888 Returns: 889 Successful response 890 """ 891 query: dict[str, object] = {} 892 if since is not None: 893 query["since"] = since 894 if until is not None: 895 query["until"] = until 896 if group_by is not None: 897 query["group_by"] = group_by 898 if task is not None: 899 query["task"] = task 900 if limit is not None: 901 query["limit"] = limit 902 return await self._http.request( 903 "/api/v1/ai/usage", 904 query=query, 905 response_type=AiUsageResponse, 906 ) 907 908 909class StreamResource: 910 def __init__(self, http: SyncHttpClient): 911 self._http = http 912 913 def create(self, input: StreamCreateInput) -> Iterator[StreamCreateEvent]: 914 """ 915 Stream a chat completion 916 Streams a chat completion over Server-Sent Events. Emits `thinking_delta` for 917 supported reasoning models, `message_delta`, `message_complete`, 918 `tool_call_*`, `tool_result`, and a terminal `done` (or `error`) event. Same 919 request shape as the non-streaming completion endpoint; the app must have the 920 `llm_calls` entitlement. 921 922 Args: 923 input: Request body. 924 input.attribution: Optional caller tags recorded on the LLM-call accounting row. Allowed keys: `task_id` (max 64 chars), `work_id` (max 64), `agent_kind` (one of `worker`, `one_off`, `subagent`, `overseer`, `task_reviewer`, `interactive`, `daemon_job`), `agent_id` (max 64), `client` (max 32). Anything else is a 400. 925 input.context: Key-value map used to resolve template variables in message content. Omit if messages contain no templates. 926 input.messages: Ordered list of conversation messages to send to the model. 927 input.opts: Model and sampling configuration for this request. 928 input.session_id: Optional UUID grouping this and other completions under one session in the Developers dashboard. Pass the same value across requests to link them; omit to auto-generate a per-request session. 929 930 Returns: 931 Server-Sent Events stream 932 """ 933 yield from self._http.stream_sse_sync( 934 "/api/v1/ai/chat/completions/stream", method="POST", body=input 935 ) 936 937 938class CompletionResource: 939 def __init__(self, http: SyncHttpClient): 940 self._http = http 941 self.stream = StreamResource(http) 942 943 def create(self, input: CompletionCreateInput) -> AICompletionResult: 944 """ 945 Create a chat completion 946 Sends a list of messages to the configured AI provider and returns a single 947 completion. Use this endpoint when you want direct, low-level access to the 948 underlying model without any workflow or agent orchestration. 949 The authenticated app must have the `llm_calls` entitlement enabled on its 950 plan. Requests that exceed the plan quota are rejected with `402`. Token 951 usage is recorded against the authenticated app and organization. 952 Supply `tools` and `tool_choice` to enable OpenAI-compatible function 953 calling. Use `server_tools` to activate platform-managed tools such as 954 search that run on the server side before the response is returned. 955 956 Args: 957 input: Request body. 958 input.attribution: Optional caller tags recorded on the LLM-call accounting row. Allowed keys: `task_id` (max 64 chars), `work_id` (max 64), `agent_kind` (one of `worker`, `one_off`, `subagent`, `overseer`, `task_reviewer`, `interactive`, `daemon_job`), `agent_id` (max 64), `client` (max 32). Anything else is a 400. 959 input.context: Key-value map used to resolve template variables in message content. Omit if messages contain no templates. 960 input.messages: Ordered list of conversation messages to send to the model. 961 input.opts: Model and sampling configuration for this request. 962 input.session_id: Optional UUID grouping this and other completions under one session in the Developers dashboard. Pass the same value across requests to link them; omit to auto-generate a per-request session. 963 964 Returns: 965 The completed AI response, including the generated message, finish reason, and token usage. 966 """ 967 return self._http.request( 968 "/api/v1/ai/chat/completions", 969 method="POST", 970 body=input, 971 response_type=AICompletionResult, 972 ) 973 974 975class ChatResource: 976 def __init__(self, http: SyncHttpClient): 977 self._http = http 978 self.completions = CompletionResource(http) 979 980 def models(self) -> ChatModelsResponse: 981 """ 982 List available AI models 983 Returns the set of AI models that can be used with the chat completion and 984 workflow endpoints. The list reflects models currently enabled for the 985 platform and includes each model's identifier and whether it is the default. 986 Use the `model` field from any entry in `data` as the value for 987 `opts.model` when calling the completions or workflows endpoint. 988 989 Returns: 990 Successful response 991 """ 992 return self._http.request("/api/v1/ai/chat/models", response_type=ChatModelsResponse) 993 994 995class EmbeddingResource: 996 def __init__(self, http: SyncHttpClient): 997 self._http = http 998 999 def similarity_comparison( 1000 self, input: EmbeddingSimilarityComparisonInput 1001 ) -> EmbeddingSimilarityComparisonResponse: 1002 """ 1003 Compare the embedding similarity of two texts 1004 Embeds both texts in one synchronous request using the platform's default 1005 embedding model, then returns their cosine similarity. The score uses the 1006 same `1 - cosine_distance` convention as context retrieval. A score near 1007 `1.0` indicates similar vector direction; lower scores indicate less similar 1008 text. This endpoint is intended for authenticated users interactively 1009 exploring how the platform's retrieval similarity behaves. 1010 1011 Args: 1012 input: Request body. 1013 input.text_a: First text to embed and compare. 1014 input.text_b: Second text to embed and compare. 1015 1016 Returns: 1017 Successful response 1018 """ 1019 return self._http.request( 1020 "/api/v1/ai/embedding/similarity_comparison", 1021 method="POST", 1022 body=input, 1023 response_type=EmbeddingSimilarityComparisonResponse, 1024 ) 1025 1026 1027class EvaluationResource: 1028 def __init__(self, http: SyncHttpClient): 1029 self._http = http 1030 1031 def evaluations(self, input: EvaluationEvaluationsInput) -> AIEvaluationResult: 1032 """ 1033 Create an evaluation 1034 Sends a shared `state` and a list of typed questions to an evaluation 1035 model and returns typed answers. This is not chat completion and not 1036 JSON-schema structured output: there is no generated text. 1037 Each question is a `boolean`, `choice`, or `score` object with its own 1038 `id`. Answers carry that `id`, including a `refusal` answer containing 1039 only `id` and `type` when the model declines to judge a question. 1040 Image input, labelled score levels, and refusal answers are model-dependent. 1041 Images are separate from `state` and use the chat completion image-part format. 1042 Models without image support reject image input with `400 unsupported_capability`. 1043 The authenticated app must have the `llm_calls` entitlement enabled on its 1044 plan. Requests that exceed the plan quota are rejected with `402`. Token 1045 usage is recorded against the authenticated app and organization. 1046 1047 Args: 1048 input: Request body. 1049 input.images: Optional image content parts. Omitted or empty means no images. Requires model image support. 1050 input.model: Evaluation model identifier. Omit to use the platform default. 1051 input.questions: Nonempty list of boolean, choice, or score questions. Each question must include `id`, `type`, and `instructions`. 1052 input.session_id: Optional UUID grouping this evaluation under one session in the Developers dashboard. Generated when omitted. 1053 input.state: Shared content the model judges. A string, JSON object, or JSON array. Every question in the request sees this same state. 1054 1055 Returns: 1056 Typed boolean, choice, score, or refusal answers, plus model and usage. 1057 """ 1058 return self._http.request( 1059 "/api/v1/ai/evaluation/evaluations", 1060 method="POST", 1061 body=input, 1062 response_type=AIEvaluationResult, 1063 ) 1064 1065 def models(self) -> EvaluationModelsResponse: 1066 """ 1067 List available evaluation models 1068 Returns the set of evaluation models that can be used with the evaluations 1069 endpoint. The list reflects models currently enabled for the platform and 1070 includes each model's identifier and whether it is the default. 1071 Use the `id` field from any entry in `data` as the `model` value when 1072 calling the evaluations endpoint. 1073 1074 Returns: 1075 Successful response 1076 """ 1077 return self._http.request( 1078 "/api/v1/ai/evaluation/models", 1079 response_type=EvaluationModelsResponse, 1080 ) 1081 1082 1083class ImageResource: 1084 def __init__(self, http: SyncHttpClient): 1085 self._http = http 1086 1087 def edits(self, input: ImageEditsInput) -> AIImageResult: 1088 """ 1089 Edit an image with a text prompt 1090 Applies a text-guided edit to one or more source images and returns the 1091 resulting image. Pass the source images as base64-encoded objects in the 1092 `images` array alongside a `prompt` describing the desired modification. 1093 The underlying provider is selected by the `model` parameter. Omit `model` 1094 to use the platform default. Size, quality, style, and format options are 1095 forwarded to the provider as-is; unsupported combinations for a given model 1096 return a 422 error with the provider's error message. 1097 This endpoint requires authentication. The request is billed against the 1098 workspace associated with the authenticated user. 1099 1100 Args: 1101 input: Request body. 1102 input.aspect_ratio: Desired aspect ratio of the output, e.g. `"1:1"` or `"16:9"`. Not supported by all models; omit to use the model's default. 1103 input.background: Background treatment for the output. Accepted values and behavior are model-dependent. 1104 input.height: Explicit output height in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 1105 input.image_size: Output resolution tier for Gemini models, e.g. `"1K"`, `"2K"`, or `"4K"`. Ignored by non-Gemini models. 1106 input.images: One or more source images to edit. Each image must be supplied as a base64-encoded object. 1107 input.model: Model identifier to use for editing. Omit to use the platform default image model. 1108 input.output_format: Desired MIME type or format for the returned image. Common values: `"png"`, `"jpeg"`, `"webp"`. Defaults to the model's native format. 1109 input.prompt: Natural-language description of the edit to apply to the source image(s). 1110 input.quality: Quality preset for the output image. Accepted values and behavior are model-dependent. 1111 input.session_id: Optional session UUID for grouping provider attempts in usage records. Generated when omitted. 1112 input.size: Output dimensions as a WxH string, e.g. `"1024x1024"`. Applies to OpenAI-compatible models. Omit to use the model's default. 1113 input.style: Style preset applied to the edit. Accepted values and behavior are model-dependent. 1114 input.width: Explicit output width in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 1115 1116 Returns: 1117 The resulting edited image, including base64 data or a URL depending on the model. 1118 """ 1119 return self._http.request( 1120 "/api/v1/ai/image/edits", 1121 method="POST", 1122 body=input, 1123 response_type=AIImageResult, 1124 ) 1125 1126 def generations(self, input: ImageGenerationsInput) -> AIImageResult: 1127 """ 1128 Generate an image from a text prompt 1129 Generates one or more images from a natural-language `prompt` using the 1130 specified AI image model. The response contains the first generated image; 1131 use `n` to request additional images (where supported by the model). 1132 The underlying provider is selected by the `model` parameter. Omit `model` 1133 to use the platform default. Size, quality, style, and format options are 1134 forwarded to the provider as-is; unsupported combinations for a given model 1135 return a 422 error with the provider's error message. 1136 This endpoint requires authentication. The request is billed against the 1137 workspace associated with the authenticated user. 1138 1139 Args: 1140 input: Request body. 1141 input.aspect_ratio: Desired aspect ratio of the output, e.g. `"1:1"` or `"16:9"`. Not supported by all models; omit to use the model's default. 1142 input.background: Background treatment for the output. Accepted values and behavior are model-dependent. 1143 input.height: Explicit output height in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 1144 input.image_size: Output resolution tier for Gemini models, e.g. `"1K"`, `"2K"`, or `"4K"`. Ignored by non-Gemini models. 1145 input.model: Model identifier to use for generation. Omit to use the platform default image model. 1146 input.n: Number of images to generate. Defaults to `1`. Values greater than `1` are only supported by models that allow batch generation. 1147 input.output_format: Desired MIME type or format for the returned image. Common values: `"png"`, `"jpeg"`, `"webp"`. Defaults to the model's native format. 1148 input.prompt: Natural-language description of the image to generate. 1149 input.quality: Quality preset for the output image. Accepted values and behavior are model-dependent. 1150 input.session_id: Optional session UUID for grouping provider attempts in usage records. Generated when omitted. 1151 input.size: Output dimensions as a WxH string, e.g. `"1024x1024"`. Applies to OpenAI-compatible models. Omit to use the model's default. 1152 input.style: Style preset applied to the generated image. Accepted values and behavior are model-dependent. 1153 input.width: Explicit output width in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 1154 1155 Returns: 1156 The generated image, including base64 data or a URL depending on the model. 1157 """ 1158 return self._http.request( 1159 "/api/v1/ai/image/generations", 1160 method="POST", 1161 body=input, 1162 response_type=AIImageResult, 1163 ) 1164 1165 def models(self) -> ImageModelsResponse: 1166 """ 1167 List available image generation models 1168 Returns the list of image generation models available on the platform. 1169 Exactly one entry in the list carries `default: true`, indicating the model 1170 used when no `model` parameter is supplied to the generation or editing 1171 endpoints. 1172 This endpoint requires authentication and reflects the models enabled for 1173 the authenticated user's workspace. 1174 1175 Returns: 1176 Successful response 1177 """ 1178 return self._http.request("/api/v1/ai/image/models", response_type=ImageModelsResponse) 1179 1180 1181class AiResource: 1182 def __init__(self, http: SyncHttpClient): 1183 self._http = http 1184 self.chat = ChatResource(http) 1185 self.embedding = EmbeddingResource(http) 1186 self.evaluation = EvaluationResource(http) 1187 self.image = ImageResource(http) 1188 1189 def session_token(self, input: AiSessionTokenInput) -> AiSessionTokenResponse: 1190 """ 1191 Mint a principal-bound billing session token 1192 1193 Args: 1194 input: Request body. 1195 1196 Returns: 1197 Successful response 1198 """ 1199 return self._http.request( 1200 "/api/v1/ai/session_token", 1201 method="POST", 1202 body=input, 1203 response_type=AiSessionTokenResponse, 1204 ) 1205 1206 def usage( 1207 self, 1208 *, 1209 since: str | None = None, 1210 until: str | None = None, 1211 group_by: list[Literal["task", "model", "agent_kind", "agent_id", "hour"]] | None = None, 1212 task: list[str] | None = None, 1213 limit: int | None = None, 1214 ) -> AiUsageResponse: 1215 """ 1216 Read the authenticated user's LLM usage 1217 Returns the authenticated user's own LLM usage aggregated over a bounded 1218 time window. Each row carries request and token sums plus the customer-billed 1219 cost for the group. Cost is derived from the customer's active billing plan; 1220 provider-reported cost is never returned. 1221 Pass `group_by` one or more times to choose the grouping dimensions 1222 (`task`, `model`, `agent_kind`, `agent_id`, `hour`). The window (`since` to 1223 `until`) may span at most 31 days. Results are capped at `limit` groups. 1224 1225 Args: 1226 since: Window start as an ISO 8601 timestamp (inclusive). Defaults to 7 days before `until`. 1227 until: Window end as an ISO 8601 timestamp (inclusive). Defaults to now. 1228 group_by: Grouping dimensions. Repeat for multiple dimensions (e.g. `group_by[]=task&group_by[]=model`). Defaults to `model`. 1229 task: Restrict results to these caller task IDs. Omit to include every task. 1230 limit: Maximum number of groups to return. Defaults to 50; maximum is 200. 1231 1232 Returns: 1233 Successful response 1234 """ 1235 query: dict[str, object] = {} 1236 if since is not None: 1237 query["since"] = since 1238 if until is not None: 1239 query["until"] = until 1240 if group_by is not None: 1241 query["group_by"] = group_by 1242 if task is not None: 1243 query["task"] = task 1244 if limit is not None: 1245 query["limit"] = limit 1246 return self._http.request("/api/v1/ai/usage", query=query, response_type=AiUsageResponse)
33class StreamCreateInputMessagesItemToolCallsItem(TypedDict, total=False): 34 arguments: Required[dict[str, Any]] 35 "Arguments the model wants to pass to the tool, as a key-value map. Deserialize and validate these against the tool's input schema before executing." 36 id: Required[str] 37 "Unique identifier for this tool call, assigned by the model. Use this value as `id` when submitting the corresponding tool result." 38 name: Required[str] 39 'Name of the tool or function the model wants to invoke, e.g. `"web_search"` or `"run_code"`.' 40 thought_signature: str | None 41 "Opaque signature representing the model's internal reasoning that led to this tool call. `null` when the provider does not expose chain-of-thought data."
Arguments the model wants to pass to the tool, as a key-value map. Deserialize and validate these against the tool's input schema before executing.
Unique identifier for this tool call, assigned by the model. Use this value as id when submitting the corresponding tool result.
44class StreamCreateInputMessagesItemToolResultsItem(TypedDict, total=False): 45 content: str | None 46 "Plain-text output produced by the tool execution. `null` when the result is expressed entirely through `resolution`." 47 id: Required[str] 48 "ID of the tool call this result satisfies. Must match the `id` from the corresponding `AIToolCall`." 49 name: Required[str] 50 'Name of the tool or function that was executed, e.g. `"web_search"`. Must match the `name` from the corresponding `AIToolCall`.' 51 resolution: Any | None 52 "Structured result data from the tool execution. Shape varies by tool. `null` when the result is expressed as plain text in `content`."
Plain-text output produced by the tool execution. null when the result is expressed entirely through resolution.
ID of the tool call this result satisfies. Must match the id from the corresponding AIToolCall.
Name of the tool or function that was executed, e.g. "web_search". Must match the name from the corresponding AIToolCall.
Structured result data from the tool execution. Shape varies by tool. null when the result is expressed as plain text in content.
55class StreamCreateInputMessagesItem(TypedDict, total=False): 56 content: str | None 57 "Plain-text content of the message. Present for `system`, `user`, and `assistant` messages. `null` when the message body is expressed through `content_parts` or `tool_calls`." 58 content_parts: list[dict[str, Any]] | None 59 'Multimodal content parts for the message, used when the body includes images or mixed media. Each part is a map with a `type` key (`"text"`, `"image_url"`, or `"image_data"`). `null` when `content` is set.' 60 resume_token: str | None 61 "Opaque token that can be passed on a subsequent request to resume this conversation from the current state. `null` when the provider does not support conversation resumption." 62 role: Required[str] 63 'The speaker role for this message. One of `"system"`, `"user"`, `"assistant"`, or `"tool"`.' 64 structured_output: Any | None 65 "Parsed structured data returned by the model when a JSON schema or structured-output mode was requested. Shape varies by the schema supplied at call time. `null` when structured output was not requested." 66 tool_calls: list[StreamCreateInputMessagesItemToolCallsItem] | None 67 "Tool calls requested by the model in an `assistant` message. Present only on assistant messages that invoke one or more tools. `null` on all other message roles." 68 tool_results: list[StreamCreateInputMessagesItemToolResultsItem] | None 69 "Tool execution results provided in a `tool` message. Each entry corresponds to a prior tool call by its `id`. `null` on all other message roles."
Plain-text content of the message. Present for system, user, and assistant messages. null when the message body is expressed through content_parts or tool_calls.
Multimodal content parts for the message, used when the body includes images or mixed media. Each part is a map with a type key ("text", "image_url", or "image_data"). null when content is set.
Opaque token that can be passed on a subsequent request to resume this conversation from the current state. null when the provider does not support conversation resumption.
The speaker role for this message. One of "system", "user", "assistant", or "tool".
Parsed structured data returned by the model when a JSON schema or structured-output mode was requested. Shape varies by the schema supplied at call time. null when structured output was not requested.
Tool calls requested by the model in an assistant message. Present only on assistant messages that invoke one or more tools. null on all other message roles.
Tool execution results provided in a tool message. Each entry corresponds to a prior tool call by its id. null on all other message roles.
72class StreamCreateInputOptsToolsItemFunction(TypedDict, total=False): 73 description: str | None 74 "Human-readable description of what the function does. The model uses this to decide when to call the function. `null` if not provided." 75 name: Required[str] 76 'Unique name of the function that the model can invoke, e.g. `"get_weather"`.' 77 parameters: Required[dict[str, Any]] 78 'JSON Schema object describing the function\'s accepted parameters. Must be a valid JSON Schema of type `"object"`.'
81class StreamCreateInputOptsToolsItem(TypedDict): 82 function: StreamCreateInputOptsToolsItemFunction 83 "Callable function this tool exposes, including its name, description, and parameter schema." 84 type: str 85 'The tool type. Currently always `"function"`.'
Callable function this tool exposes, including its name, description, and parameter schema.
88class StreamCreateInputOpts(TypedDict, total=False): 89 max_tokens: int | None 90 "Maximum number of tokens the model may generate. Omit for the model default." 91 model: Required[str] 92 'Model identifier, e.g. `"gpt-4o"` or `"claude-3-7-sonnet-latest"`.' 93 server_tools: list[dict[str, Any]] | None 94 'Server-managed tool declarations executed before the response. Each entry must include a `type` key; currently only `"search"` is supported.' 95 temperature: float | None 96 "Sampling temperature between `0.0` and `2.0`. Higher values produce more random output. Omit for the model default." 97 tool_choice: str | None 98 'Controls tool selection. One of `"auto"`, `"required"`, or `"none"`. Omit to let the model decide.' 99 tools: list[StreamCreateInputOptsToolsItem] | None 100 "OpenAI-compatible tool definitions available to the model. Omit when not using function calling."
Server-managed tool declarations executed before the response. Each entry must include a type key; currently only "search" is supported.
Sampling temperature between 0.0 and 2.0. Higher values produce more random output. Omit for the model default.
Controls tool selection. One of "auto", "required", or "none". Omit to let the model decide.
OpenAI-compatible tool definitions available to the model. Omit when not using function calling.
103class StreamCreateInput(TypedDict, total=False): 104 "Stream a chat completion" 105 106 attribution: dict[str, Any] | None 107 "Optional caller tags recorded on the LLM-call accounting row. Allowed keys: `task_id` (max 64 chars), `work_id` (max 64), `agent_kind` (one of `worker`, `one_off`, `subagent`, `overseer`, `task_reviewer`, `interactive`, `daemon_job`), `agent_id` (max 64), `client` (max 32). Anything else is a 400." 108 context: dict[str, Any] | None 109 "Key-value map used to resolve template variables in message content. Omit if messages contain no templates." 110 messages: Required[list[StreamCreateInputMessagesItem]] 111 "Ordered list of conversation messages to send to the model." 112 opts: Required[StreamCreateInputOpts] 113 "Model and sampling configuration for this request." 114 session_id: str | None 115 "Optional UUID grouping this and other completions under one session in the Developers dashboard. Pass the same value across requests to link them; omit to auto-generate a per-request session."
Stream a chat completion
Optional caller tags recorded on the LLM-call accounting row. Allowed keys: task_id (max 64 chars), work_id (max 64), agent_kind (one of worker, one_off, subagent, overseer, task_reviewer, interactive, daemon_job), agent_id (max 64), client (max 32). Anything else is a 400.
Key-value map used to resolve template variables in message content. Omit if messages contain no templates.
Ordered list of conversation messages to send to the model.
118class CompletionCreateInputMessagesItemToolCallsItem(TypedDict, total=False): 119 arguments: Required[dict[str, Any]] 120 "Arguments the model wants to pass to the tool, as a key-value map. Deserialize and validate these against the tool's input schema before executing." 121 id: Required[str] 122 "Unique identifier for this tool call, assigned by the model. Use this value as `id` when submitting the corresponding tool result." 123 name: Required[str] 124 'Name of the tool or function the model wants to invoke, e.g. `"web_search"` or `"run_code"`.' 125 thought_signature: str | None 126 "Opaque signature representing the model's internal reasoning that led to this tool call. `null` when the provider does not expose chain-of-thought data."
Arguments the model wants to pass to the tool, as a key-value map. Deserialize and validate these against the tool's input schema before executing.
Unique identifier for this tool call, assigned by the model. Use this value as id when submitting the corresponding tool result.
129class CompletionCreateInputMessagesItemToolResultsItem(TypedDict, total=False): 130 content: str | None 131 "Plain-text output produced by the tool execution. `null` when the result is expressed entirely through `resolution`." 132 id: Required[str] 133 "ID of the tool call this result satisfies. Must match the `id` from the corresponding `AIToolCall`." 134 name: Required[str] 135 'Name of the tool or function that was executed, e.g. `"web_search"`. Must match the `name` from the corresponding `AIToolCall`.' 136 resolution: Any | None 137 "Structured result data from the tool execution. Shape varies by tool. `null` when the result is expressed as plain text in `content`."
Plain-text output produced by the tool execution. null when the result is expressed entirely through resolution.
ID of the tool call this result satisfies. Must match the id from the corresponding AIToolCall.
Name of the tool or function that was executed, e.g. "web_search". Must match the name from the corresponding AIToolCall.
Structured result data from the tool execution. Shape varies by tool. null when the result is expressed as plain text in content.
140class CompletionCreateInputMessagesItem(TypedDict, total=False): 141 content: str | None 142 "Plain-text content of the message. Present for `system`, `user`, and `assistant` messages. `null` when the message body is expressed through `content_parts` or `tool_calls`." 143 content_parts: list[dict[str, Any]] | None 144 'Multimodal content parts for the message, used when the body includes images or mixed media. Each part is a map with a `type` key (`"text"`, `"image_url"`, or `"image_data"`). `null` when `content` is set.' 145 resume_token: str | None 146 "Opaque token that can be passed on a subsequent request to resume this conversation from the current state. `null` when the provider does not support conversation resumption." 147 role: Required[str] 148 'The speaker role for this message. One of `"system"`, `"user"`, `"assistant"`, or `"tool"`.' 149 structured_output: Any | None 150 "Parsed structured data returned by the model when a JSON schema or structured-output mode was requested. Shape varies by the schema supplied at call time. `null` when structured output was not requested." 151 tool_calls: list[CompletionCreateInputMessagesItemToolCallsItem] | None 152 "Tool calls requested by the model in an `assistant` message. Present only on assistant messages that invoke one or more tools. `null` on all other message roles." 153 tool_results: list[CompletionCreateInputMessagesItemToolResultsItem] | None 154 "Tool execution results provided in a `tool` message. Each entry corresponds to a prior tool call by its `id`. `null` on all other message roles."
Plain-text content of the message. Present for system, user, and assistant messages. null when the message body is expressed through content_parts or tool_calls.
Multimodal content parts for the message, used when the body includes images or mixed media. Each part is a map with a type key ("text", "image_url", or "image_data"). null when content is set.
Opaque token that can be passed on a subsequent request to resume this conversation from the current state. null when the provider does not support conversation resumption.
The speaker role for this message. One of "system", "user", "assistant", or "tool".
Parsed structured data returned by the model when a JSON schema or structured-output mode was requested. Shape varies by the schema supplied at call time. null when structured output was not requested.
Tool calls requested by the model in an assistant message. Present only on assistant messages that invoke one or more tools. null on all other message roles.
Tool execution results provided in a tool message. Each entry corresponds to a prior tool call by its id. null on all other message roles.
157class CompletionCreateInputOptsToolsItemFunction(TypedDict, total=False): 158 description: str | None 159 "Human-readable description of what the function does. The model uses this to decide when to call the function. `null` if not provided." 160 name: Required[str] 161 'Unique name of the function that the model can invoke, e.g. `"get_weather"`.' 162 parameters: Required[dict[str, Any]] 163 'JSON Schema object describing the function\'s accepted parameters. Must be a valid JSON Schema of type `"object"`.'
166class CompletionCreateInputOptsToolsItem(TypedDict): 167 function: CompletionCreateInputOptsToolsItemFunction 168 "Callable function this tool exposes, including its name, description, and parameter schema." 169 type: str 170 'The tool type. Currently always `"function"`.'
173class CompletionCreateInputOpts(TypedDict, total=False): 174 max_tokens: int | None 175 "Maximum number of tokens the model may generate in the completion. Omit to use the model's default limit." 176 model: Required[str] 177 'Model identifier to use for the completion, e.g. `"gpt-4o"` or `"claude-3-7-sonnet-latest"`.' 178 server_tools: list[dict[str, Any]] | None 179 'Server-managed tool declarations executed before the response is returned. Each entry must include a `type` key; currently only `"search"` is supported.' 180 structured_output: dict[str, Any] | None 181 "Native structured-output configuration. Include a `schema` JSON Schema object and optional `name` and `strict` fields." 182 temperature: float | None 183 "Sampling temperature between `0.0` and `2.0`. Higher values produce more random output. Omit to use the model's default." 184 tool_choice: str | None 185 'Controls how the model selects tools. One of `"auto"`, `"required"`, or `"none"`. Omit to let the model decide.' 186 tools: list[CompletionCreateInputOptsToolsItem] | None 187 "OpenAI-compatible tool definitions available to the model. Omit when not using function calling."
Maximum number of tokens the model may generate in the completion. Omit to use the model's default limit.
Model identifier to use for the completion, e.g. "gpt-4o" or "claude-3-7-sonnet-latest".
Server-managed tool declarations executed before the response is returned. Each entry must include a type key; currently only "search" is supported.
Native structured-output configuration. Include a schema JSON Schema object and optional name and strict fields.
Sampling temperature between 0.0 and 2.0. Higher values produce more random output. Omit to use the model's default.
Controls how the model selects tools. One of "auto", "required", or "none". Omit to let the model decide.
OpenAI-compatible tool definitions available to the model. Omit when not using function calling.
190class CompletionCreateInput(TypedDict, total=False): 191 "Create a chat completion" 192 193 attribution: dict[str, Any] | None 194 "Optional caller tags recorded on the LLM-call accounting row. Allowed keys: `task_id` (max 64 chars), `work_id` (max 64), `agent_kind` (one of `worker`, `one_off`, `subagent`, `overseer`, `task_reviewer`, `interactive`, `daemon_job`), `agent_id` (max 64), `client` (max 32). Anything else is a 400." 195 context: dict[str, Any] | None 196 "Key-value map used to resolve template variables in message content. Omit if messages contain no templates." 197 messages: Required[list[CompletionCreateInputMessagesItem]] 198 "Ordered list of conversation messages to send to the model." 199 opts: Required[CompletionCreateInputOpts] 200 "Model and sampling configuration for this request." 201 session_id: str | None 202 "Optional UUID grouping this and other completions under one session in the Developers dashboard. Pass the same value across requests to link them; omit to auto-generate a per-request session."
Create a chat completion
Optional caller tags recorded on the LLM-call accounting row. Allowed keys: task_id (max 64 chars), work_id (max 64), agent_kind (one of worker, one_off, subagent, overseer, task_reviewer, interactive, daemon_job), agent_id (max 64), client (max 32). Anything else is a 400.
Key-value map used to resolve template variables in message content. Omit if messages contain no templates.
Ordered list of conversation messages to send to the model.
205class EmbeddingSimilarityComparisonInput(TypedDict): 206 "Compare the embedding similarity of two texts" 207 208 text_a: str 209 "First text to embed and compare." 210 text_b: str 211 "Second text to embed and compare."
Compare the embedding similarity of two texts
214class EvaluationEvaluationsInputImagesItem(TypedDict, total=False): 215 image_data: str | None 216 "Base64 image bytes; requires image_type." 217 image_type: str | None 218 "Image MIME type, such as image/png." 219 image_url: str | None 220 "Image URL; mutually exclusive with image_data." 221 type: Required[Literal["image"]]
224class EvaluationEvaluationsInput(TypedDict, total=False): 225 "Create an evaluation" 226 227 images: list[EvaluationEvaluationsInputImagesItem] | None 228 "Optional image content parts. Omitted or empty means no images. Requires model image support." 229 model: str | None 230 "Evaluation model identifier. Omit to use the platform default." 231 questions: Required[list[dict[str, Any] | dict[str, Any] | dict[str, Any]]] 232 "Nonempty list of boolean, choice, or score questions. Each question must include `id`, `type`, and `instructions`." 233 session_id: str | None 234 "Optional UUID grouping this evaluation under one session in the Developers dashboard. Generated when omitted." 235 state: Required[Any] 236 "Shared content the model judges. A string, JSON object, or JSON array. Every question in the request sees this same state."
Create an evaluation
Optional image content parts. Omitted or empty means no images. Requires model image support.
Nonempty list of boolean, choice, or score questions. Each question must include id, type, and instructions.
239class ImageEditsInputImagesItem(TypedDict): 240 image_data: str 241 "The raw image content encoded as a base64 string (standard encoding, no line breaks)." 242 image_type: str 243 'MIME type of the image, e.g. `"image/png"` or `"image/jpeg"`. Must match the actual encoding of `image_data`.'
The raw image content encoded as a base64 string (standard encoding, no line breaks).
MIME type of the image, e.g. "image/png" or "image/jpeg". Must match the actual encoding of image_data.
246class ImageEditsInput(TypedDict, total=False): 247 "Edit an image with a text prompt" 248 249 aspect_ratio: str | None 250 'Desired aspect ratio of the output, e.g. `"1:1"` or `"16:9"`. Not supported by all models; omit to use the model\'s default.' 251 background: str | None 252 "Background treatment for the output. Accepted values and behavior are model-dependent." 253 height: int | None 254 "Explicit output height in pixels. Takes precedence over `size` when both are provided. Not supported by all models." 255 image_size: str | None 256 'Output resolution tier for Gemini models, e.g. `"1K"`, `"2K"`, or `"4K"`. Ignored by non-Gemini models.' 257 images: Required[list[ImageEditsInputImagesItem]] 258 "One or more source images to edit. Each image must be supplied as a base64-encoded object." 259 model: str | None 260 "Model identifier to use for editing. Omit to use the platform default image model." 261 output_format: str | None 262 'Desired MIME type or format for the returned image. Common values: `"png"`, `"jpeg"`, `"webp"`. Defaults to the model\'s native format.' 263 prompt: Required[str] 264 "Natural-language description of the edit to apply to the source image(s)." 265 quality: str | None 266 "Quality preset for the output image. Accepted values and behavior are model-dependent." 267 session_id: str | None 268 "Optional session UUID for grouping provider attempts in usage records. Generated when omitted." 269 size: str | None 270 'Output dimensions as a WxH string, e.g. `"1024x1024"`. Applies to OpenAI-compatible models. Omit to use the model\'s default.' 271 style: str | None 272 "Style preset applied to the edit. Accepted values and behavior are model-dependent." 273 width: int | None 274 "Explicit output width in pixels. Takes precedence over `size` when both are provided. Not supported by all models."
Edit an image with a text prompt
Desired aspect ratio of the output, e.g. "1:1" or "16:9". Not supported by all models; omit to use the model's default.
Background treatment for the output. Accepted values and behavior are model-dependent.
Explicit output height in pixels. Takes precedence over size when both are provided. Not supported by all models.
Output resolution tier for Gemini models, e.g. "1K", "2K", or "4K". Ignored by non-Gemini models.
One or more source images to edit. Each image must be supplied as a base64-encoded object.
Model identifier to use for editing. Omit to use the platform default image model.
Desired MIME type or format for the returned image. Common values: "png", "jpeg", "webp". Defaults to the model's native format.
Quality preset for the output image. Accepted values and behavior are model-dependent.
Optional session UUID for grouping provider attempts in usage records. Generated when omitted.
Output dimensions as a WxH string, e.g. "1024x1024". Applies to OpenAI-compatible models. Omit to use the model's default.
Style preset applied to the edit. Accepted values and behavior are model-dependent.
Explicit output width in pixels. Takes precedence over size when both are provided. Not supported by all models.
277class ImageGenerationsInput(TypedDict, total=False): 278 "Generate an image from a text prompt" 279 280 aspect_ratio: str | None 281 'Desired aspect ratio of the output, e.g. `"1:1"` or `"16:9"`. Not supported by all models; omit to use the model\'s default.' 282 background: str | None 283 "Background treatment for the output. Accepted values and behavior are model-dependent." 284 height: int | None 285 "Explicit output height in pixels. Takes precedence over `size` when both are provided. Not supported by all models." 286 image_size: str | None 287 'Output resolution tier for Gemini models, e.g. `"1K"`, `"2K"`, or `"4K"`. Ignored by non-Gemini models.' 288 model: str | None 289 "Model identifier to use for generation. Omit to use the platform default image model." 290 n: int | None 291 "Number of images to generate. Defaults to `1`. Values greater than `1` are only supported by models that allow batch generation." 292 output_format: str | None 293 'Desired MIME type or format for the returned image. Common values: `"png"`, `"jpeg"`, `"webp"`. Defaults to the model\'s native format.' 294 prompt: Required[str] 295 "Natural-language description of the image to generate." 296 quality: str | None 297 "Quality preset for the output image. Accepted values and behavior are model-dependent." 298 session_id: str | None 299 "Optional session UUID for grouping provider attempts in usage records. Generated when omitted." 300 size: str | None 301 'Output dimensions as a WxH string, e.g. `"1024x1024"`. Applies to OpenAI-compatible models. Omit to use the model\'s default.' 302 style: str | None 303 "Style preset applied to the generated image. Accepted values and behavior are model-dependent." 304 width: int | None 305 "Explicit output width in pixels. Takes precedence over `size` when both are provided. Not supported by all models."
Generate an image from a text prompt
Desired aspect ratio of the output, e.g. "1:1" or "16:9". Not supported by all models; omit to use the model's default.
Background treatment for the output. Accepted values and behavior are model-dependent.
Explicit output height in pixels. Takes precedence over size when both are provided. Not supported by all models.
Output resolution tier for Gemini models, e.g. "1K", "2K", or "4K". Ignored by non-Gemini models.
Model identifier to use for generation. Omit to use the platform default image model.
Number of images to generate. Defaults to 1. Values greater than 1 are only supported by models that allow batch generation.
Desired MIME type or format for the returned image. Common values: "png", "jpeg", "webp". Defaults to the model's native format.
Quality preset for the output image. Accepted values and behavior are model-dependent.
Optional session UUID for grouping provider attempts in usage records. Generated when omitted.
Output dimensions as a WxH string, e.g. "1024x1024". Applies to OpenAI-compatible models. Omit to use the model's default.
Style preset applied to the generated image. Accepted values and behavior are model-dependent.
Explicit output width in pixels. Takes precedence over size when both are provided. Not supported by all models.
308class AiSessionTokenInput(TypedDict, total=False): 309 "Mint a principal-bound billing session token" 310 311 entitlement: Literal["llm_calls", "run_automation"] | None 312 restrictions: dict[str, Any] | None 313 ttl: int | None 314 user_id: Required[str]
Mint a principal-bound billing session token
317class ChatModelsResponseDataItem(BaseModel): 318 capabilities: list[Literal["image", "search", "temperature", "thinking"]] = Field( 319 ..., 320 description='Machine-readable model capabilities. `"image"` marks image-input chat, `"search"` marks built-in web search, `"temperature"` marks models that accept the temperature generation parameter, and `"thinking"` marks models with configurable reasoning. Empty when the catalog entry declares no special capabilities.', 321 ) 322 context_window: int | None = Field( 323 default=None, 324 description="Maximum context-window size in tokens this model accepts, when the platform publishes it. Use it to size prompt/history against the real window rather than a hardcoded default. `null` for entries whose window the platform does not report (e.g. legacy or mock model listings); clients should apply a conservative fallback in that case.", 325 ) 326 default: bool = Field( 327 ..., 328 description="`true` for the model the platform selects when an agent has no `default_model` configured, or for the system-wide fallback in image-generation contexts. Exactly one entry in any given model list carries this flag.", 329 ) 330 id: str = Field( 331 ..., 332 description='Provider-assigned model identifier used when specifying a model on API requests, e.g. `"claude-sonnet-4-6"` or `"gemini-2.5-flash"`.', 333 ) 334 input_media_formats: list[str] = Field( 335 ..., 336 description='MIME types accepted in chat `content_parts` image/file inputs for this model. For image-capable chat models this includes values such as `"image/png"`. Empty for text-only models.', 337 ) 338 name: str = Field( 339 ..., 340 description='Human-readable display label for this model, e.g. `"Claude Sonnet 4.6"` or `"Gemini 3.5 Flash (thinking)"`. Render this value directly in pickers rather than attempting to parse or transform `id`. Falls back to the `id` string when the catalog entry does not declare an explicit name.', 341 ) 342 output_media_formats: list[str] = Field( 343 ..., 344 description="MIME types this model can emit as media in chat responses. Empty for text-output models, including image-understanding models that only return text.", 345 )
!!! abstract "Usage Documentation" Models
A base class for creating Pydantic models.
Attributes:
- __class_vars__: The names of the class variables defined on the model.
- __private_attributes__: Metadata about the private attributes of the model.
- __signature__: The synthesized
__init__[Signature][inspect.Signature] of the model. - __pydantic_complete__: Whether model building is completed, or if there are still undefined fields.
- __pydantic_core_schema__: The core schema of the model.
- __pydantic_custom_init__: Whether the model has a custom
__init__function. - __pydantic_decorators__: Metadata containing the decorators defined on the model.
This replaces
Model.__validators__andModel.__root_validators__from Pydantic V1. - __pydantic_generic_metadata__: A dictionary containing metadata about generic Pydantic models.
The
originandargsitems map to the [__origin__][genericalias.__origin__] and [__args__][genericalias.__args__] attributes of [generic aliases][types-genericalias], and theparameteritem maps to the__parameter__attribute of generic classes. - __pydantic_parent_namespace__: Parent namespace of the model, used for automatic rebuilding of models.
- __pydantic_post_init__: The name of the post-init method for the model, if defined.
- __pydantic_root_model__: Whether the model is a [
RootModel][pydantic.root_model.RootModel]. - __pydantic_serializer__: The
pydantic-coreSchemaSerializerused to dump instances of the model. - __pydantic_validator__: The
pydantic-coreSchemaValidatorused to validate instances of the model. - __pydantic_fields__: A dictionary of field names and their corresponding [
FieldInfo][pydantic.fields.FieldInfo] objects. - __pydantic_computed_fields__: A dictionary of computed field names and their corresponding [
ComputedFieldInfo][pydantic.fields.ComputedFieldInfo] objects. - __pydantic_extra__: A dictionary containing extra values, if [
extra][pydantic.config.ConfigDict.extra] is set to'allow'. - __pydantic_fields_set__: The names of fields explicitly set during instantiation.
- __pydantic_private__: Values of private attributes set on the model instance.
Machine-readable model capabilities. "image" marks image-input chat, "search" marks built-in web search, "temperature" marks models that accept the temperature generation parameter, and "thinking" marks models with configurable reasoning. Empty when the catalog entry declares no special capabilities.
Maximum context-window size in tokens this model accepts, when the platform publishes it. Use it to size prompt/history against the real window rather than a hardcoded default. null for entries whose window the platform does not report (e.g. legacy or mock model listings); clients should apply a conservative fallback in that case.
true for the model the platform selects when an agent has no default_model configured, or for the system-wide fallback in image-generation contexts. Exactly one entry in any given model list carries this flag.
Provider-assigned model identifier used when specifying a model on API requests, e.g. "claude-sonnet-4-6" or "gemini-2.5-flash".
MIME types accepted in chat content_parts image/file inputs for this model. For image-capable chat models this includes values such as "image/png". Empty for text-only models.
348class ChatModelsResponse(BaseModel): 349 """ 350 Successful response 351 """ 352 353 data: list[ChatModelsResponseDataItem] = Field( 354 ..., description="Array of available model objects. At least one entry is always present." 355 )
Successful response
358class EmbeddingSimilarityComparisonResponse(BaseModel): 359 """ 360 Successful response 361 """ 362 363 model: str = Field( 364 ..., description="Configured default embedding model key used for both texts." 365 ) 366 similarity_score: float = Field( 367 ..., 368 description="Cosine similarity from `-1.0` to `1.0`, computed as `1 - cosine_distance`.", 369 )
Successful response
372class EvaluationModelsResponseDataItem(BaseModel): 373 capabilities: list[Literal["image", "search", "temperature", "thinking"]] = Field( 374 ..., 375 description='Machine-readable model capabilities. `"image"` marks image-input chat, `"search"` marks built-in web search, `"temperature"` marks models that accept the temperature generation parameter, and `"thinking"` marks models with configurable reasoning. Empty when the catalog entry declares no special capabilities.', 376 ) 377 context_window: int | None = Field( 378 default=None, 379 description="Maximum context-window size in tokens this model accepts, when the platform publishes it. Use it to size prompt/history against the real window rather than a hardcoded default. `null` for entries whose window the platform does not report (e.g. legacy or mock model listings); clients should apply a conservative fallback in that case.", 380 ) 381 default: bool = Field( 382 ..., 383 description="`true` for the model the platform selects when an agent has no `default_model` configured, or for the system-wide fallback in image-generation contexts. Exactly one entry in any given model list carries this flag.", 384 ) 385 id: str = Field( 386 ..., 387 description='Provider-assigned model identifier used when specifying a model on API requests, e.g. `"claude-sonnet-4-6"` or `"gemini-2.5-flash"`.', 388 ) 389 input_media_formats: list[str] = Field( 390 ..., 391 description='MIME types accepted in chat `content_parts` image/file inputs for this model. For image-capable chat models this includes values such as `"image/png"`. Empty for text-only models.', 392 ) 393 name: str = Field( 394 ..., 395 description='Human-readable display label for this model, e.g. `"Claude Sonnet 4.6"` or `"Gemini 3.5 Flash (thinking)"`. Render this value directly in pickers rather than attempting to parse or transform `id`. Falls back to the `id` string when the catalog entry does not declare an explicit name.', 396 ) 397 output_media_formats: list[str] = Field( 398 ..., 399 description="MIME types this model can emit as media in chat responses. Empty for text-output models, including image-understanding models that only return text.", 400 )
!!! abstract "Usage Documentation" Models
A base class for creating Pydantic models.
Attributes:
- __class_vars__: The names of the class variables defined on the model.
- __private_attributes__: Metadata about the private attributes of the model.
- __signature__: The synthesized
__init__[Signature][inspect.Signature] of the model. - __pydantic_complete__: Whether model building is completed, or if there are still undefined fields.
- __pydantic_core_schema__: The core schema of the model.
- __pydantic_custom_init__: Whether the model has a custom
__init__function. - __pydantic_decorators__: Metadata containing the decorators defined on the model.
This replaces
Model.__validators__andModel.__root_validators__from Pydantic V1. - __pydantic_generic_metadata__: A dictionary containing metadata about generic Pydantic models.
The
originandargsitems map to the [__origin__][genericalias.__origin__] and [__args__][genericalias.__args__] attributes of [generic aliases][types-genericalias], and theparameteritem maps to the__parameter__attribute of generic classes. - __pydantic_parent_namespace__: Parent namespace of the model, used for automatic rebuilding of models.
- __pydantic_post_init__: The name of the post-init method for the model, if defined.
- __pydantic_root_model__: Whether the model is a [
RootModel][pydantic.root_model.RootModel]. - __pydantic_serializer__: The
pydantic-coreSchemaSerializerused to dump instances of the model. - __pydantic_validator__: The
pydantic-coreSchemaValidatorused to validate instances of the model. - __pydantic_fields__: A dictionary of field names and their corresponding [
FieldInfo][pydantic.fields.FieldInfo] objects. - __pydantic_computed_fields__: A dictionary of computed field names and their corresponding [
ComputedFieldInfo][pydantic.fields.ComputedFieldInfo] objects. - __pydantic_extra__: A dictionary containing extra values, if [
extra][pydantic.config.ConfigDict.extra] is set to'allow'. - __pydantic_fields_set__: The names of fields explicitly set during instantiation.
- __pydantic_private__: Values of private attributes set on the model instance.
Machine-readable model capabilities. "image" marks image-input chat, "search" marks built-in web search, "temperature" marks models that accept the temperature generation parameter, and "thinking" marks models with configurable reasoning. Empty when the catalog entry declares no special capabilities.
Maximum context-window size in tokens this model accepts, when the platform publishes it. Use it to size prompt/history against the real window rather than a hardcoded default. null for entries whose window the platform does not report (e.g. legacy or mock model listings); clients should apply a conservative fallback in that case.
true for the model the platform selects when an agent has no default_model configured, or for the system-wide fallback in image-generation contexts. Exactly one entry in any given model list carries this flag.
Provider-assigned model identifier used when specifying a model on API requests, e.g. "claude-sonnet-4-6" or "gemini-2.5-flash".
MIME types accepted in chat content_parts image/file inputs for this model. For image-capable chat models this includes values such as "image/png". Empty for text-only models.
403class EvaluationModelsResponse(BaseModel): 404 """ 405 Successful response 406 """ 407 408 data: list[EvaluationModelsResponseDataItem] = Field( 409 ..., 410 description="Array of available evaluation model objects. At least one entry is always present.", 411 )
Successful response
414class ImageModelsResponseDataItem(BaseModel): 415 capabilities: list[Literal["image", "search", "temperature", "thinking"]] = Field( 416 ..., 417 description='Machine-readable model capabilities. `"image"` marks image-input chat, `"search"` marks built-in web search, `"temperature"` marks models that accept the temperature generation parameter, and `"thinking"` marks models with configurable reasoning. Empty when the catalog entry declares no special capabilities.', 418 ) 419 context_window: int | None = Field( 420 default=None, 421 description="Maximum context-window size in tokens this model accepts, when the platform publishes it. Use it to size prompt/history against the real window rather than a hardcoded default. `null` for entries whose window the platform does not report (e.g. legacy or mock model listings); clients should apply a conservative fallback in that case.", 422 ) 423 default: bool = Field( 424 ..., 425 description="`true` for the model the platform selects when an agent has no `default_model` configured, or for the system-wide fallback in image-generation contexts. Exactly one entry in any given model list carries this flag.", 426 ) 427 id: str = Field( 428 ..., 429 description='Provider-assigned model identifier used when specifying a model on API requests, e.g. `"claude-sonnet-4-6"` or `"gemini-2.5-flash"`.', 430 ) 431 input_media_formats: list[str] = Field( 432 ..., 433 description='MIME types accepted in chat `content_parts` image/file inputs for this model. For image-capable chat models this includes values such as `"image/png"`. Empty for text-only models.', 434 ) 435 name: str = Field( 436 ..., 437 description='Human-readable display label for this model, e.g. `"Claude Sonnet 4.6"` or `"Gemini 3.5 Flash (thinking)"`. Render this value directly in pickers rather than attempting to parse or transform `id`. Falls back to the `id` string when the catalog entry does not declare an explicit name.', 438 ) 439 output_media_formats: list[str] = Field( 440 ..., 441 description="MIME types this model can emit as media in chat responses. Empty for text-output models, including image-understanding models that only return text.", 442 )
!!! abstract "Usage Documentation" Models
A base class for creating Pydantic models.
Attributes:
- __class_vars__: The names of the class variables defined on the model.
- __private_attributes__: Metadata about the private attributes of the model.
- __signature__: The synthesized
__init__[Signature][inspect.Signature] of the model. - __pydantic_complete__: Whether model building is completed, or if there are still undefined fields.
- __pydantic_core_schema__: The core schema of the model.
- __pydantic_custom_init__: Whether the model has a custom
__init__function. - __pydantic_decorators__: Metadata containing the decorators defined on the model.
This replaces
Model.__validators__andModel.__root_validators__from Pydantic V1. - __pydantic_generic_metadata__: A dictionary containing metadata about generic Pydantic models.
The
originandargsitems map to the [__origin__][genericalias.__origin__] and [__args__][genericalias.__args__] attributes of [generic aliases][types-genericalias], and theparameteritem maps to the__parameter__attribute of generic classes. - __pydantic_parent_namespace__: Parent namespace of the model, used for automatic rebuilding of models.
- __pydantic_post_init__: The name of the post-init method for the model, if defined.
- __pydantic_root_model__: Whether the model is a [
RootModel][pydantic.root_model.RootModel]. - __pydantic_serializer__: The
pydantic-coreSchemaSerializerused to dump instances of the model. - __pydantic_validator__: The
pydantic-coreSchemaValidatorused to validate instances of the model. - __pydantic_fields__: A dictionary of field names and their corresponding [
FieldInfo][pydantic.fields.FieldInfo] objects. - __pydantic_computed_fields__: A dictionary of computed field names and their corresponding [
ComputedFieldInfo][pydantic.fields.ComputedFieldInfo] objects. - __pydantic_extra__: A dictionary containing extra values, if [
extra][pydantic.config.ConfigDict.extra] is set to'allow'. - __pydantic_fields_set__: The names of fields explicitly set during instantiation.
- __pydantic_private__: Values of private attributes set on the model instance.
Machine-readable model capabilities. "image" marks image-input chat, "search" marks built-in web search, "temperature" marks models that accept the temperature generation parameter, and "thinking" marks models with configurable reasoning. Empty when the catalog entry declares no special capabilities.
Maximum context-window size in tokens this model accepts, when the platform publishes it. Use it to size prompt/history against the real window rather than a hardcoded default. null for entries whose window the platform does not report (e.g. legacy or mock model listings); clients should apply a conservative fallback in that case.
true for the model the platform selects when an agent has no default_model configured, or for the system-wide fallback in image-generation contexts. Exactly one entry in any given model list carries this flag.
Provider-assigned model identifier used when specifying a model on API requests, e.g. "claude-sonnet-4-6" or "gemini-2.5-flash".
MIME types accepted in chat content_parts image/file inputs for this model. For image-capable chat models this includes values such as "image/png". Empty for text-only models.
445class ImageModelsResponse(BaseModel): 446 """ 447 Successful response 448 """ 449 450 data: list[ImageModelsResponseDataItem] = Field( 451 ..., 452 description="Array of available image generation models, including their identifiers, human-readable names, and which one is the platform default.", 453 )
Successful response
456class AiSessionTokenResponse(BaseModel): 457 """ 458 Successful response 459 """ 460 461 expires_at: str 462 token: str
Successful response
465class AiUsageResponseDataItem(BaseModel): 466 agent_id: str | None = Field( 467 default=None, 468 description="Agent ID for this group. Present only when grouped by `agent_id`.", 469 ) 470 agent_kind: str | None = Field( 471 default=None, 472 description="Agent kind for this group. Present only when grouped by `agent_kind`.", 473 ) 474 billed_usd: float | None = Field( 475 default=None, 476 description="Customer-billed cost for this group in USD. `null` when `priced` is `false`.", 477 ) 478 cache_read_tokens: int = Field(..., description="Summed cache-read tokens in this group.") 479 cache_write_tokens: int = Field(..., description="Summed cache-write tokens in this group.") 480 completion_tokens: int = Field( 481 ..., description="Summed completion (output) tokens in this group." 482 ) 483 hour: str | None = Field( 484 default=None, 485 description="Hour bucket (ISO 8601) for this group. Present only when grouped by `hour`.", 486 ) 487 model: str | None = Field( 488 default=None, 489 description="Model identifier for this group. Present only when grouped by `model`.", 490 ) 491 priced: bool = Field( 492 ..., 493 description="`true` when `billed_usd` was priced from the customer's active billing plan; `false` when the group could not be priced.", 494 ) 495 prompt_tokens: int = Field(..., description="Summed prompt (input) tokens in this group.") 496 requests: int = Field(..., description="Number of LLM calls in this group.") 497 task: str | None = Field( 498 default=None, 499 description="Caller task ID for this group. Present only when grouped by `task`.", 500 )
!!! abstract "Usage Documentation" Models
A base class for creating Pydantic models.
Attributes:
- __class_vars__: The names of the class variables defined on the model.
- __private_attributes__: Metadata about the private attributes of the model.
- __signature__: The synthesized
__init__[Signature][inspect.Signature] of the model. - __pydantic_complete__: Whether model building is completed, or if there are still undefined fields.
- __pydantic_core_schema__: The core schema of the model.
- __pydantic_custom_init__: Whether the model has a custom
__init__function. - __pydantic_decorators__: Metadata containing the decorators defined on the model.
This replaces
Model.__validators__andModel.__root_validators__from Pydantic V1. - __pydantic_generic_metadata__: A dictionary containing metadata about generic Pydantic models.
The
originandargsitems map to the [__origin__][genericalias.__origin__] and [__args__][genericalias.__args__] attributes of [generic aliases][types-genericalias], and theparameteritem maps to the__parameter__attribute of generic classes. - __pydantic_parent_namespace__: Parent namespace of the model, used for automatic rebuilding of models.
- __pydantic_post_init__: The name of the post-init method for the model, if defined.
- __pydantic_root_model__: Whether the model is a [
RootModel][pydantic.root_model.RootModel]. - __pydantic_serializer__: The
pydantic-coreSchemaSerializerused to dump instances of the model. - __pydantic_validator__: The
pydantic-coreSchemaValidatorused to validate instances of the model. - __pydantic_fields__: A dictionary of field names and their corresponding [
FieldInfo][pydantic.fields.FieldInfo] objects. - __pydantic_computed_fields__: A dictionary of computed field names and their corresponding [
ComputedFieldInfo][pydantic.fields.ComputedFieldInfo] objects. - __pydantic_extra__: A dictionary containing extra values, if [
extra][pydantic.config.ConfigDict.extra] is set to'allow'. - __pydantic_fields_set__: The names of fields explicitly set during instantiation.
- __pydantic_private__: Values of private attributes set on the model instance.
Customer-billed cost for this group in USD. null when priced is false.
true when billed_usd was priced from the customer's active billing plan; false when the group could not be priced.
503class AiUsageResponse(BaseModel): 504 """ 505 Successful response 506 """ 507 508 data: list[AiUsageResponseDataItem] = Field( 509 ..., 510 description="One row per group with request/token sums, the group key fields, `billed_usd`, and `priced`.", 511 ) 512 since: str = Field(..., description="Effective window start (ISO 8601).") 513 until: str = Field(..., description="Effective window end (ISO 8601).")
Successful response
562class AsyncStreamResource: 563 def __init__(self, http: HttpClient): 564 self._http = http 565 566 async def create(self, input: StreamCreateInput) -> AsyncIterator[StreamCreateEvent]: 567 """ 568 Stream a chat completion 569 Streams a chat completion over Server-Sent Events. Emits `thinking_delta` for 570 supported reasoning models, `message_delta`, `message_complete`, 571 `tool_call_*`, `tool_result`, and a terminal `done` (or `error`) event. Same 572 request shape as the non-streaming completion endpoint; the app must have the 573 `llm_calls` entitlement. 574 575 Args: 576 input: Request body. 577 input.attribution: Optional caller tags recorded on the LLM-call accounting row. Allowed keys: `task_id` (max 64 chars), `work_id` (max 64), `agent_kind` (one of `worker`, `one_off`, `subagent`, `overseer`, `task_reviewer`, `interactive`, `daemon_job`), `agent_id` (max 64), `client` (max 32). Anything else is a 400. 578 input.context: Key-value map used to resolve template variables in message content. Omit if messages contain no templates. 579 input.messages: Ordered list of conversation messages to send to the model. 580 input.opts: Model and sampling configuration for this request. 581 input.session_id: Optional UUID grouping this and other completions under one session in the Developers dashboard. Pass the same value across requests to link them; omit to auto-generate a per-request session. 582 583 Returns: 584 Server-Sent Events stream 585 """ 586 async for event in self._http.stream_sse( 587 "/api/v1/ai/chat/completions/stream", method="POST", body=input 588 ): 589 yield event
566 async def create(self, input: StreamCreateInput) -> AsyncIterator[StreamCreateEvent]: 567 """ 568 Stream a chat completion 569 Streams a chat completion over Server-Sent Events. Emits `thinking_delta` for 570 supported reasoning models, `message_delta`, `message_complete`, 571 `tool_call_*`, `tool_result`, and a terminal `done` (or `error`) event. Same 572 request shape as the non-streaming completion endpoint; the app must have the 573 `llm_calls` entitlement. 574 575 Args: 576 input: Request body. 577 input.attribution: Optional caller tags recorded on the LLM-call accounting row. Allowed keys: `task_id` (max 64 chars), `work_id` (max 64), `agent_kind` (one of `worker`, `one_off`, `subagent`, `overseer`, `task_reviewer`, `interactive`, `daemon_job`), `agent_id` (max 64), `client` (max 32). Anything else is a 400. 578 input.context: Key-value map used to resolve template variables in message content. Omit if messages contain no templates. 579 input.messages: Ordered list of conversation messages to send to the model. 580 input.opts: Model and sampling configuration for this request. 581 input.session_id: Optional UUID grouping this and other completions under one session in the Developers dashboard. Pass the same value across requests to link them; omit to auto-generate a per-request session. 582 583 Returns: 584 Server-Sent Events stream 585 """ 586 async for event in self._http.stream_sse( 587 "/api/v1/ai/chat/completions/stream", method="POST", body=input 588 ): 589 yield event
Stream a chat completion
Streams a chat completion over Server-Sent Events. Emits thinking_delta for
supported reasoning models, message_delta, message_complete,
tool_call_*, tool_result, and a terminal done (or error) event. Same
request shape as the non-streaming completion endpoint; the app must have the
llm_calls entitlement.
Arguments:
- input: Request body.
- input.attribution: Optional caller tags recorded on the LLM-call accounting row. Allowed keys:
task_id(max 64 chars),work_id(max 64),agent_kind(one ofworker,one_off,subagent,overseer,task_reviewer,interactive,daemon_job),agent_id(max 64),client(max 32). Anything else is a 400. - input.context: Key-value map used to resolve template variables in message content. Omit if messages contain no templates.
- input.messages: Ordered list of conversation messages to send to the model.
- input.opts: Model and sampling configuration for this request.
- input.session_id: Optional UUID grouping this and other completions under one session in the Developers dashboard. Pass the same value across requests to link them; omit to auto-generate a per-request session.
Returns:
Server-Sent Events stream
592class AsyncCompletionResource: 593 def __init__(self, http: HttpClient): 594 self._http = http 595 self.stream = AsyncStreamResource(http) 596 597 async def create(self, input: CompletionCreateInput) -> AICompletionResult: 598 """ 599 Create a chat completion 600 Sends a list of messages to the configured AI provider and returns a single 601 completion. Use this endpoint when you want direct, low-level access to the 602 underlying model without any workflow or agent orchestration. 603 The authenticated app must have the `llm_calls` entitlement enabled on its 604 plan. Requests that exceed the plan quota are rejected with `402`. Token 605 usage is recorded against the authenticated app and organization. 606 Supply `tools` and `tool_choice` to enable OpenAI-compatible function 607 calling. Use `server_tools` to activate platform-managed tools such as 608 search that run on the server side before the response is returned. 609 610 Args: 611 input: Request body. 612 input.attribution: Optional caller tags recorded on the LLM-call accounting row. Allowed keys: `task_id` (max 64 chars), `work_id` (max 64), `agent_kind` (one of `worker`, `one_off`, `subagent`, `overseer`, `task_reviewer`, `interactive`, `daemon_job`), `agent_id` (max 64), `client` (max 32). Anything else is a 400. 613 input.context: Key-value map used to resolve template variables in message content. Omit if messages contain no templates. 614 input.messages: Ordered list of conversation messages to send to the model. 615 input.opts: Model and sampling configuration for this request. 616 input.session_id: Optional UUID grouping this and other completions under one session in the Developers dashboard. Pass the same value across requests to link them; omit to auto-generate a per-request session. 617 618 Returns: 619 The completed AI response, including the generated message, finish reason, and token usage. 620 """ 621 return await self._http.request( 622 "/api/v1/ai/chat/completions", 623 method="POST", 624 body=input, 625 response_type=AICompletionResult, 626 )
597 async def create(self, input: CompletionCreateInput) -> AICompletionResult: 598 """ 599 Create a chat completion 600 Sends a list of messages to the configured AI provider and returns a single 601 completion. Use this endpoint when you want direct, low-level access to the 602 underlying model without any workflow or agent orchestration. 603 The authenticated app must have the `llm_calls` entitlement enabled on its 604 plan. Requests that exceed the plan quota are rejected with `402`. Token 605 usage is recorded against the authenticated app and organization. 606 Supply `tools` and `tool_choice` to enable OpenAI-compatible function 607 calling. Use `server_tools` to activate platform-managed tools such as 608 search that run on the server side before the response is returned. 609 610 Args: 611 input: Request body. 612 input.attribution: Optional caller tags recorded on the LLM-call accounting row. Allowed keys: `task_id` (max 64 chars), `work_id` (max 64), `agent_kind` (one of `worker`, `one_off`, `subagent`, `overseer`, `task_reviewer`, `interactive`, `daemon_job`), `agent_id` (max 64), `client` (max 32). Anything else is a 400. 613 input.context: Key-value map used to resolve template variables in message content. Omit if messages contain no templates. 614 input.messages: Ordered list of conversation messages to send to the model. 615 input.opts: Model and sampling configuration for this request. 616 input.session_id: Optional UUID grouping this and other completions under one session in the Developers dashboard. Pass the same value across requests to link them; omit to auto-generate a per-request session. 617 618 Returns: 619 The completed AI response, including the generated message, finish reason, and token usage. 620 """ 621 return await self._http.request( 622 "/api/v1/ai/chat/completions", 623 method="POST", 624 body=input, 625 response_type=AICompletionResult, 626 )
Create a chat completion
Sends a list of messages to the configured AI provider and returns a single
completion. Use this endpoint when you want direct, low-level access to the
underlying model without any workflow or agent orchestration.
The authenticated app must have the llm_calls entitlement enabled on its
plan. Requests that exceed the plan quota are rejected with 402. Token
usage is recorded against the authenticated app and organization.
Supply tools and tool_choice to enable OpenAI-compatible function
calling. Use server_tools to activate platform-managed tools such as
search that run on the server side before the response is returned.
Arguments:
- input: Request body.
- input.attribution: Optional caller tags recorded on the LLM-call accounting row. Allowed keys:
task_id(max 64 chars),work_id(max 64),agent_kind(one ofworker,one_off,subagent,overseer,task_reviewer,interactive,daemon_job),agent_id(max 64),client(max 32). Anything else is a 400. - input.context: Key-value map used to resolve template variables in message content. Omit if messages contain no templates.
- input.messages: Ordered list of conversation messages to send to the model.
- input.opts: Model and sampling configuration for this request.
- input.session_id: Optional UUID grouping this and other completions under one session in the Developers dashboard. Pass the same value across requests to link them; omit to auto-generate a per-request session.
Returns:
The completed AI response, including the generated message, finish reason, and token usage.
629class AsyncChatResource: 630 def __init__(self, http: HttpClient): 631 self._http = http 632 self.completions = AsyncCompletionResource(http) 633 634 async def models(self) -> ChatModelsResponse: 635 """ 636 List available AI models 637 Returns the set of AI models that can be used with the chat completion and 638 workflow endpoints. The list reflects models currently enabled for the 639 platform and includes each model's identifier and whether it is the default. 640 Use the `model` field from any entry in `data` as the value for 641 `opts.model` when calling the completions or workflows endpoint. 642 643 Returns: 644 Successful response 645 """ 646 return await self._http.request("/api/v1/ai/chat/models", response_type=ChatModelsResponse)
634 async def models(self) -> ChatModelsResponse: 635 """ 636 List available AI models 637 Returns the set of AI models that can be used with the chat completion and 638 workflow endpoints. The list reflects models currently enabled for the 639 platform and includes each model's identifier and whether it is the default. 640 Use the `model` field from any entry in `data` as the value for 641 `opts.model` when calling the completions or workflows endpoint. 642 643 Returns: 644 Successful response 645 """ 646 return await self._http.request("/api/v1/ai/chat/models", response_type=ChatModelsResponse)
List available AI models
Returns the set of AI models that can be used with the chat completion and
workflow endpoints. The list reflects models currently enabled for the
platform and includes each model's identifier and whether it is the default.
Use the model field from any entry in data as the value for
opts.model when calling the completions or workflows endpoint.
Returns:
Successful response
649class AsyncEmbeddingResource: 650 def __init__(self, http: HttpClient): 651 self._http = http 652 653 async def similarity_comparison( 654 self, input: EmbeddingSimilarityComparisonInput 655 ) -> EmbeddingSimilarityComparisonResponse: 656 """ 657 Compare the embedding similarity of two texts 658 Embeds both texts in one synchronous request using the platform's default 659 embedding model, then returns their cosine similarity. The score uses the 660 same `1 - cosine_distance` convention as context retrieval. A score near 661 `1.0` indicates similar vector direction; lower scores indicate less similar 662 text. This endpoint is intended for authenticated users interactively 663 exploring how the platform's retrieval similarity behaves. 664 665 Args: 666 input: Request body. 667 input.text_a: First text to embed and compare. 668 input.text_b: Second text to embed and compare. 669 670 Returns: 671 Successful response 672 """ 673 return await self._http.request( 674 "/api/v1/ai/embedding/similarity_comparison", 675 method="POST", 676 body=input, 677 response_type=EmbeddingSimilarityComparisonResponse, 678 )
653 async def similarity_comparison( 654 self, input: EmbeddingSimilarityComparisonInput 655 ) -> EmbeddingSimilarityComparisonResponse: 656 """ 657 Compare the embedding similarity of two texts 658 Embeds both texts in one synchronous request using the platform's default 659 embedding model, then returns their cosine similarity. The score uses the 660 same `1 - cosine_distance` convention as context retrieval. A score near 661 `1.0` indicates similar vector direction; lower scores indicate less similar 662 text. This endpoint is intended for authenticated users interactively 663 exploring how the platform's retrieval similarity behaves. 664 665 Args: 666 input: Request body. 667 input.text_a: First text to embed and compare. 668 input.text_b: Second text to embed and compare. 669 670 Returns: 671 Successful response 672 """ 673 return await self._http.request( 674 "/api/v1/ai/embedding/similarity_comparison", 675 method="POST", 676 body=input, 677 response_type=EmbeddingSimilarityComparisonResponse, 678 )
Compare the embedding similarity of two texts
Embeds both texts in one synchronous request using the platform's default
embedding model, then returns their cosine similarity. The score uses the
same 1 - cosine_distance convention as context retrieval. A score near
1.0 indicates similar vector direction; lower scores indicate less similar
text. This endpoint is intended for authenticated users interactively
exploring how the platform's retrieval similarity behaves.
Arguments:
- input: Request body.
- input.text_a: First text to embed and compare.
- input.text_b: Second text to embed and compare.
Returns:
Successful response
681class AsyncEvaluationResource: 682 def __init__(self, http: HttpClient): 683 self._http = http 684 685 async def evaluations(self, input: EvaluationEvaluationsInput) -> AIEvaluationResult: 686 """ 687 Create an evaluation 688 Sends a shared `state` and a list of typed questions to an evaluation 689 model and returns typed answers. This is not chat completion and not 690 JSON-schema structured output: there is no generated text. 691 Each question is a `boolean`, `choice`, or `score` object with its own 692 `id`. Answers carry that `id`, including a `refusal` answer containing 693 only `id` and `type` when the model declines to judge a question. 694 Image input, labelled score levels, and refusal answers are model-dependent. 695 Images are separate from `state` and use the chat completion image-part format. 696 Models without image support reject image input with `400 unsupported_capability`. 697 The authenticated app must have the `llm_calls` entitlement enabled on its 698 plan. Requests that exceed the plan quota are rejected with `402`. Token 699 usage is recorded against the authenticated app and organization. 700 701 Args: 702 input: Request body. 703 input.images: Optional image content parts. Omitted or empty means no images. Requires model image support. 704 input.model: Evaluation model identifier. Omit to use the platform default. 705 input.questions: Nonempty list of boolean, choice, or score questions. Each question must include `id`, `type`, and `instructions`. 706 input.session_id: Optional UUID grouping this evaluation under one session in the Developers dashboard. Generated when omitted. 707 input.state: Shared content the model judges. A string, JSON object, or JSON array. Every question in the request sees this same state. 708 709 Returns: 710 Typed boolean, choice, score, or refusal answers, plus model and usage. 711 """ 712 return await self._http.request( 713 "/api/v1/ai/evaluation/evaluations", 714 method="POST", 715 body=input, 716 response_type=AIEvaluationResult, 717 ) 718 719 async def models(self) -> EvaluationModelsResponse: 720 """ 721 List available evaluation models 722 Returns the set of evaluation models that can be used with the evaluations 723 endpoint. The list reflects models currently enabled for the platform and 724 includes each model's identifier and whether it is the default. 725 Use the `id` field from any entry in `data` as the `model` value when 726 calling the evaluations endpoint. 727 728 Returns: 729 Successful response 730 """ 731 return await self._http.request( 732 "/api/v1/ai/evaluation/models", 733 response_type=EvaluationModelsResponse, 734 )
685 async def evaluations(self, input: EvaluationEvaluationsInput) -> AIEvaluationResult: 686 """ 687 Create an evaluation 688 Sends a shared `state` and a list of typed questions to an evaluation 689 model and returns typed answers. This is not chat completion and not 690 JSON-schema structured output: there is no generated text. 691 Each question is a `boolean`, `choice`, or `score` object with its own 692 `id`. Answers carry that `id`, including a `refusal` answer containing 693 only `id` and `type` when the model declines to judge a question. 694 Image input, labelled score levels, and refusal answers are model-dependent. 695 Images are separate from `state` and use the chat completion image-part format. 696 Models without image support reject image input with `400 unsupported_capability`. 697 The authenticated app must have the `llm_calls` entitlement enabled on its 698 plan. Requests that exceed the plan quota are rejected with `402`. Token 699 usage is recorded against the authenticated app and organization. 700 701 Args: 702 input: Request body. 703 input.images: Optional image content parts. Omitted or empty means no images. Requires model image support. 704 input.model: Evaluation model identifier. Omit to use the platform default. 705 input.questions: Nonempty list of boolean, choice, or score questions. Each question must include `id`, `type`, and `instructions`. 706 input.session_id: Optional UUID grouping this evaluation under one session in the Developers dashboard. Generated when omitted. 707 input.state: Shared content the model judges. A string, JSON object, or JSON array. Every question in the request sees this same state. 708 709 Returns: 710 Typed boolean, choice, score, or refusal answers, plus model and usage. 711 """ 712 return await self._http.request( 713 "/api/v1/ai/evaluation/evaluations", 714 method="POST", 715 body=input, 716 response_type=AIEvaluationResult, 717 )
Create an evaluation
Sends a shared state and a list of typed questions to an evaluation
model and returns typed answers. This is not chat completion and not
JSON-schema structured output: there is no generated text.
Each question is a boolean, choice, or score object with its own
id. Answers carry that id, including a refusal answer containing
only id and type when the model declines to judge a question.
Image input, labelled score levels, and refusal answers are model-dependent.
Images are separate from state and use the chat completion image-part format.
Models without image support reject image input with 400 unsupported_capability.
The authenticated app must have the llm_calls entitlement enabled on its
plan. Requests that exceed the plan quota are rejected with 402. Token
usage is recorded against the authenticated app and organization.
Arguments:
- input: Request body.
- input.images: Optional image content parts. Omitted or empty means no images. Requires model image support.
- input.model: Evaluation model identifier. Omit to use the platform default.
- input.questions: Nonempty list of boolean, choice, or score questions. Each question must include
id,type, andinstructions. - input.session_id: Optional UUID grouping this evaluation under one session in the Developers dashboard. Generated when omitted.
- input.state: Shared content the model judges. A string, JSON object, or JSON array. Every question in the request sees this same state.
Returns:
Typed boolean, choice, score, or refusal answers, plus model and usage.
719 async def models(self) -> EvaluationModelsResponse: 720 """ 721 List available evaluation models 722 Returns the set of evaluation models that can be used with the evaluations 723 endpoint. The list reflects models currently enabled for the platform and 724 includes each model's identifier and whether it is the default. 725 Use the `id` field from any entry in `data` as the `model` value when 726 calling the evaluations endpoint. 727 728 Returns: 729 Successful response 730 """ 731 return await self._http.request( 732 "/api/v1/ai/evaluation/models", 733 response_type=EvaluationModelsResponse, 734 )
List available evaluation models
Returns the set of evaluation models that can be used with the evaluations
endpoint. The list reflects models currently enabled for the platform and
includes each model's identifier and whether it is the default.
Use the id field from any entry in data as the model value when
calling the evaluations endpoint.
Returns:
Successful response
737class AsyncImageResource: 738 def __init__(self, http: HttpClient): 739 self._http = http 740 741 async def edits(self, input: ImageEditsInput) -> AIImageResult: 742 """ 743 Edit an image with a text prompt 744 Applies a text-guided edit to one or more source images and returns the 745 resulting image. Pass the source images as base64-encoded objects in the 746 `images` array alongside a `prompt` describing the desired modification. 747 The underlying provider is selected by the `model` parameter. Omit `model` 748 to use the platform default. Size, quality, style, and format options are 749 forwarded to the provider as-is; unsupported combinations for a given model 750 return a 422 error with the provider's error message. 751 This endpoint requires authentication. The request is billed against the 752 workspace associated with the authenticated user. 753 754 Args: 755 input: Request body. 756 input.aspect_ratio: Desired aspect ratio of the output, e.g. `"1:1"` or `"16:9"`. Not supported by all models; omit to use the model's default. 757 input.background: Background treatment for the output. Accepted values and behavior are model-dependent. 758 input.height: Explicit output height in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 759 input.image_size: Output resolution tier for Gemini models, e.g. `"1K"`, `"2K"`, or `"4K"`. Ignored by non-Gemini models. 760 input.images: One or more source images to edit. Each image must be supplied as a base64-encoded object. 761 input.model: Model identifier to use for editing. Omit to use the platform default image model. 762 input.output_format: Desired MIME type or format for the returned image. Common values: `"png"`, `"jpeg"`, `"webp"`. Defaults to the model's native format. 763 input.prompt: Natural-language description of the edit to apply to the source image(s). 764 input.quality: Quality preset for the output image. Accepted values and behavior are model-dependent. 765 input.session_id: Optional session UUID for grouping provider attempts in usage records. Generated when omitted. 766 input.size: Output dimensions as a WxH string, e.g. `"1024x1024"`. Applies to OpenAI-compatible models. Omit to use the model's default. 767 input.style: Style preset applied to the edit. Accepted values and behavior are model-dependent. 768 input.width: Explicit output width in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 769 770 Returns: 771 The resulting edited image, including base64 data or a URL depending on the model. 772 """ 773 return await self._http.request( 774 "/api/v1/ai/image/edits", 775 method="POST", 776 body=input, 777 response_type=AIImageResult, 778 ) 779 780 async def generations(self, input: ImageGenerationsInput) -> AIImageResult: 781 """ 782 Generate an image from a text prompt 783 Generates one or more images from a natural-language `prompt` using the 784 specified AI image model. The response contains the first generated image; 785 use `n` to request additional images (where supported by the model). 786 The underlying provider is selected by the `model` parameter. Omit `model` 787 to use the platform default. Size, quality, style, and format options are 788 forwarded to the provider as-is; unsupported combinations for a given model 789 return a 422 error with the provider's error message. 790 This endpoint requires authentication. The request is billed against the 791 workspace associated with the authenticated user. 792 793 Args: 794 input: Request body. 795 input.aspect_ratio: Desired aspect ratio of the output, e.g. `"1:1"` or `"16:9"`. Not supported by all models; omit to use the model's default. 796 input.background: Background treatment for the output. Accepted values and behavior are model-dependent. 797 input.height: Explicit output height in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 798 input.image_size: Output resolution tier for Gemini models, e.g. `"1K"`, `"2K"`, or `"4K"`. Ignored by non-Gemini models. 799 input.model: Model identifier to use for generation. Omit to use the platform default image model. 800 input.n: Number of images to generate. Defaults to `1`. Values greater than `1` are only supported by models that allow batch generation. 801 input.output_format: Desired MIME type or format for the returned image. Common values: `"png"`, `"jpeg"`, `"webp"`. Defaults to the model's native format. 802 input.prompt: Natural-language description of the image to generate. 803 input.quality: Quality preset for the output image. Accepted values and behavior are model-dependent. 804 input.session_id: Optional session UUID for grouping provider attempts in usage records. Generated when omitted. 805 input.size: Output dimensions as a WxH string, e.g. `"1024x1024"`. Applies to OpenAI-compatible models. Omit to use the model's default. 806 input.style: Style preset applied to the generated image. Accepted values and behavior are model-dependent. 807 input.width: Explicit output width in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 808 809 Returns: 810 The generated image, including base64 data or a URL depending on the model. 811 """ 812 return await self._http.request( 813 "/api/v1/ai/image/generations", 814 method="POST", 815 body=input, 816 response_type=AIImageResult, 817 ) 818 819 async def models(self) -> ImageModelsResponse: 820 """ 821 List available image generation models 822 Returns the list of image generation models available on the platform. 823 Exactly one entry in the list carries `default: true`, indicating the model 824 used when no `model` parameter is supplied to the generation or editing 825 endpoints. 826 This endpoint requires authentication and reflects the models enabled for 827 the authenticated user's workspace. 828 829 Returns: 830 Successful response 831 """ 832 return await self._http.request( 833 "/api/v1/ai/image/models", 834 response_type=ImageModelsResponse, 835 )
741 async def edits(self, input: ImageEditsInput) -> AIImageResult: 742 """ 743 Edit an image with a text prompt 744 Applies a text-guided edit to one or more source images and returns the 745 resulting image. Pass the source images as base64-encoded objects in the 746 `images` array alongside a `prompt` describing the desired modification. 747 The underlying provider is selected by the `model` parameter. Omit `model` 748 to use the platform default. Size, quality, style, and format options are 749 forwarded to the provider as-is; unsupported combinations for a given model 750 return a 422 error with the provider's error message. 751 This endpoint requires authentication. The request is billed against the 752 workspace associated with the authenticated user. 753 754 Args: 755 input: Request body. 756 input.aspect_ratio: Desired aspect ratio of the output, e.g. `"1:1"` or `"16:9"`. Not supported by all models; omit to use the model's default. 757 input.background: Background treatment for the output. Accepted values and behavior are model-dependent. 758 input.height: Explicit output height in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 759 input.image_size: Output resolution tier for Gemini models, e.g. `"1K"`, `"2K"`, or `"4K"`. Ignored by non-Gemini models. 760 input.images: One or more source images to edit. Each image must be supplied as a base64-encoded object. 761 input.model: Model identifier to use for editing. Omit to use the platform default image model. 762 input.output_format: Desired MIME type or format for the returned image. Common values: `"png"`, `"jpeg"`, `"webp"`. Defaults to the model's native format. 763 input.prompt: Natural-language description of the edit to apply to the source image(s). 764 input.quality: Quality preset for the output image. Accepted values and behavior are model-dependent. 765 input.session_id: Optional session UUID for grouping provider attempts in usage records. Generated when omitted. 766 input.size: Output dimensions as a WxH string, e.g. `"1024x1024"`. Applies to OpenAI-compatible models. Omit to use the model's default. 767 input.style: Style preset applied to the edit. Accepted values and behavior are model-dependent. 768 input.width: Explicit output width in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 769 770 Returns: 771 The resulting edited image, including base64 data or a URL depending on the model. 772 """ 773 return await self._http.request( 774 "/api/v1/ai/image/edits", 775 method="POST", 776 body=input, 777 response_type=AIImageResult, 778 )
Edit an image with a text prompt
Applies a text-guided edit to one or more source images and returns the
resulting image. Pass the source images as base64-encoded objects in the
images array alongside a prompt describing the desired modification.
The underlying provider is selected by the model parameter. Omit model
to use the platform default. Size, quality, style, and format options are
forwarded to the provider as-is; unsupported combinations for a given model
return a 422 error with the provider's error message.
This endpoint requires authentication. The request is billed against the
workspace associated with the authenticated user.
Arguments:
- input: Request body.
- input.aspect_ratio: Desired aspect ratio of the output, e.g.
"1:1"or"16:9". Not supported by all models; omit to use the model's default. - input.background: Background treatment for the output. Accepted values and behavior are model-dependent.
- input.height: Explicit output height in pixels. Takes precedence over
sizewhen both are provided. Not supported by all models. - input.image_size: Output resolution tier for Gemini models, e.g.
"1K","2K", or"4K". Ignored by non-Gemini models. - input.images: One or more source images to edit. Each image must be supplied as a base64-encoded object.
- input.model: Model identifier to use for editing. Omit to use the platform default image model.
- input.output_format: Desired MIME type or format for the returned image. Common values:
"png","jpeg","webp". Defaults to the model's native format. - input.prompt: Natural-language description of the edit to apply to the source image(s).
- input.quality: Quality preset for the output image. Accepted values and behavior are model-dependent.
- input.session_id: Optional session UUID for grouping provider attempts in usage records. Generated when omitted.
- input.size: Output dimensions as a WxH string, e.g.
"1024x1024". Applies to OpenAI-compatible models. Omit to use the model's default. - input.style: Style preset applied to the edit. Accepted values and behavior are model-dependent.
- input.width: Explicit output width in pixels. Takes precedence over
sizewhen both are provided. Not supported by all models.
Returns:
The resulting edited image, including base64 data or a URL depending on the model.
780 async def generations(self, input: ImageGenerationsInput) -> AIImageResult: 781 """ 782 Generate an image from a text prompt 783 Generates one or more images from a natural-language `prompt` using the 784 specified AI image model. The response contains the first generated image; 785 use `n` to request additional images (where supported by the model). 786 The underlying provider is selected by the `model` parameter. Omit `model` 787 to use the platform default. Size, quality, style, and format options are 788 forwarded to the provider as-is; unsupported combinations for a given model 789 return a 422 error with the provider's error message. 790 This endpoint requires authentication. The request is billed against the 791 workspace associated with the authenticated user. 792 793 Args: 794 input: Request body. 795 input.aspect_ratio: Desired aspect ratio of the output, e.g. `"1:1"` or `"16:9"`. Not supported by all models; omit to use the model's default. 796 input.background: Background treatment for the output. Accepted values and behavior are model-dependent. 797 input.height: Explicit output height in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 798 input.image_size: Output resolution tier for Gemini models, e.g. `"1K"`, `"2K"`, or `"4K"`. Ignored by non-Gemini models. 799 input.model: Model identifier to use for generation. Omit to use the platform default image model. 800 input.n: Number of images to generate. Defaults to `1`. Values greater than `1` are only supported by models that allow batch generation. 801 input.output_format: Desired MIME type or format for the returned image. Common values: `"png"`, `"jpeg"`, `"webp"`. Defaults to the model's native format. 802 input.prompt: Natural-language description of the image to generate. 803 input.quality: Quality preset for the output image. Accepted values and behavior are model-dependent. 804 input.session_id: Optional session UUID for grouping provider attempts in usage records. Generated when omitted. 805 input.size: Output dimensions as a WxH string, e.g. `"1024x1024"`. Applies to OpenAI-compatible models. Omit to use the model's default. 806 input.style: Style preset applied to the generated image. Accepted values and behavior are model-dependent. 807 input.width: Explicit output width in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 808 809 Returns: 810 The generated image, including base64 data or a URL depending on the model. 811 """ 812 return await self._http.request( 813 "/api/v1/ai/image/generations", 814 method="POST", 815 body=input, 816 response_type=AIImageResult, 817 )
Generate an image from a text prompt
Generates one or more images from a natural-language prompt using the
specified AI image model. The response contains the first generated image;
use n to request additional images (where supported by the model).
The underlying provider is selected by the model parameter. Omit model
to use the platform default. Size, quality, style, and format options are
forwarded to the provider as-is; unsupported combinations for a given model
return a 422 error with the provider's error message.
This endpoint requires authentication. The request is billed against the
workspace associated with the authenticated user.
Arguments:
- input: Request body.
- input.aspect_ratio: Desired aspect ratio of the output, e.g.
"1:1"or"16:9". Not supported by all models; omit to use the model's default. - input.background: Background treatment for the output. Accepted values and behavior are model-dependent.
- input.height: Explicit output height in pixels. Takes precedence over
sizewhen both are provided. Not supported by all models. - input.image_size: Output resolution tier for Gemini models, e.g.
"1K","2K", or"4K". Ignored by non-Gemini models. - input.model: Model identifier to use for generation. Omit to use the platform default image model.
- input.n: Number of images to generate. Defaults to
1. Values greater than1are only supported by models that allow batch generation. - input.output_format: Desired MIME type or format for the returned image. Common values:
"png","jpeg","webp". Defaults to the model's native format. - input.prompt: Natural-language description of the image to generate.
- input.quality: Quality preset for the output image. Accepted values and behavior are model-dependent.
- input.session_id: Optional session UUID for grouping provider attempts in usage records. Generated when omitted.
- input.size: Output dimensions as a WxH string, e.g.
"1024x1024". Applies to OpenAI-compatible models. Omit to use the model's default. - input.style: Style preset applied to the generated image. Accepted values and behavior are model-dependent.
- input.width: Explicit output width in pixels. Takes precedence over
sizewhen both are provided. Not supported by all models.
Returns:
The generated image, including base64 data or a URL depending on the model.
819 async def models(self) -> ImageModelsResponse: 820 """ 821 List available image generation models 822 Returns the list of image generation models available on the platform. 823 Exactly one entry in the list carries `default: true`, indicating the model 824 used when no `model` parameter is supplied to the generation or editing 825 endpoints. 826 This endpoint requires authentication and reflects the models enabled for 827 the authenticated user's workspace. 828 829 Returns: 830 Successful response 831 """ 832 return await self._http.request( 833 "/api/v1/ai/image/models", 834 response_type=ImageModelsResponse, 835 )
List available image generation models
Returns the list of image generation models available on the platform.
Exactly one entry in the list carries default: true, indicating the model
used when no model parameter is supplied to the generation or editing
endpoints.
This endpoint requires authentication and reflects the models enabled for
the authenticated user's workspace.
Returns:
Successful response
838class AsyncAiResource: 839 def __init__(self, http: HttpClient): 840 self._http = http 841 self.chat = AsyncChatResource(http) 842 self.embedding = AsyncEmbeddingResource(http) 843 self.evaluation = AsyncEvaluationResource(http) 844 self.image = AsyncImageResource(http) 845 846 async def session_token(self, input: AiSessionTokenInput) -> AiSessionTokenResponse: 847 """ 848 Mint a principal-bound billing session token 849 850 Args: 851 input: Request body. 852 853 Returns: 854 Successful response 855 """ 856 return await self._http.request( 857 "/api/v1/ai/session_token", 858 method="POST", 859 body=input, 860 response_type=AiSessionTokenResponse, 861 ) 862 863 async def usage( 864 self, 865 *, 866 since: str | None = None, 867 until: str | None = None, 868 group_by: list[Literal["task", "model", "agent_kind", "agent_id", "hour"]] | None = None, 869 task: list[str] | None = None, 870 limit: int | None = None, 871 ) -> AiUsageResponse: 872 """ 873 Read the authenticated user's LLM usage 874 Returns the authenticated user's own LLM usage aggregated over a bounded 875 time window. Each row carries request and token sums plus the customer-billed 876 cost for the group. Cost is derived from the customer's active billing plan; 877 provider-reported cost is never returned. 878 Pass `group_by` one or more times to choose the grouping dimensions 879 (`task`, `model`, `agent_kind`, `agent_id`, `hour`). The window (`since` to 880 `until`) may span at most 31 days. Results are capped at `limit` groups. 881 882 Args: 883 since: Window start as an ISO 8601 timestamp (inclusive). Defaults to 7 days before `until`. 884 until: Window end as an ISO 8601 timestamp (inclusive). Defaults to now. 885 group_by: Grouping dimensions. Repeat for multiple dimensions (e.g. `group_by[]=task&group_by[]=model`). Defaults to `model`. 886 task: Restrict results to these caller task IDs. Omit to include every task. 887 limit: Maximum number of groups to return. Defaults to 50; maximum is 200. 888 889 Returns: 890 Successful response 891 """ 892 query: dict[str, object] = {} 893 if since is not None: 894 query["since"] = since 895 if until is not None: 896 query["until"] = until 897 if group_by is not None: 898 query["group_by"] = group_by 899 if task is not None: 900 query["task"] = task 901 if limit is not None: 902 query["limit"] = limit 903 return await self._http.request( 904 "/api/v1/ai/usage", 905 query=query, 906 response_type=AiUsageResponse, 907 )
846 async def session_token(self, input: AiSessionTokenInput) -> AiSessionTokenResponse: 847 """ 848 Mint a principal-bound billing session token 849 850 Args: 851 input: Request body. 852 853 Returns: 854 Successful response 855 """ 856 return await self._http.request( 857 "/api/v1/ai/session_token", 858 method="POST", 859 body=input, 860 response_type=AiSessionTokenResponse, 861 )
Mint a principal-bound billing session token
Arguments:
- input: Request body.
Returns:
Successful response
863 async def usage( 864 self, 865 *, 866 since: str | None = None, 867 until: str | None = None, 868 group_by: list[Literal["task", "model", "agent_kind", "agent_id", "hour"]] | None = None, 869 task: list[str] | None = None, 870 limit: int | None = None, 871 ) -> AiUsageResponse: 872 """ 873 Read the authenticated user's LLM usage 874 Returns the authenticated user's own LLM usage aggregated over a bounded 875 time window. Each row carries request and token sums plus the customer-billed 876 cost for the group. Cost is derived from the customer's active billing plan; 877 provider-reported cost is never returned. 878 Pass `group_by` one or more times to choose the grouping dimensions 879 (`task`, `model`, `agent_kind`, `agent_id`, `hour`). The window (`since` to 880 `until`) may span at most 31 days. Results are capped at `limit` groups. 881 882 Args: 883 since: Window start as an ISO 8601 timestamp (inclusive). Defaults to 7 days before `until`. 884 until: Window end as an ISO 8601 timestamp (inclusive). Defaults to now. 885 group_by: Grouping dimensions. Repeat for multiple dimensions (e.g. `group_by[]=task&group_by[]=model`). Defaults to `model`. 886 task: Restrict results to these caller task IDs. Omit to include every task. 887 limit: Maximum number of groups to return. Defaults to 50; maximum is 200. 888 889 Returns: 890 Successful response 891 """ 892 query: dict[str, object] = {} 893 if since is not None: 894 query["since"] = since 895 if until is not None: 896 query["until"] = until 897 if group_by is not None: 898 query["group_by"] = group_by 899 if task is not None: 900 query["task"] = task 901 if limit is not None: 902 query["limit"] = limit 903 return await self._http.request( 904 "/api/v1/ai/usage", 905 query=query, 906 response_type=AiUsageResponse, 907 )
Read the authenticated user's LLM usage
Returns the authenticated user's own LLM usage aggregated over a bounded
time window. Each row carries request and token sums plus the customer-billed
cost for the group. Cost is derived from the customer's active billing plan;
provider-reported cost is never returned.
Pass group_by one or more times to choose the grouping dimensions
(task, model, agent_kind, agent_id, hour). The window (since to
until) may span at most 31 days. Results are capped at limit groups.
Arguments:
- since: Window start as an ISO 8601 timestamp (inclusive). Defaults to 7 days before
until. - until: Window end as an ISO 8601 timestamp (inclusive). Defaults to now.
- group_by: Grouping dimensions. Repeat for multiple dimensions (e.g.
group_by[]=task&group_by[]=model). Defaults tomodel. - task: Restrict results to these caller task IDs. Omit to include every task.
- limit: Maximum number of groups to return. Defaults to 50; maximum is 200.
Returns:
Successful response
910class StreamResource: 911 def __init__(self, http: SyncHttpClient): 912 self._http = http 913 914 def create(self, input: StreamCreateInput) -> Iterator[StreamCreateEvent]: 915 """ 916 Stream a chat completion 917 Streams a chat completion over Server-Sent Events. Emits `thinking_delta` for 918 supported reasoning models, `message_delta`, `message_complete`, 919 `tool_call_*`, `tool_result`, and a terminal `done` (or `error`) event. Same 920 request shape as the non-streaming completion endpoint; the app must have the 921 `llm_calls` entitlement. 922 923 Args: 924 input: Request body. 925 input.attribution: Optional caller tags recorded on the LLM-call accounting row. Allowed keys: `task_id` (max 64 chars), `work_id` (max 64), `agent_kind` (one of `worker`, `one_off`, `subagent`, `overseer`, `task_reviewer`, `interactive`, `daemon_job`), `agent_id` (max 64), `client` (max 32). Anything else is a 400. 926 input.context: Key-value map used to resolve template variables in message content. Omit if messages contain no templates. 927 input.messages: Ordered list of conversation messages to send to the model. 928 input.opts: Model and sampling configuration for this request. 929 input.session_id: Optional UUID grouping this and other completions under one session in the Developers dashboard. Pass the same value across requests to link them; omit to auto-generate a per-request session. 930 931 Returns: 932 Server-Sent Events stream 933 """ 934 yield from self._http.stream_sse_sync( 935 "/api/v1/ai/chat/completions/stream", method="POST", body=input 936 )
914 def create(self, input: StreamCreateInput) -> Iterator[StreamCreateEvent]: 915 """ 916 Stream a chat completion 917 Streams a chat completion over Server-Sent Events. Emits `thinking_delta` for 918 supported reasoning models, `message_delta`, `message_complete`, 919 `tool_call_*`, `tool_result`, and a terminal `done` (or `error`) event. Same 920 request shape as the non-streaming completion endpoint; the app must have the 921 `llm_calls` entitlement. 922 923 Args: 924 input: Request body. 925 input.attribution: Optional caller tags recorded on the LLM-call accounting row. Allowed keys: `task_id` (max 64 chars), `work_id` (max 64), `agent_kind` (one of `worker`, `one_off`, `subagent`, `overseer`, `task_reviewer`, `interactive`, `daemon_job`), `agent_id` (max 64), `client` (max 32). Anything else is a 400. 926 input.context: Key-value map used to resolve template variables in message content. Omit if messages contain no templates. 927 input.messages: Ordered list of conversation messages to send to the model. 928 input.opts: Model and sampling configuration for this request. 929 input.session_id: Optional UUID grouping this and other completions under one session in the Developers dashboard. Pass the same value across requests to link them; omit to auto-generate a per-request session. 930 931 Returns: 932 Server-Sent Events stream 933 """ 934 yield from self._http.stream_sse_sync( 935 "/api/v1/ai/chat/completions/stream", method="POST", body=input 936 )
Stream a chat completion
Streams a chat completion over Server-Sent Events. Emits thinking_delta for
supported reasoning models, message_delta, message_complete,
tool_call_*, tool_result, and a terminal done (or error) event. Same
request shape as the non-streaming completion endpoint; the app must have the
llm_calls entitlement.
Arguments:
- input: Request body.
- input.attribution: Optional caller tags recorded on the LLM-call accounting row. Allowed keys:
task_id(max 64 chars),work_id(max 64),agent_kind(one ofworker,one_off,subagent,overseer,task_reviewer,interactive,daemon_job),agent_id(max 64),client(max 32). Anything else is a 400. - input.context: Key-value map used to resolve template variables in message content. Omit if messages contain no templates.
- input.messages: Ordered list of conversation messages to send to the model.
- input.opts: Model and sampling configuration for this request.
- input.session_id: Optional UUID grouping this and other completions under one session in the Developers dashboard. Pass the same value across requests to link them; omit to auto-generate a per-request session.
Returns:
Server-Sent Events stream
939class CompletionResource: 940 def __init__(self, http: SyncHttpClient): 941 self._http = http 942 self.stream = StreamResource(http) 943 944 def create(self, input: CompletionCreateInput) -> AICompletionResult: 945 """ 946 Create a chat completion 947 Sends a list of messages to the configured AI provider and returns a single 948 completion. Use this endpoint when you want direct, low-level access to the 949 underlying model without any workflow or agent orchestration. 950 The authenticated app must have the `llm_calls` entitlement enabled on its 951 plan. Requests that exceed the plan quota are rejected with `402`. Token 952 usage is recorded against the authenticated app and organization. 953 Supply `tools` and `tool_choice` to enable OpenAI-compatible function 954 calling. Use `server_tools` to activate platform-managed tools such as 955 search that run on the server side before the response is returned. 956 957 Args: 958 input: Request body. 959 input.attribution: Optional caller tags recorded on the LLM-call accounting row. Allowed keys: `task_id` (max 64 chars), `work_id` (max 64), `agent_kind` (one of `worker`, `one_off`, `subagent`, `overseer`, `task_reviewer`, `interactive`, `daemon_job`), `agent_id` (max 64), `client` (max 32). Anything else is a 400. 960 input.context: Key-value map used to resolve template variables in message content. Omit if messages contain no templates. 961 input.messages: Ordered list of conversation messages to send to the model. 962 input.opts: Model and sampling configuration for this request. 963 input.session_id: Optional UUID grouping this and other completions under one session in the Developers dashboard. Pass the same value across requests to link them; omit to auto-generate a per-request session. 964 965 Returns: 966 The completed AI response, including the generated message, finish reason, and token usage. 967 """ 968 return self._http.request( 969 "/api/v1/ai/chat/completions", 970 method="POST", 971 body=input, 972 response_type=AICompletionResult, 973 )
944 def create(self, input: CompletionCreateInput) -> AICompletionResult: 945 """ 946 Create a chat completion 947 Sends a list of messages to the configured AI provider and returns a single 948 completion. Use this endpoint when you want direct, low-level access to the 949 underlying model without any workflow or agent orchestration. 950 The authenticated app must have the `llm_calls` entitlement enabled on its 951 plan. Requests that exceed the plan quota are rejected with `402`. Token 952 usage is recorded against the authenticated app and organization. 953 Supply `tools` and `tool_choice` to enable OpenAI-compatible function 954 calling. Use `server_tools` to activate platform-managed tools such as 955 search that run on the server side before the response is returned. 956 957 Args: 958 input: Request body. 959 input.attribution: Optional caller tags recorded on the LLM-call accounting row. Allowed keys: `task_id` (max 64 chars), `work_id` (max 64), `agent_kind` (one of `worker`, `one_off`, `subagent`, `overseer`, `task_reviewer`, `interactive`, `daemon_job`), `agent_id` (max 64), `client` (max 32). Anything else is a 400. 960 input.context: Key-value map used to resolve template variables in message content. Omit if messages contain no templates. 961 input.messages: Ordered list of conversation messages to send to the model. 962 input.opts: Model and sampling configuration for this request. 963 input.session_id: Optional UUID grouping this and other completions under one session in the Developers dashboard. Pass the same value across requests to link them; omit to auto-generate a per-request session. 964 965 Returns: 966 The completed AI response, including the generated message, finish reason, and token usage. 967 """ 968 return self._http.request( 969 "/api/v1/ai/chat/completions", 970 method="POST", 971 body=input, 972 response_type=AICompletionResult, 973 )
Create a chat completion
Sends a list of messages to the configured AI provider and returns a single
completion. Use this endpoint when you want direct, low-level access to the
underlying model without any workflow or agent orchestration.
The authenticated app must have the llm_calls entitlement enabled on its
plan. Requests that exceed the plan quota are rejected with 402. Token
usage is recorded against the authenticated app and organization.
Supply tools and tool_choice to enable OpenAI-compatible function
calling. Use server_tools to activate platform-managed tools such as
search that run on the server side before the response is returned.
Arguments:
- input: Request body.
- input.attribution: Optional caller tags recorded on the LLM-call accounting row. Allowed keys:
task_id(max 64 chars),work_id(max 64),agent_kind(one ofworker,one_off,subagent,overseer,task_reviewer,interactive,daemon_job),agent_id(max 64),client(max 32). Anything else is a 400. - input.context: Key-value map used to resolve template variables in message content. Omit if messages contain no templates.
- input.messages: Ordered list of conversation messages to send to the model.
- input.opts: Model and sampling configuration for this request.
- input.session_id: Optional UUID grouping this and other completions under one session in the Developers dashboard. Pass the same value across requests to link them; omit to auto-generate a per-request session.
Returns:
The completed AI response, including the generated message, finish reason, and token usage.
976class ChatResource: 977 def __init__(self, http: SyncHttpClient): 978 self._http = http 979 self.completions = CompletionResource(http) 980 981 def models(self) -> ChatModelsResponse: 982 """ 983 List available AI models 984 Returns the set of AI models that can be used with the chat completion and 985 workflow endpoints. The list reflects models currently enabled for the 986 platform and includes each model's identifier and whether it is the default. 987 Use the `model` field from any entry in `data` as the value for 988 `opts.model` when calling the completions or workflows endpoint. 989 990 Returns: 991 Successful response 992 """ 993 return self._http.request("/api/v1/ai/chat/models", response_type=ChatModelsResponse)
981 def models(self) -> ChatModelsResponse: 982 """ 983 List available AI models 984 Returns the set of AI models that can be used with the chat completion and 985 workflow endpoints. The list reflects models currently enabled for the 986 platform and includes each model's identifier and whether it is the default. 987 Use the `model` field from any entry in `data` as the value for 988 `opts.model` when calling the completions or workflows endpoint. 989 990 Returns: 991 Successful response 992 """ 993 return self._http.request("/api/v1/ai/chat/models", response_type=ChatModelsResponse)
List available AI models
Returns the set of AI models that can be used with the chat completion and
workflow endpoints. The list reflects models currently enabled for the
platform and includes each model's identifier and whether it is the default.
Use the model field from any entry in data as the value for
opts.model when calling the completions or workflows endpoint.
Returns:
Successful response
996class EmbeddingResource: 997 def __init__(self, http: SyncHttpClient): 998 self._http = http 999 1000 def similarity_comparison( 1001 self, input: EmbeddingSimilarityComparisonInput 1002 ) -> EmbeddingSimilarityComparisonResponse: 1003 """ 1004 Compare the embedding similarity of two texts 1005 Embeds both texts in one synchronous request using the platform's default 1006 embedding model, then returns their cosine similarity. The score uses the 1007 same `1 - cosine_distance` convention as context retrieval. A score near 1008 `1.0` indicates similar vector direction; lower scores indicate less similar 1009 text. This endpoint is intended for authenticated users interactively 1010 exploring how the platform's retrieval similarity behaves. 1011 1012 Args: 1013 input: Request body. 1014 input.text_a: First text to embed and compare. 1015 input.text_b: Second text to embed and compare. 1016 1017 Returns: 1018 Successful response 1019 """ 1020 return self._http.request( 1021 "/api/v1/ai/embedding/similarity_comparison", 1022 method="POST", 1023 body=input, 1024 response_type=EmbeddingSimilarityComparisonResponse, 1025 )
1000 def similarity_comparison( 1001 self, input: EmbeddingSimilarityComparisonInput 1002 ) -> EmbeddingSimilarityComparisonResponse: 1003 """ 1004 Compare the embedding similarity of two texts 1005 Embeds both texts in one synchronous request using the platform's default 1006 embedding model, then returns their cosine similarity. The score uses the 1007 same `1 - cosine_distance` convention as context retrieval. A score near 1008 `1.0` indicates similar vector direction; lower scores indicate less similar 1009 text. This endpoint is intended for authenticated users interactively 1010 exploring how the platform's retrieval similarity behaves. 1011 1012 Args: 1013 input: Request body. 1014 input.text_a: First text to embed and compare. 1015 input.text_b: Second text to embed and compare. 1016 1017 Returns: 1018 Successful response 1019 """ 1020 return self._http.request( 1021 "/api/v1/ai/embedding/similarity_comparison", 1022 method="POST", 1023 body=input, 1024 response_type=EmbeddingSimilarityComparisonResponse, 1025 )
Compare the embedding similarity of two texts
Embeds both texts in one synchronous request using the platform's default
embedding model, then returns their cosine similarity. The score uses the
same 1 - cosine_distance convention as context retrieval. A score near
1.0 indicates similar vector direction; lower scores indicate less similar
text. This endpoint is intended for authenticated users interactively
exploring how the platform's retrieval similarity behaves.
Arguments:
- input: Request body.
- input.text_a: First text to embed and compare.
- input.text_b: Second text to embed and compare.
Returns:
Successful response
1028class EvaluationResource: 1029 def __init__(self, http: SyncHttpClient): 1030 self._http = http 1031 1032 def evaluations(self, input: EvaluationEvaluationsInput) -> AIEvaluationResult: 1033 """ 1034 Create an evaluation 1035 Sends a shared `state` and a list of typed questions to an evaluation 1036 model and returns typed answers. This is not chat completion and not 1037 JSON-schema structured output: there is no generated text. 1038 Each question is a `boolean`, `choice`, or `score` object with its own 1039 `id`. Answers carry that `id`, including a `refusal` answer containing 1040 only `id` and `type` when the model declines to judge a question. 1041 Image input, labelled score levels, and refusal answers are model-dependent. 1042 Images are separate from `state` and use the chat completion image-part format. 1043 Models without image support reject image input with `400 unsupported_capability`. 1044 The authenticated app must have the `llm_calls` entitlement enabled on its 1045 plan. Requests that exceed the plan quota are rejected with `402`. Token 1046 usage is recorded against the authenticated app and organization. 1047 1048 Args: 1049 input: Request body. 1050 input.images: Optional image content parts. Omitted or empty means no images. Requires model image support. 1051 input.model: Evaluation model identifier. Omit to use the platform default. 1052 input.questions: Nonempty list of boolean, choice, or score questions. Each question must include `id`, `type`, and `instructions`. 1053 input.session_id: Optional UUID grouping this evaluation under one session in the Developers dashboard. Generated when omitted. 1054 input.state: Shared content the model judges. A string, JSON object, or JSON array. Every question in the request sees this same state. 1055 1056 Returns: 1057 Typed boolean, choice, score, or refusal answers, plus model and usage. 1058 """ 1059 return self._http.request( 1060 "/api/v1/ai/evaluation/evaluations", 1061 method="POST", 1062 body=input, 1063 response_type=AIEvaluationResult, 1064 ) 1065 1066 def models(self) -> EvaluationModelsResponse: 1067 """ 1068 List available evaluation models 1069 Returns the set of evaluation models that can be used with the evaluations 1070 endpoint. The list reflects models currently enabled for the platform and 1071 includes each model's identifier and whether it is the default. 1072 Use the `id` field from any entry in `data` as the `model` value when 1073 calling the evaluations endpoint. 1074 1075 Returns: 1076 Successful response 1077 """ 1078 return self._http.request( 1079 "/api/v1/ai/evaluation/models", 1080 response_type=EvaluationModelsResponse, 1081 )
1032 def evaluations(self, input: EvaluationEvaluationsInput) -> AIEvaluationResult: 1033 """ 1034 Create an evaluation 1035 Sends a shared `state` and a list of typed questions to an evaluation 1036 model and returns typed answers. This is not chat completion and not 1037 JSON-schema structured output: there is no generated text. 1038 Each question is a `boolean`, `choice`, or `score` object with its own 1039 `id`. Answers carry that `id`, including a `refusal` answer containing 1040 only `id` and `type` when the model declines to judge a question. 1041 Image input, labelled score levels, and refusal answers are model-dependent. 1042 Images are separate from `state` and use the chat completion image-part format. 1043 Models without image support reject image input with `400 unsupported_capability`. 1044 The authenticated app must have the `llm_calls` entitlement enabled on its 1045 plan. Requests that exceed the plan quota are rejected with `402`. Token 1046 usage is recorded against the authenticated app and organization. 1047 1048 Args: 1049 input: Request body. 1050 input.images: Optional image content parts. Omitted or empty means no images. Requires model image support. 1051 input.model: Evaluation model identifier. Omit to use the platform default. 1052 input.questions: Nonempty list of boolean, choice, or score questions. Each question must include `id`, `type`, and `instructions`. 1053 input.session_id: Optional UUID grouping this evaluation under one session in the Developers dashboard. Generated when omitted. 1054 input.state: Shared content the model judges. A string, JSON object, or JSON array. Every question in the request sees this same state. 1055 1056 Returns: 1057 Typed boolean, choice, score, or refusal answers, plus model and usage. 1058 """ 1059 return self._http.request( 1060 "/api/v1/ai/evaluation/evaluations", 1061 method="POST", 1062 body=input, 1063 response_type=AIEvaluationResult, 1064 )
Create an evaluation
Sends a shared state and a list of typed questions to an evaluation
model and returns typed answers. This is not chat completion and not
JSON-schema structured output: there is no generated text.
Each question is a boolean, choice, or score object with its own
id. Answers carry that id, including a refusal answer containing
only id and type when the model declines to judge a question.
Image input, labelled score levels, and refusal answers are model-dependent.
Images are separate from state and use the chat completion image-part format.
Models without image support reject image input with 400 unsupported_capability.
The authenticated app must have the llm_calls entitlement enabled on its
plan. Requests that exceed the plan quota are rejected with 402. Token
usage is recorded against the authenticated app and organization.
Arguments:
- input: Request body.
- input.images: Optional image content parts. Omitted or empty means no images. Requires model image support.
- input.model: Evaluation model identifier. Omit to use the platform default.
- input.questions: Nonempty list of boolean, choice, or score questions. Each question must include
id,type, andinstructions. - input.session_id: Optional UUID grouping this evaluation under one session in the Developers dashboard. Generated when omitted.
- input.state: Shared content the model judges. A string, JSON object, or JSON array. Every question in the request sees this same state.
Returns:
Typed boolean, choice, score, or refusal answers, plus model and usage.
1066 def models(self) -> EvaluationModelsResponse: 1067 """ 1068 List available evaluation models 1069 Returns the set of evaluation models that can be used with the evaluations 1070 endpoint. The list reflects models currently enabled for the platform and 1071 includes each model's identifier and whether it is the default. 1072 Use the `id` field from any entry in `data` as the `model` value when 1073 calling the evaluations endpoint. 1074 1075 Returns: 1076 Successful response 1077 """ 1078 return self._http.request( 1079 "/api/v1/ai/evaluation/models", 1080 response_type=EvaluationModelsResponse, 1081 )
List available evaluation models
Returns the set of evaluation models that can be used with the evaluations
endpoint. The list reflects models currently enabled for the platform and
includes each model's identifier and whether it is the default.
Use the id field from any entry in data as the model value when
calling the evaluations endpoint.
Returns:
Successful response
1084class ImageResource: 1085 def __init__(self, http: SyncHttpClient): 1086 self._http = http 1087 1088 def edits(self, input: ImageEditsInput) -> AIImageResult: 1089 """ 1090 Edit an image with a text prompt 1091 Applies a text-guided edit to one or more source images and returns the 1092 resulting image. Pass the source images as base64-encoded objects in the 1093 `images` array alongside a `prompt` describing the desired modification. 1094 The underlying provider is selected by the `model` parameter. Omit `model` 1095 to use the platform default. Size, quality, style, and format options are 1096 forwarded to the provider as-is; unsupported combinations for a given model 1097 return a 422 error with the provider's error message. 1098 This endpoint requires authentication. The request is billed against the 1099 workspace associated with the authenticated user. 1100 1101 Args: 1102 input: Request body. 1103 input.aspect_ratio: Desired aspect ratio of the output, e.g. `"1:1"` or `"16:9"`. Not supported by all models; omit to use the model's default. 1104 input.background: Background treatment for the output. Accepted values and behavior are model-dependent. 1105 input.height: Explicit output height in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 1106 input.image_size: Output resolution tier for Gemini models, e.g. `"1K"`, `"2K"`, or `"4K"`. Ignored by non-Gemini models. 1107 input.images: One or more source images to edit. Each image must be supplied as a base64-encoded object. 1108 input.model: Model identifier to use for editing. Omit to use the platform default image model. 1109 input.output_format: Desired MIME type or format for the returned image. Common values: `"png"`, `"jpeg"`, `"webp"`. Defaults to the model's native format. 1110 input.prompt: Natural-language description of the edit to apply to the source image(s). 1111 input.quality: Quality preset for the output image. Accepted values and behavior are model-dependent. 1112 input.session_id: Optional session UUID for grouping provider attempts in usage records. Generated when omitted. 1113 input.size: Output dimensions as a WxH string, e.g. `"1024x1024"`. Applies to OpenAI-compatible models. Omit to use the model's default. 1114 input.style: Style preset applied to the edit. Accepted values and behavior are model-dependent. 1115 input.width: Explicit output width in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 1116 1117 Returns: 1118 The resulting edited image, including base64 data or a URL depending on the model. 1119 """ 1120 return self._http.request( 1121 "/api/v1/ai/image/edits", 1122 method="POST", 1123 body=input, 1124 response_type=AIImageResult, 1125 ) 1126 1127 def generations(self, input: ImageGenerationsInput) -> AIImageResult: 1128 """ 1129 Generate an image from a text prompt 1130 Generates one or more images from a natural-language `prompt` using the 1131 specified AI image model. The response contains the first generated image; 1132 use `n` to request additional images (where supported by the model). 1133 The underlying provider is selected by the `model` parameter. Omit `model` 1134 to use the platform default. Size, quality, style, and format options are 1135 forwarded to the provider as-is; unsupported combinations for a given model 1136 return a 422 error with the provider's error message. 1137 This endpoint requires authentication. The request is billed against the 1138 workspace associated with the authenticated user. 1139 1140 Args: 1141 input: Request body. 1142 input.aspect_ratio: Desired aspect ratio of the output, e.g. `"1:1"` or `"16:9"`. Not supported by all models; omit to use the model's default. 1143 input.background: Background treatment for the output. Accepted values and behavior are model-dependent. 1144 input.height: Explicit output height in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 1145 input.image_size: Output resolution tier for Gemini models, e.g. `"1K"`, `"2K"`, or `"4K"`. Ignored by non-Gemini models. 1146 input.model: Model identifier to use for generation. Omit to use the platform default image model. 1147 input.n: Number of images to generate. Defaults to `1`. Values greater than `1` are only supported by models that allow batch generation. 1148 input.output_format: Desired MIME type or format for the returned image. Common values: `"png"`, `"jpeg"`, `"webp"`. Defaults to the model's native format. 1149 input.prompt: Natural-language description of the image to generate. 1150 input.quality: Quality preset for the output image. Accepted values and behavior are model-dependent. 1151 input.session_id: Optional session UUID for grouping provider attempts in usage records. Generated when omitted. 1152 input.size: Output dimensions as a WxH string, e.g. `"1024x1024"`. Applies to OpenAI-compatible models. Omit to use the model's default. 1153 input.style: Style preset applied to the generated image. Accepted values and behavior are model-dependent. 1154 input.width: Explicit output width in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 1155 1156 Returns: 1157 The generated image, including base64 data or a URL depending on the model. 1158 """ 1159 return self._http.request( 1160 "/api/v1/ai/image/generations", 1161 method="POST", 1162 body=input, 1163 response_type=AIImageResult, 1164 ) 1165 1166 def models(self) -> ImageModelsResponse: 1167 """ 1168 List available image generation models 1169 Returns the list of image generation models available on the platform. 1170 Exactly one entry in the list carries `default: true`, indicating the model 1171 used when no `model` parameter is supplied to the generation or editing 1172 endpoints. 1173 This endpoint requires authentication and reflects the models enabled for 1174 the authenticated user's workspace. 1175 1176 Returns: 1177 Successful response 1178 """ 1179 return self._http.request("/api/v1/ai/image/models", response_type=ImageModelsResponse)
1088 def edits(self, input: ImageEditsInput) -> AIImageResult: 1089 """ 1090 Edit an image with a text prompt 1091 Applies a text-guided edit to one or more source images and returns the 1092 resulting image. Pass the source images as base64-encoded objects in the 1093 `images` array alongside a `prompt` describing the desired modification. 1094 The underlying provider is selected by the `model` parameter. Omit `model` 1095 to use the platform default. Size, quality, style, and format options are 1096 forwarded to the provider as-is; unsupported combinations for a given model 1097 return a 422 error with the provider's error message. 1098 This endpoint requires authentication. The request is billed against the 1099 workspace associated with the authenticated user. 1100 1101 Args: 1102 input: Request body. 1103 input.aspect_ratio: Desired aspect ratio of the output, e.g. `"1:1"` or `"16:9"`. Not supported by all models; omit to use the model's default. 1104 input.background: Background treatment for the output. Accepted values and behavior are model-dependent. 1105 input.height: Explicit output height in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 1106 input.image_size: Output resolution tier for Gemini models, e.g. `"1K"`, `"2K"`, or `"4K"`. Ignored by non-Gemini models. 1107 input.images: One or more source images to edit. Each image must be supplied as a base64-encoded object. 1108 input.model: Model identifier to use for editing. Omit to use the platform default image model. 1109 input.output_format: Desired MIME type or format for the returned image. Common values: `"png"`, `"jpeg"`, `"webp"`. Defaults to the model's native format. 1110 input.prompt: Natural-language description of the edit to apply to the source image(s). 1111 input.quality: Quality preset for the output image. Accepted values and behavior are model-dependent. 1112 input.session_id: Optional session UUID for grouping provider attempts in usage records. Generated when omitted. 1113 input.size: Output dimensions as a WxH string, e.g. `"1024x1024"`. Applies to OpenAI-compatible models. Omit to use the model's default. 1114 input.style: Style preset applied to the edit. Accepted values and behavior are model-dependent. 1115 input.width: Explicit output width in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 1116 1117 Returns: 1118 The resulting edited image, including base64 data or a URL depending on the model. 1119 """ 1120 return self._http.request( 1121 "/api/v1/ai/image/edits", 1122 method="POST", 1123 body=input, 1124 response_type=AIImageResult, 1125 )
Edit an image with a text prompt
Applies a text-guided edit to one or more source images and returns the
resulting image. Pass the source images as base64-encoded objects in the
images array alongside a prompt describing the desired modification.
The underlying provider is selected by the model parameter. Omit model
to use the platform default. Size, quality, style, and format options are
forwarded to the provider as-is; unsupported combinations for a given model
return a 422 error with the provider's error message.
This endpoint requires authentication. The request is billed against the
workspace associated with the authenticated user.
Arguments:
- input: Request body.
- input.aspect_ratio: Desired aspect ratio of the output, e.g.
"1:1"or"16:9". Not supported by all models; omit to use the model's default. - input.background: Background treatment for the output. Accepted values and behavior are model-dependent.
- input.height: Explicit output height in pixels. Takes precedence over
sizewhen both are provided. Not supported by all models. - input.image_size: Output resolution tier for Gemini models, e.g.
"1K","2K", or"4K". Ignored by non-Gemini models. - input.images: One or more source images to edit. Each image must be supplied as a base64-encoded object.
- input.model: Model identifier to use for editing. Omit to use the platform default image model.
- input.output_format: Desired MIME type or format for the returned image. Common values:
"png","jpeg","webp". Defaults to the model's native format. - input.prompt: Natural-language description of the edit to apply to the source image(s).
- input.quality: Quality preset for the output image. Accepted values and behavior are model-dependent.
- input.session_id: Optional session UUID for grouping provider attempts in usage records. Generated when omitted.
- input.size: Output dimensions as a WxH string, e.g.
"1024x1024". Applies to OpenAI-compatible models. Omit to use the model's default. - input.style: Style preset applied to the edit. Accepted values and behavior are model-dependent.
- input.width: Explicit output width in pixels. Takes precedence over
sizewhen both are provided. Not supported by all models.
Returns:
The resulting edited image, including base64 data or a URL depending on the model.
1127 def generations(self, input: ImageGenerationsInput) -> AIImageResult: 1128 """ 1129 Generate an image from a text prompt 1130 Generates one or more images from a natural-language `prompt` using the 1131 specified AI image model. The response contains the first generated image; 1132 use `n` to request additional images (where supported by the model). 1133 The underlying provider is selected by the `model` parameter. Omit `model` 1134 to use the platform default. Size, quality, style, and format options are 1135 forwarded to the provider as-is; unsupported combinations for a given model 1136 return a 422 error with the provider's error message. 1137 This endpoint requires authentication. The request is billed against the 1138 workspace associated with the authenticated user. 1139 1140 Args: 1141 input: Request body. 1142 input.aspect_ratio: Desired aspect ratio of the output, e.g. `"1:1"` or `"16:9"`. Not supported by all models; omit to use the model's default. 1143 input.background: Background treatment for the output. Accepted values and behavior are model-dependent. 1144 input.height: Explicit output height in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 1145 input.image_size: Output resolution tier for Gemini models, e.g. `"1K"`, `"2K"`, or `"4K"`. Ignored by non-Gemini models. 1146 input.model: Model identifier to use for generation. Omit to use the platform default image model. 1147 input.n: Number of images to generate. Defaults to `1`. Values greater than `1` are only supported by models that allow batch generation. 1148 input.output_format: Desired MIME type or format for the returned image. Common values: `"png"`, `"jpeg"`, `"webp"`. Defaults to the model's native format. 1149 input.prompt: Natural-language description of the image to generate. 1150 input.quality: Quality preset for the output image. Accepted values and behavior are model-dependent. 1151 input.session_id: Optional session UUID for grouping provider attempts in usage records. Generated when omitted. 1152 input.size: Output dimensions as a WxH string, e.g. `"1024x1024"`. Applies to OpenAI-compatible models. Omit to use the model's default. 1153 input.style: Style preset applied to the generated image. Accepted values and behavior are model-dependent. 1154 input.width: Explicit output width in pixels. Takes precedence over `size` when both are provided. Not supported by all models. 1155 1156 Returns: 1157 The generated image, including base64 data or a URL depending on the model. 1158 """ 1159 return self._http.request( 1160 "/api/v1/ai/image/generations", 1161 method="POST", 1162 body=input, 1163 response_type=AIImageResult, 1164 )
Generate an image from a text prompt
Generates one or more images from a natural-language prompt using the
specified AI image model. The response contains the first generated image;
use n to request additional images (where supported by the model).
The underlying provider is selected by the model parameter. Omit model
to use the platform default. Size, quality, style, and format options are
forwarded to the provider as-is; unsupported combinations for a given model
return a 422 error with the provider's error message.
This endpoint requires authentication. The request is billed against the
workspace associated with the authenticated user.
Arguments:
- input: Request body.
- input.aspect_ratio: Desired aspect ratio of the output, e.g.
"1:1"or"16:9". Not supported by all models; omit to use the model's default. - input.background: Background treatment for the output. Accepted values and behavior are model-dependent.
- input.height: Explicit output height in pixels. Takes precedence over
sizewhen both are provided. Not supported by all models. - input.image_size: Output resolution tier for Gemini models, e.g.
"1K","2K", or"4K". Ignored by non-Gemini models. - input.model: Model identifier to use for generation. Omit to use the platform default image model.
- input.n: Number of images to generate. Defaults to
1. Values greater than1are only supported by models that allow batch generation. - input.output_format: Desired MIME type or format for the returned image. Common values:
"png","jpeg","webp". Defaults to the model's native format. - input.prompt: Natural-language description of the image to generate.
- input.quality: Quality preset for the output image. Accepted values and behavior are model-dependent.
- input.session_id: Optional session UUID for grouping provider attempts in usage records. Generated when omitted.
- input.size: Output dimensions as a WxH string, e.g.
"1024x1024". Applies to OpenAI-compatible models. Omit to use the model's default. - input.style: Style preset applied to the generated image. Accepted values and behavior are model-dependent.
- input.width: Explicit output width in pixels. Takes precedence over
sizewhen both are provided. Not supported by all models.
Returns:
The generated image, including base64 data or a URL depending on the model.
1166 def models(self) -> ImageModelsResponse: 1167 """ 1168 List available image generation models 1169 Returns the list of image generation models available on the platform. 1170 Exactly one entry in the list carries `default: true`, indicating the model 1171 used when no `model` parameter is supplied to the generation or editing 1172 endpoints. 1173 This endpoint requires authentication and reflects the models enabled for 1174 the authenticated user's workspace. 1175 1176 Returns: 1177 Successful response 1178 """ 1179 return self._http.request("/api/v1/ai/image/models", response_type=ImageModelsResponse)
List available image generation models
Returns the list of image generation models available on the platform.
Exactly one entry in the list carries default: true, indicating the model
used when no model parameter is supplied to the generation or editing
endpoints.
This endpoint requires authentication and reflects the models enabled for
the authenticated user's workspace.
Returns:
Successful response
1182class AiResource: 1183 def __init__(self, http: SyncHttpClient): 1184 self._http = http 1185 self.chat = ChatResource(http) 1186 self.embedding = EmbeddingResource(http) 1187 self.evaluation = EvaluationResource(http) 1188 self.image = ImageResource(http) 1189 1190 def session_token(self, input: AiSessionTokenInput) -> AiSessionTokenResponse: 1191 """ 1192 Mint a principal-bound billing session token 1193 1194 Args: 1195 input: Request body. 1196 1197 Returns: 1198 Successful response 1199 """ 1200 return self._http.request( 1201 "/api/v1/ai/session_token", 1202 method="POST", 1203 body=input, 1204 response_type=AiSessionTokenResponse, 1205 ) 1206 1207 def usage( 1208 self, 1209 *, 1210 since: str | None = None, 1211 until: str | None = None, 1212 group_by: list[Literal["task", "model", "agent_kind", "agent_id", "hour"]] | None = None, 1213 task: list[str] | None = None, 1214 limit: int | None = None, 1215 ) -> AiUsageResponse: 1216 """ 1217 Read the authenticated user's LLM usage 1218 Returns the authenticated user's own LLM usage aggregated over a bounded 1219 time window. Each row carries request and token sums plus the customer-billed 1220 cost for the group. Cost is derived from the customer's active billing plan; 1221 provider-reported cost is never returned. 1222 Pass `group_by` one or more times to choose the grouping dimensions 1223 (`task`, `model`, `agent_kind`, `agent_id`, `hour`). The window (`since` to 1224 `until`) may span at most 31 days. Results are capped at `limit` groups. 1225 1226 Args: 1227 since: Window start as an ISO 8601 timestamp (inclusive). Defaults to 7 days before `until`. 1228 until: Window end as an ISO 8601 timestamp (inclusive). Defaults to now. 1229 group_by: Grouping dimensions. Repeat for multiple dimensions (e.g. `group_by[]=task&group_by[]=model`). Defaults to `model`. 1230 task: Restrict results to these caller task IDs. Omit to include every task. 1231 limit: Maximum number of groups to return. Defaults to 50; maximum is 200. 1232 1233 Returns: 1234 Successful response 1235 """ 1236 query: dict[str, object] = {} 1237 if since is not None: 1238 query["since"] = since 1239 if until is not None: 1240 query["until"] = until 1241 if group_by is not None: 1242 query["group_by"] = group_by 1243 if task is not None: 1244 query["task"] = task 1245 if limit is not None: 1246 query["limit"] = limit 1247 return self._http.request("/api/v1/ai/usage", query=query, response_type=AiUsageResponse)
1190 def session_token(self, input: AiSessionTokenInput) -> AiSessionTokenResponse: 1191 """ 1192 Mint a principal-bound billing session token 1193 1194 Args: 1195 input: Request body. 1196 1197 Returns: 1198 Successful response 1199 """ 1200 return self._http.request( 1201 "/api/v1/ai/session_token", 1202 method="POST", 1203 body=input, 1204 response_type=AiSessionTokenResponse, 1205 )
Mint a principal-bound billing session token
Arguments:
- input: Request body.
Returns:
Successful response
1207 def usage( 1208 self, 1209 *, 1210 since: str | None = None, 1211 until: str | None = None, 1212 group_by: list[Literal["task", "model", "agent_kind", "agent_id", "hour"]] | None = None, 1213 task: list[str] | None = None, 1214 limit: int | None = None, 1215 ) -> AiUsageResponse: 1216 """ 1217 Read the authenticated user's LLM usage 1218 Returns the authenticated user's own LLM usage aggregated over a bounded 1219 time window. Each row carries request and token sums plus the customer-billed 1220 cost for the group. Cost is derived from the customer's active billing plan; 1221 provider-reported cost is never returned. 1222 Pass `group_by` one or more times to choose the grouping dimensions 1223 (`task`, `model`, `agent_kind`, `agent_id`, `hour`). The window (`since` to 1224 `until`) may span at most 31 days. Results are capped at `limit` groups. 1225 1226 Args: 1227 since: Window start as an ISO 8601 timestamp (inclusive). Defaults to 7 days before `until`. 1228 until: Window end as an ISO 8601 timestamp (inclusive). Defaults to now. 1229 group_by: Grouping dimensions. Repeat for multiple dimensions (e.g. `group_by[]=task&group_by[]=model`). Defaults to `model`. 1230 task: Restrict results to these caller task IDs. Omit to include every task. 1231 limit: Maximum number of groups to return. Defaults to 50; maximum is 200. 1232 1233 Returns: 1234 Successful response 1235 """ 1236 query: dict[str, object] = {} 1237 if since is not None: 1238 query["since"] = since 1239 if until is not None: 1240 query["until"] = until 1241 if group_by is not None: 1242 query["group_by"] = group_by 1243 if task is not None: 1244 query["task"] = task 1245 if limit is not None: 1246 query["limit"] = limit 1247 return self._http.request("/api/v1/ai/usage", query=query, response_type=AiUsageResponse)
Read the authenticated user's LLM usage
Returns the authenticated user's own LLM usage aggregated over a bounded
time window. Each row carries request and token sums plus the customer-billed
cost for the group. Cost is derived from the customer's active billing plan;
provider-reported cost is never returned.
Pass group_by one or more times to choose the grouping dimensions
(task, model, agent_kind, agent_id, hour). The window (since to
until) may span at most 31 days. Results are capped at limit groups.
Arguments:
- since: Window start as an ISO 8601 timestamp (inclusive). Defaults to 7 days before
until. - until: Window end as an ISO 8601 timestamp (inclusive). Defaults to now.
- group_by: Grouping dimensions. Repeat for multiple dimensions (e.g.
group_by[]=task&group_by[]=model). Defaults tomodel. - task: Restrict results to these caller task IDs. Omit to include every task.
- limit: Maximum number of groups to return. Defaults to 50; maximum is 200.
Returns:
Successful response