GatewayClient¶
flow_sdk.gateway_client.GatewayClient(base_url=None, auth_token=None, timeout=60.0, on_auth_token_refresh=None)
¶
Client for calling the platform AI gateway from workflow containers.
Provides methods for chat completions (streaming and non-streaming), embeddings, and model/provider discovery. All requests are authenticated with the same JWT token used by PlatformClient.
Attributes:
| Name | Type | Description |
|---|---|---|
base_url |
Platform API base URL |
|
auth_token |
JWT authentication token |
|
client |
Async HTTP client instance |
Initialize gateway client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str | None
|
Platform API base URL (defaults to PLATFORM_API_URL env var) |
None
|
auth_token
|
str | None
|
JWT token (defaults to AUTH_TOKEN env var) |
None
|
timeout
|
float
|
Request timeout in seconds (default: 60) |
60.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If base_url or auth_token not provided and not in environment |
Source code in flow_sdk/gateway_client.py
__aenter__()
async
¶
__aexit__(exc_type, exc_val, exc_tb)
async
¶
close()
async
¶
chat_completion(model, messages, *, temperature=None, max_tokens=None, top_p=None)
async
¶
Send a non-streaming chat completion request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Model identifier (e.g., "openai/gpt-4o") |
required |
messages
|
list[dict[str, Any]]
|
List of message dicts with "role" and "content" |
required |
temperature
|
float | None
|
Sampling temperature (optional) |
None
|
max_tokens
|
int | None
|
Maximum tokens to generate (optional) |
None
|
top_p
|
float | None
|
Nucleus sampling probability (optional) |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
OpenAI-shaped response dict with id, object, model, choices, usage |
Raises:
| Type | Description |
|---|---|
GatewayAuthError
|
If authentication fails |
GatewayModelNotFoundError
|
If model not found |
GatewayRateLimitError
|
If rate limited |
GatewayProviderError
|
If upstream provider fails |
GatewayClientError
|
For other errors |
Source code in flow_sdk/gateway_client.py
stream_chat_completion(model, messages, *, temperature=None, max_tokens=None, top_p=None)
async
¶
Send a streaming chat completion request.
Parses server-sent events (SSE) and yields each chunk as a dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Model identifier (e.g., "openai/gpt-4o") |
required |
messages
|
list[dict[str, Any]]
|
List of message dicts with "role" and "content" |
required |
temperature
|
float | None
|
Sampling temperature (optional) |
None
|
max_tokens
|
int | None
|
Maximum tokens to generate (optional) |
None
|
top_p
|
float | None
|
Nucleus sampling probability (optional) |
None
|
Yields:
| Type | Description |
|---|---|
AsyncGenerator[dict[str, Any], None]
|
OpenAI-shaped streaming chunk dicts with delta content |
Raises:
| Type | Description |
|---|---|
GatewayAuthError
|
If authentication fails |
GatewayModelNotFoundError
|
If model not found |
GatewayRateLimitError
|
If rate limited |
GatewayProviderError
|
If upstream provider fails |
GatewayClientError
|
For other errors |
Source code in flow_sdk/gateway_client.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | |
embedding(model, input)
async
¶
Generate embeddings for the given input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Embedding model identifier |
required |
input
|
str | list[str]
|
Text string or list of strings to embed |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
OpenAI-shaped response with object, data (list of embedding vectors), |
dict[str, Any]
|
and usage |
Raises:
| Type | Description |
|---|---|
GatewayAuthError
|
If authentication fails |
GatewayModelNotFoundError
|
If model not found |
GatewayRateLimitError
|
If rate limited |
GatewayProviderError
|
If upstream provider fails |
GatewayClientError
|
For other errors |
Source code in flow_sdk/gateway_client.py
list_models()
async
¶
List all available models through the gateway.
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of model dicts from the OpenAI-shaped models response |
Raises:
| Type | Description |
|---|---|
GatewayAuthError
|
If authentication fails |
GatewayClientError
|
For other errors |
Source code in flow_sdk/gateway_client.py
list_provider_models(provider_name, scope='organization')
async
¶
List models available from a specific provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_name
|
str
|
Provider identifier (e.g., "openai", "anthropic") |
required |
scope
|
str
|
Scope for model listing (default: "organization") |
'organization'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with provider, models list, and total count |
Raises:
| Type | Description |
|---|---|
GatewayAuthError
|
If authentication fails |
GatewayModelNotFoundError
|
If provider not found |
GatewayClientError
|
For other errors |
Source code in flow_sdk/gateway_client.py
list_known_providers()
async
¶
List all known LLM providers.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of provider name strings |
Raises:
| Type | Description |
|---|---|
GatewayAuthError
|
If authentication fails |
GatewayClientError
|
For other errors |