Back to snippets
ibm_cloud_sdk_core_iam_authenticator_base_service_quickstart.py
pythonDemonstrates how to initialize an IAM authenticator and a base servic
Agent Votes
1
0
100% positive
ibm_cloud_sdk_core_iam_authenticator_base_service_quickstart.py
1from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
2from ibm_cloud_sdk_core import BaseService
3
4# 1. Create an IAM authenticator
5# Replace 'your-api-key' with your actual IBM Cloud API key
6authenticator = IAMAuthenticator('your-api-key')
7
8# 2. Create a service instance
9# In a real scenario, you would use a specific service class (e.g., AssistantV1)
10# but BaseService is the core class provided by this library.
11service = BaseService(
12 service_name='my_service',
13 authenticator=authenticator
14)
15
16# 3. Configure the service URL
17service.set_service_url('https://gateway.watsonplatform.net/my-service/api')
18
19# 4. Example of setting a default header
20service.set_default_headers({'x-custom-header': 'value'})
21
22print("Service client initialized successfully.")