I'm able to search file names and file contents using bitbucket's api, though not just file names but that's another issue.
What I can't figure out now is how to search in a specific commit/branch/tag.
Can't find how to do it using the documentation.
What I do see is that when searching for a file that isn't in master but is in one of the tags, the api can't find it :(
Search result before the deletion:
$ curl -u "username:password" "https://api.bitbucket.org/2.0/users/alik-takipi/search/code?search_query=bitbucket-search-test"
{"query_substituted": false, "pagelen": 10, "values": [{"content_matches": [], "path_matches": [{"text": "alik.test.agent/"}, {"text": "bitbucket-search-test", "match": true}, {"text": ".txt"}], "type": "code_search_result", "file": {"path": "alik.test.agent/bitbucket-search-test.txt", "type": "commit_file", "links": {"self": {"href": "https://api.bitbucket.org/2.0/repositories/alik-takipi/public-misc/src/3ce5f354e99c76bab9e73f6119d3fe1970cf8a34/alik.test.agent/bitbucket-search-test.txt"}}}, "content_match_count": 0}], "page": 1, "size": 1}
search result after the deletion:
$ curl -u "username:password" "https://api.bitbucket.org/2.0/users/alik-takipi/search/code?search_query=bitbucket-search-test"
{"query_substituted": false, "pagelen": 10, "values": [], "page": 1, "size": 0}
The file can be found in this tag.