Skip to main content

Custom endpoint requests

Use client.custom when you need a low-level authenticated HTTP request but still want the SDK's client configuration. It is deliberately generic. It returns a raw httpx2.Response, and you decide how to validate and parse the payload.

This is useful for custom extension endpoints and for SAS REST API operations where you want direct request control instead of a handwritten SDK wrapper.

What client.custom reuses​

Requests sent through client.custom use the same transport setup as the rest of SVIClient:

  • bearer-token authentication from the configured token provider
  • SDK default headers and user agent
  • timeout, TLS verification, redirects, and HTTPX client arguments
  • retry settings for retryable methods and statuses
  • HTTP logging, redaction, and body-log controls
  • sync and async cleanup through SVIClient.close() / SVIClient.close_async()

client.custom adds no generated models, no service-specific parsing, no endpoint discovery and no operation-specific exceptions. Treat it as authenticated httpx2 with the SDK's transport defaults.

Basic usage​

import sasvi

client = sasvi.SVIClient(
base_url="https://viya.example.com",
auth=auth,
)

response = client.custom.get("/extension/ping")
response.raise_for_status()

payload = response.json()

The convenience methods are:

client.custom.get(path, **kwargs)
client.custom.post(path, **kwargs)
client.custom.put(path, **kwargs)
client.custom.patch(path, **kwargs)
client.custom.delete(path, **kwargs)

The generic form is:

response = client.custom.request(
"POST",
"/extension/items",
json={"name": "Example"},
)

All request keyword arguments are passed to HTTPX after the SDK applies URL resolution, authentication, default headers, retry behavior, and logging.

A Host header must name the request URL's host. Any other value raises AuthConfigurationError, and nothing is sent.

URL resolution​

Relative paths are resolved against SVIConfig.base_url:

client = sasvi.SVIClient(base_url="viya.example.com", auth=auth)

# Sends GET https://viya.example.com/extension/ping
response = client.custom.get("/extension/ping")

Bare host names are normalized to HTTPS when used as base_url values. For authenticated clients, the resolved URL must stay on the same origin as SVIConfig.base_url unless you opt in to sending SDK authentication elsewhere:

# Sends GET https://viya.example.com/custom-root/items
response = client.custom.get(
"items",
base_url="viya.example.com/custom-root",
)

Same-origin absolute request URLs are allowed:

response = client.custom.get("https://viya.example.com/extension/ping")

Off-origin calls require allow_external_auth=True:

response = client.custom.get(
"https://custom.example.com/extension/ping",
allow_external_auth=True,
)

The lock is on the target, not on whether the SDK spots a credential on the request. Any origin other than the configured base_url needs the flag, including a request that carries no authentication at all. Earlier releases refused only a request whose credential the SDK recognised by header name, so a bespoke secret header, a cookie jar set through sync_httpx_args, or a token in a query parameter all sailed past it.

Use the flag when you mean to reach that origin, and know that it also permits the SDK's configured authentication to travel there. If the target is an off-loopback http:// URL and the request carries credentials, the SDK logs a WARNING rather than blocking.

Absolute URLs now get the same scheme and user-info checks as base_url: a scheme other than https/http, and a URL of the form https://user:pass@host, each raise ValueError.

client.custom ignores service_urls overrides, which only apply to the generated service clients. To call a service path through client.custom, put the service root in the path yourself.

Example: SAS Visual Investigator getConfiguration​

The SAS REST API reference page for this operation is SASVisualInvestigator/getConfiguration. Use that page as the source of truth for the method, path, accepted media types, and response shape for your target Viya release.

In SDK terms, the SAND service root is /svi-sand, and the configuration operation path is /admin/config. A root-relative custom request therefore uses /svi-sand/admin/config:

response = client.custom.get(
"/svi-sand/admin/config",
headers={"Accept": "application/json"},
)
response.raise_for_status()

configuration = response.json()

This same endpoint is also available through the generated API layer:

