# Can an AI agent choose which API to call?

Yes. How to let your agent pick a provider for each job at runtime instead of hardcoding one, and how to keep that choice honest.

Yes. An agent can choose its API at runtime if it has two things: a list of the tools that can do the job, and a fair way to rank them. Hardcoding one provider is simpler, but it locks in that provider's accuracy, price and outages.

## What a good choice needs

- **Coverage.** The tools that can do this job, in this region.
- **A score from tests, not marketing.** The same cases run against every tool.
- **Price per useful result.** A cheap call that returns nothing isn't cheap.
- **A check on the answer.** So a wrong result is caught and not paid for.

## Hardcoded or chosen at runtime

Hardcoded provider compared with choosing at runtime

|  | Hardcoded provider | Chosen at runtime |
|---|---|---|
| Switching provider | A code change and a deploy | Follows the ranking |
| When the provider fails | Your agent fails or retries | It can try the next-ranked tool |
| Accuracy | Whatever that provider gives | The best score for the job and region |

## How to do it with Arettic

### 1. Ask for the job

**curl**

```bash
curl https://api.arettic.com/v1/recommend \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{ "task": "find the email and job title of the CTO at acme.com" }'
```

The answer lists the tools ranked by score, then price, each with its price per passing result and the check it must pass.

### 2. Run the top tool

**curl**

```bash
curl https://api.arettic.com/v1/execute \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "tool_id": "hunter-verify-email",
    "input": { "email": "jane@acme.com" },
    "fallback": true,
    "max_price": 50
  }'
```

With `fallback: true`, if an item fails, the next-ranked tool runs once within your `max_price`. Only the tool that passes is charged.

## Keep the ranking honest

A ranking only helps if nobody can buy their way up. On Arettic, paying never changes a score, rank or routing decision, and the score formula is public on [How scores work](/docs/scores). More on [provider discovery](/discovery).

## Questions

### Is choosing at runtime slower?

It adds one call. `recommend` is free, and your agent can reuse its answer for the same job and region.

### Can I force a provider?

Yes. Send any purchasable `tool_id` to `execute`. On Pro and up, owners can pin a tool so it's tried first.

Updated 2026-10-23. This page as HTML: https://arettic.com/guides/let-agent-choose-api-provider · Markdown: https://arettic.com/guides/let-agent-choose-api-provider.md · JSON: https://arettic.com/guides/let-agent-choose-api-provider.json
