# Python over HTTP

A complete example using Python's standard library, with no separate SDK.

Source: https://shvydko.ai/en/docs/integrations/python

## Prepare the input

Save request.json from the first-request page. Supply SHVYDKO_BASE_URL and SHVYDKO_API_KEY through the server process environment. The example uses json, os, and urllib.request from the standard library.

- [Copy request.json](https://shvydko.ai/en/docs/quickstart#request)

## Request, status, and response

This example deliberately does not retry POST automatically. Add your own bounded retry mechanism after considering the HTTP status and risk of duplicate processing.

### request.py · Python 3

```python
import json
import os
import urllib.error
import urllib.request

base_url = os.environ["SHVYDKO_BASE_URL"].rstrip("/")
api_key = os.environ["SHVYDKO_API_KEY"]
with open("request.json", encoding="utf-8") as source:
    payload = json.load(source)

request = urllib.request.Request(
    base_url + "/v1/systemone",
    data=json.dumps(payload, ensure_ascii=False).encode("utf-8"),
    headers={
        "Authorization": "Bearer " + api_key,
        "Content-Type": "application/json",
        "User-Agent": "ShvydkoClient/1.0",
    },
    method="POST",
)

try:
    with urllib.request.urlopen(request, timeout=150) as response:
        result = json.load(response)
except urllib.error.HTTPError as error:
    # Do not log the API key or the original customer context.
    try:
        detail = json.loads(error.read()).get("detail", "Request failed")
    except (ValueError, AttributeError):
        detail = "Non-JSON error response"
    retry_after = error.headers.get("Retry-After")
    raise SystemExit(
        f"Shvydko HTTP {error.code}: {detail}; Retry-After={retry_after}"
    )
except (urllib.error.URLError, TimeoutError) as error:
    raise SystemExit(
        "Network failure; check Usage before repeating a paid request"
    ) from error

print("request_id:", result["request_id"])
print("team:", result["answers"]["team"]["choice"])
print("input_tokens:", result["usage"]["input_tokens"])
print("cost_usd:", result["usage"]["cost_usd"])
```

## Connecting to your application

- Keep the secret in the server environment, separately for each development environment.
- Pass only validated fields and allowed categories to business logic.
- Limit concurrency according to the organization's quota.
- Associate request_id with your task ID without logging secrets.

> This is a direct Shvydko HTTP client. It does not claim a separate official Python SDK or compatibility with all third-party SDKs.

## Related documentation

- [First request](https://shvydko.ai/en/docs-markdown/quickstart.md)
- [POST /v1/systemone](https://shvydko.ai/en/docs-markdown/api/systemone.md)
- [Errors and retries](https://shvydko.ai/en/docs-markdown/api/errors.md)
