Improve context and api_path handling