You can assume an IAM role programmatically using the AWS SDKs or AWS CLI. Here's an example using the AWS CLI:
aws sts assume-role --role-arn arn:aws:iam::123456789012:role/my-role --role-session-name MySession
This command returns temporary security credentials that you can use to make API requests.