configuration_model = client.api.sand.export_configuration()

The SAS reference page names the operation getConfiguration. The generated Python method name can differ, because it comes from the service's OpenAPI metadata.

Prefer the generated or handwritten SDK surface when it already does what you need. Reach for client.custom when you need direct control over the request, when you are following a SAS REST API reference page by hand, or when the endpoint is an extension the SDK cannot model.

Translating a SAS REST API page​

When you use a SAS REST API reference page with client.custom, map the page into the request like this:

  1. Copy the HTTP method into get, post, patch, put, delete, or request(...).
  2. Copy the path, including the service root such as /svi-sand, /svi-datahub, or /files.
  3. Copy required query parameters into params={...}.
  4. Copy required request headers into headers={...}.
  5. Copy JSON request bodies into json={...}.
  6. Call response.raise_for_status() if HTTP errors should raise immediately.
  7. Parse with response.json(), response.text, response.content, or a custom parser.

Example with query parameters:

response = client.custom.get(
"/extension/items",
params={"start": 0, "limit": 25},
headers={"Accept": "application/json"},
)
response.raise_for_status()

items = response.json()

Example with a JSON body:

response = client.custom.post(
"/extension/items",
headers={"Accept": "application/json"},
json={
"name": "Notebook-created item",
"category": "example",
},
)
response.raise_for_status()

created_item = response.json()

Example with raw bytes:

response = client.custom.post(
"/extension/blob",
headers={"Content-Type": "application/octet-stream"},
content=b"raw payload",
)
response.raise_for_status()

Example: cascading reference data​

The typed client.admin.reference_lists helpers cover normal reference lists. Visual Investigator cascading reference-data hierarchies are different. They are served by /svi-datahub/admin/cascadingData, which the generated public Data Hub API surface behind the typed configuration domain does not expose.

If your deployment needs a low-level cascading-data operation, keep it explicit and local to your project code through client.custom. The request returns a raw httpx2.Response, so your code owns the payload shape, validation, parsing and compatibility checks for your Viya release.

Read an existing hierarchy:

response = client.custom.get("/svi-datahub/admin/cascadingData/investigation_result")
response.raise_for_status()

hierarchy = response.json()

Create a disposable hierarchy:

payload = {
"name": "sdk_example_cascading_20260521090000",
"label": "SDK Example Cascading Data",
"localizedLabels": [{"localeCd": "en-US", "label": "SDK Example Cascading Data"}],
"levels": [
{
"name": "status",
"label": "Status",
"maxCodeLength": 32,
"alphabeticalSort": False,
"hierarchyLevel": 0,
"referenceListType": "LEVEL",
"localizedLabels": [{"localeCd": "en-US", "label": "Status"}],
"items": [
{
"code": "OPEN",
"label": "Open",
"archived": False,
"displayIndex": 0,
"localizedLabels": [{"localeCd": "en-US", "label": "Open"}],
}
],
},
{
"name": "reason",
"label": "Reason",
"maxCodeLength": 32,
"alphabeticalSort": False,
"hierarchyLevel": 1,
"referenceListType": "LEVEL",
"localizedLabels": [{"localeCd": "en-US", "label": "Reason"}],
"items": [
{
"code": "REVIEW",
"label": "Needs Review",
"archived": False,
"displayIndex": 0,
"parentCode": "OPEN",
"localizedLabels": [{"localeCd": "en-US", "label": "Needs Review"}],
}
],
},
],
}

response = client.custom.post("/svi-datahub/admin/cascadingData", json=payload)
response.raise_for_status()

Update by sending the full hierarchy payload back to the hierarchy name:

hierarchy["levels"][0]["items"][0]["label"] = "Open Case"

response = client.custom.put(
f"/svi-datahub/admin/cascadingData/{hierarchy['name']}",
json=hierarchy,
)
response.raise_for_status()

The companion notebook creates, reads, updates and deletes a hierarchy with a disposable name:

Response handling​

client.custom returns httpx2.Response directly:

