adk_model_http_client (erlang_adk v0.8.0)

View Source

Provider-neutral construction of bounded JSON model requests.

This module owns no credentials and knows no vendor wire schema. It joins a validated base URL with a fixed adapter-owned path, derives the exact scheme/host allow-list, encodes only a checked JSON map, and invokes an injected adk_model_http_transport. Redirects are always disabled.

Summary

Functions

Resolve a direct adapter key or its conventional environment value. Error terms never contain credential material.

Resolve an environment credential only for the adapter's exact official base URL. A custom HTTPS endpoint must carry an explicit key, which keeps caller-controlled origins from receiving ambient credentials.

Resolve only a key present in this request configuration. This is the credential boundary for OpenAI-compatible endpoints, which have no single official origin to which a process-wide environment key could be bound.

Require HTTPS for a credential-bearing model adapter. The generic transport still supports HTTP for explicitly keyless local integrations; native vendor adapters call this stricter boundary before resolving keys.

Functions

base_url_matches(Config, Expected)

-spec base_url_matches(map(), binary()) -> boolean().

request(Config, Path, Headers, Payload)

-spec request(map(), binary(), [{binary(), binary()}], map()) ->
                 {ok, adk_model_http_transport:response()} | {error, term()}.

resolve_api_key(Config, EnvName)

-spec resolve_api_key(map(), string()) -> {ok, binary()} | {error, missing_api_key | invalid_api_key}.

Resolve a direct adapter key or its conventional environment value. Error terms never contain credential material.

resolve_bound_api_key(Config, EnvName, OfficialBase)

-spec resolve_bound_api_key(map(), string(), binary()) ->
                               {ok, binary()} |
                               {error,
                                missing_api_key | invalid_api_key |
                                custom_endpoint_requires_explicit_api_key}.

Resolve an environment credential only for the adapter's exact official base URL. A custom HTTPS endpoint must carry an explicit key, which keeps caller-controlled origins from receiving ambient credentials.

resolve_explicit_api_key(Config)

-spec resolve_explicit_api_key(map()) -> {ok, binary()} | {error, missing_api_key | invalid_api_key}.

Resolve only a key present in this request configuration. This is the credential boundary for OpenAI-compatible endpoints, which have no single official origin to which a process-wide environment key could be bound.

stream(Config, Path, Headers, Payload, Callback)

-spec stream(map(), binary(), [{binary(), binary()}], map(), adk_model_http_transport:chunk_callback()) ->
                {ok, adk_model_http_transport:response()} | {error, term()}.

validate_https_base_url(Config)

-spec validate_https_base_url(map()) ->
                                 ok | {error, invalid_model_https_base_url | invalid_model_base_url}.

Require HTTPS for a credential-bearing model adapter. The generic transport still supports HTTP for explicitly keyless local integrations; native vendor adapters call this stricter boundary before resolving keys.

validate_options(Config)

-spec validate_options(map()) -> ok | {error, term()}.