fern/snippets/openapi-howto-rely-on-envvars.mdx
import (
"os"
baml "my-golang-app/baml_client"
)
func main() {
cfg := baml.NewConfiguration()
if boundaryEndpoint := os.Getenv("BOUNDARY_ENDPOINT"); boundaryEndpoint != "" {
cfg.BasePath = boundaryEndpoint
}
if boundaryApiKey := os.Getenv("BOUNDARY_API_KEY"); boundaryApiKey != "" {
cfg.DefaultHeader["Authorization"] = "Bearer " + boundaryApiKey
}
b := baml.NewAPIClient(cfg).DefaultAPI
// Use `b` to make API calls
}
public class ApiExample { public static void main(String[] args) { ApiClient apiClient = Configuration.getDefaultApiClient();
String boundaryEndpoint = System.getenv("BOUNDARY_ENDPOINT");
if (boundaryEndpoint != null && !boundaryEndpoint.isEmpty()) {
apiClient.setBasePath(boundaryEndpoint);
}
String boundaryApiKey = System.getenv("BOUNDARY_API_KEY");
if (boundaryApiKey != null && !boundaryApiKey.isEmpty()) {
apiClient.addDefaultHeader("Authorization", "Bearer " + boundaryApiKey);
}
DefaultApi apiInstance = new DefaultApi(apiClient);
// Use `apiInstance` to make API calls
}
}
</Tab>
<Tab title="PHP" language="php">
```php
require_once(__DIR__ . '/vendor/autoload.php');
$config = BamlClient\Configuration::getDefaultConfiguration();
$boundaryEndpoint = getenv('BOUNDARY_ENDPOINT');
$boundaryApiKey = getenv('BOUNDARY_API_KEY');
if ($boundaryEndpoint) {
$config->setHost($boundaryEndpoint);
}
if ($boundaryApiKey) {
$config->setAccessToken($boundaryApiKey);
}
$apiInstance = new OpenAPI\Client\Api\DefaultApi(
new GuzzleHttp\Client(),
$config
);
// Use `$apiInstance` to make API calls
api_client = BamlClient::ApiClient.new
boundary_endpoint = ENV['BOUNDARY_ENDPOINT'] if boundary_endpoint api_client.host = boundary_endpoint end
boundary_api_key = ENV['BOUNDARY_API_KEY'] if boundary_api_key api_client.default_headers['Authorization'] = "Bearer #{boundary_api_key}" end b = BamlClient::DefaultApi.new(api_client)
b to make API calls</Tab>
<Tab title="Rust" language="rust">
```rust
let mut config = baml_client::apis::configuration::Configuration::default();
if let Some(base_path) = std::env::var("BOUNDARY_ENDPOINT").ok() {
config.base_path = base_path;
}
if let Some(api_key) = std::env::var("BOUNDARY_API_KEY").ok() {
config.bearer_access_token = Some(api_key);
}
// Use `config` to make API calls