response = client.custom.get("/svi-sand/admin/config")

if response.status_code == 404:
configuration = None
else:
response.raise_for_status()
configuration = response.json()

That means:

  • The SDK does not convert response bodies into generated models.
  • No status raises on its own, documented or not. Every response comes back for you to inspect.
  • A request that never completed raises a typed sasvi.errors failure rather than a raw httpx2 exception: ServiceUnreachableError, NetworkError, TLSError or DeadlineExceededError.
  • Redirects, TLS, timeout and retry behavior still follow the SVIClient configuration.
  • Endpoint-specific error handling belongs in your calling code.

Retries for writes​

Custom requests use the same retry loop as the rest of the SDK. GET, HEAD and OPTIONS are resent on any retryable failure. POST and PATCH are never resent. PUT and DELETE are resent unless the request is guarded.

FailureUnguarded PUT or DELETEGuarded request
Never left: connect error, pool timeout, token fetch failedresentresent
Refused: HTTP 408 or 429resentresent
Uncertain: read, write or protocol errorresentNetworkError(outcome_unknown=True), 1 attempt
HTTP 5xxresentthe 5xx response comes back

A PUT or DELETE that carries If-Match, If-Unmodified-Since or If-None-Match is guarded on its own. To guard any other request, such as a PUT to an endpoint that is not idempotent, set the sasvi_no_retry extension:

response = client.custom.put(
"/extension/counters/increment",
json={"by": 1},
extensions={"sasvi_no_retry": True},
)

outcome_unknown=True on the error means the server may have applied the request. Read the resource before you send it again. A retried DELETE that comes back 404 after an uncertain first attempt carries response.extensions["sasvi_prior_attempt_outcome_unknown"], because the first attempt may have done the delete.

For a support ticket or notebook diagnostics, log the status and a small part of the response body:

try:
response.raise_for_status()
except Exception:
print(response.status_code)
print(response.text[:1000])
raise

Async requests​

Async custom requests use the same URL resolution and transport configuration:

async with sasvi.SVIClient(
base_url="https://viya.example.com",
auth=auth,
) as client:
response = await client.custom.get_async("/svi-sand/admin/config")
response.raise_for_status()
configuration = response.json()

The async convenience methods are:

await client.custom.get_async(path, **kwargs)
await client.custom.post_async(path, **kwargs)
await client.custom.put_async(path, **kwargs)
await client.custom.patch_async(path, **kwargs)
await client.custom.delete_async(path, **kwargs)
await client.custom.request_async(method, path, **kwargs)

Logging custom requests​

Custom endpoint requests participate in the SDK HTTP logging system:

import logging
import sasvi

logging.basicConfig(level=logging.INFO)
sasvi.configure_logging("DEBUG")

client = sasvi.SVIClient(
base_url="https://viya.example.com",
auth=auth,
log_http=True,
)

With log_http=True, the SDK logs method, sanitized URL, status, duration, retry information, and selected correlation headers. Request and response bodies are not logged unless explicitly enabled:

client = sasvi.SVIClient(
base_url="https://viya.example.com",
auth=auth,
log_level="DEBUG",
log_http=True,
log_http_response_body=True,
log_http_body_limit=4096,
)

Turn body logging on deliberately. The SDK redacts sensitive headers and query parameters, redacts known secret keys in JSON and form request bodies, truncates body output and skips binary or streaming bodies. Your application data can still be sensitive.

See Logging and diagnostics for the full logging contract.

Practical checklist​

  • Use a handwritten SDK method first when one exists.
  • Use client.api.<service> when a generated operation already matches the endpoint.
  • Use client.custom when you need direct authenticated HTTP control.
  • Include the service root in relative paths, such as /svi-sand/admin/config.
  • Set Accept and Content-Type headers from the endpoint's API reference.
  • Treat returned values as httpx2.Response, not SDK wrapper objects.
  • Keep endpoint-specific validation and parsing close to the call site.