<!-- Generated by scripts/generate-llms.mjs from docs/tasks/call-internal-api-from-ai-tools.md. Do not edit. -->

Source: https://qbash.com/docs/tasks/call-internal-api-from-ai-tools

# Call your internal API from ChatGPT, Claude and Cursor

To call your internal API from an AI tool without handing it the key, put the API call in a qbash Task and store the key as a Secret. A Task is an AI cloud function written in Python that qbash hosts on secure cloud infrastructure. You add the qbash MCP server to ChatGPT, Claude, Cursor or Codex once, and each of them can then run the Task. The Task's Python only holds a reference to the key, so the key is never in a chat, in a client's config file or in the model's context.

## Prerequisites

- A qbash account. The free plan has 100 runs a month and 3 Tasks, with no card.
- An API that qbash can reach at a public `https` address. See [Limits](https://qbash.com/docs-markdown/tasks/call-internal-api-from-ai-tools.md#limits) if yours is only reachable inside a private network.
- A key or token for that API. The example uses a bearer token. Basic auth, a custom header and a query parameter are also supported.
- An AI tool that supports remote MCP servers, such as ChatGPT, Claude, Cursor or Codex.

## 1. Store the key as a Secret

Open **Secrets** in the qbash sidebar and click **New secret**. Name it `ADMIN_API_TOKEN`, paste the token into **Value** and click **Create**. Secret names start with a letter and use uppercase letters, numbers and underscores. qbash gives the Secret a slug, which is how Task code refers to it: the name in lowercase with dashes plus the first 4 characters of its ID, such as `admin-api-token-3f9a`. Copy yours from the Secrets page, because it ends in different characters.

Do this step in qbash yourself, so that the token never passes through a chat. qbash encrypts the value, and nobody can view it again from the Secrets page, including you. You can replace it later when you rotate the token. [Using Secrets](https://qbash.com/docs-markdown/tasks/using-secrets.md) covers sharing and rotation.

## 2. Add the qbash MCP server to your AI tool

The [official qbash MCP server](https://qbash.com/docs-markdown/mcp-servers/official-mcp-server.md) is at `https://mcp.qbash.com/mcp`. Every client signs in with your qbash account over OAuth, so there is no qbash key to paste into the client either.

- **ChatGPT.** Turn on Developer mode under **Settings → Apps & Connectors → Advanced settings**. Then create a connector under **Settings → Connectors** with the URL above and OAuth authentication. On a Business, Enterprise or Edu workspace, an owner or admin adds it first.
- **Claude.** Go to **Customize → Connectors**, click **+ Add**, choose **Add custom connector** and paste the URL. On a Team or Enterprise plan, an Owner adds it under **Organization settings → Connectors** first.
- **Cursor.** Add the server to `~/.cursor/mcp.json` as `{"mcpServers": {"qbash": {"url": "https://mcp.qbash.com/mcp"}}}`, reload Cursor and sign in when it asks.
- **Codex.** Run `codex mcp add qbash --url https://mcp.qbash.com/mcp`, then `codex mcp login qbash`.

The card has the full steps for each client, with install links where the client supports them.

### ChatGPT

1. In ChatGPT, open Plugins in the left sidebar, click "Add", and choose "Add custom MCP server".
2. Enter a name, paste `https://mcp.qbash.com/mcp` as the server URL, choose OAuth, and click "Create as a plugin".
3. Install the plugin from the Personal tab and complete the qbash sign-in.
4. In a new chat, type @ and pick the plugin by its name.

Any personal plan can add one, including Free. In a Business, Enterprise or Edu workspace, if the option isn't there, talk to your workspace owner.

[Full guide for ChatGPT](https://qbash.com/docs-markdown/clients/chatgpt.md)

### claude.ai

1. In Claude, go to Customize > Connectors, click "+ Add", and choose "Add custom connector". On a Team or Enterprise plan, an Owner adds it for everyone under Organization settings > Connectors, and members then connect it.
2. Enter a name, paste `https://mcp.qbash.com/mcp` as the URL, and click "Continue".
3. Complete the qbash sign-in to authorize access.
4. In a chat, click the "+" button, choose "Connectors", and toggle the server on for that conversation.

Custom connectors are available on Free (one connector), Pro, Max, Ultra, Team and Enterprise plans.

[Full guide for Claude](https://qbash.com/docs-markdown/clients/claude.md)

### Claude Code

```sh
claude mcp add --transport http qbash https://mcp.qbash.com/mcp
```

Run this in your terminal, then inside Claude Code run /mcp, select the server, and complete the browser sign-in.

[Full guide for Claude Code](https://qbash.com/docs-markdown/clients/claude-code.md)

### Cursor

In `~/.cursor/mcp.json`:

```json
{
  "mcpServers": {
    "qbash": {
      "url": "https://mcp.qbash.com/mcp"
    }
  }
}
```

Reload Cursor, then sign in with qbash when it prompts for authentication.

[Full guide for Cursor](https://qbash.com/docs-markdown/clients/cursor.md)

### VS Code

In `.vscode/mcp.json`:

```json
{
  "servers": {
    "qbash": {
      "type": "http",
      "url": "https://mcp.qbash.com/mcp"
    }
  }
}
```

Start the server from the editor, then follow the browser sign-in prompt.

[Full guide for VS Code](https://qbash.com/docs-markdown/clients/vscode.md)

### Codex

```sh
codex mcp add qbash --url https://mcp.qbash.com/mcp
```

Run this in your terminal, then run codex mcp login qbash and complete the qbash sign-in. The Codex CLI and IDE extension share this setup. For Codex in the ChatGPT app, add qbash as a ChatGPT plugin, the same as for ChatGPT.

In `~/.codex/config.toml`:

```json
[mcp_servers.qbash]
url = "https://mcp.qbash.com/mcp"
```

Save the file, then run codex mcp login qbash and complete the qbash sign-in.

[Full guide for Codex](https://qbash.com/docs-markdown/clients/codex.md)

### Grok Bot

1. Open a Grok Bot chat.
2. Ask: “Add this MCP server: `https://mcp.qbash.com/mcp`”
3. Confirm the details and complete the qbash authorization flow presented by the Bot.

[Full guide for Grok Bot](https://qbash.com/docs-markdown/clients/grok-bot.md)

### dots

1. Open the dot and ask: “Add this MCP server: `https://mcp.qbash.com/mcp`”
2. Complete the qbash sign-in when the dot asks.
3. In a message inside the dot, type @ and pick the plugin by its name.

Dots have the same plan and role limits as ChatGPT. A qbash plugin you already installed in ChatGPT works in the dot too.

[Full guide for dots](https://qbash.com/docs-markdown/clients/chatgpt-dots.md)

### Muse

1. Open a Muse chat.
2. Ask: “Add this MCP server: `https://mcp.qbash.com/mcp`”
3. Allow Muse to contact the server, choose "Connect" on the qbash card, and complete the qbash sign-in.

[Full guide for Muse](https://qbash.com/docs-markdown/clients/muse.md)

### Other

1. Add a remote MCP server in your client. If it asks for a transport, choose Streamable HTTP.
2. Paste the server URL: `https://mcp.qbash.com/mcp`
3. Choose OAuth when the client asks how to authenticate, then complete the qbash sign-in.

[Full guide for other MCP clients](https://qbash.com/docs-markdown/clients/other.md)

## 3. Ask your AI tool to build the Task

With the server connected, your AI tool can use the qbash task builder. Paste this prompt and change the endpoints to match your API:

```text
Use qbash to build a Task called "Customer lookup".

Inputs: email (required), note (optional).

Steps:
1. GET https://admin.example.com/api/customers?email=<email>.
   Send the qbash Secret admin-api-token-3f9a as a bearer token.
2. If the API returns 404, output {"email": <email>, "found": false}.
3. If it returns any other status of 400 or above, fail the run with the status code.
4. Otherwise output the customer's id, plan and status.
5. If note was given, POST {"text": <note>} to
   https://admin.example.com/api/customers/<id>/notes with the same bearer
   token, and add the new note's id to the output.

Read the token with qbash.secrets["admin-api-token-3f9a"] and pass it to
qbash.http.auth.bearer. Never ask me for the token's value.

Description for the Task: "Looks up a customer in the admin API by email and
optionally adds a note. Returns the plan and status."
```

The builder writes the Task in Python and saves it. Every save is a version that you can go back to. The description is what an assistant reads when it decides whether to call the Task, so say when to use it and what it returns.

Open the Task in qbash before the first run and check that `ADMIN_API_TOKEN` is listed under **Secrets** in the Package. A Secret has to be attached to a Task before the Task can use it. If it's missing, choose **Add secret** from the Package **+** menu, attach it and save.

## The complete Task

This is the Task that the prompt above describes. You can also paste it into `main.py` in the [task editor](https://qbash.com/docs-markdown/tasks/task-editor.md) and add `email` and `note` as inputs.

```python title="main.py"
BASE_URL = "https://admin.example.com/api"

# A reference to the Secret. qbash fills in the stored token when it sends the request.
auth = qbash.http.auth.bearer(qbash.secrets["admin-api-token-3f9a"])

email = (qbash.inputs.get("email") or "").strip()
note = (qbash.inputs.get("note") or "").strip()

if not email:
    raise ValueError("The email input is required")

def as_json(body):
    return json.loads(body) if isinstance(body, str) else body

# GET: look the customer up by email.
lookup = qbash.http.request(
    "GET",
    f"{BASE_URL}/customers?email={urllib.parse.quote(email)}",
    auth=auth,
    timeout=10000,
)

if lookup["status"] == 404:
    qbash.output({"email": email, "found": False})
elif lookup["status"] >= 400:
    raise RuntimeError(f"Customer lookup returned HTTP {lookup['status']}")
else:
    customer = as_json(lookup["body"])
    result = {
        "email": email,
        "found": True,
        "id": customer["id"],
        "plan": customer["plan"],
        "status": customer["status"],
    }

    # POST: add a note to the customer, only when the caller sent one.
    if note:
        created = qbash.http.request(
            "POST",
            f"{BASE_URL}/customers/{customer['id']}/notes",
            body={"text": note},
            auth=auth,
            timeout=10000,
        )
        if created["status"] >= 400:
            raise RuntimeError(f"Adding the note returned HTTP {created['status']}")
        result["note_id"] = as_json(created["body"])["id"]

    qbash.output(result)
```

A few things about this code:

- **There are no `import` lines.** Tasks don't allow them. The `qbash` SDK and common standard library modules such as `json` and `urllib.parse` are already loaded.
- **HTTP goes through `qbash.http.request`.** It returns a dictionary with `status`, `headers` and `body`. An error status doesn't raise on its own, so the Task checks `status` and raises. A raised error fails the run.
- **`timeout` is in milliseconds.** The default is 30,000.
- **A dictionary passed as `body` is sent as JSON.**
- **`qbash.secrets["admin-api-token-3f9a"]` returns a reference, and the stored value never enters the Python runtime.** Pass the reference through unchanged. If you slice it, hash it or encode it, qbash can't resolve it. For other auth schemes, use `qbash.http.auth.basic`, `qbash.http.auth.header` or `qbash.http.auth.query`. The [SDK reference](https://qbash.com/docs-markdown/tasks/sdk-reference.md) lists them.

## 4. Call it from ChatGPT, Claude, Cursor and Codex

Ask in plain words in any client that has the qbash server connected:

```text
Look up jo@example.com in the admin API with the Customer lookup Task.
```

The assistant finds the Task, sends `email` as the input and gets back what the Task passed to `qbash.output`. The same Task answers from every client, so there is one copy of the logic to maintain. The assistant only sees the Task's name, description, inputs and result. The token and the Python stay in qbash.

A Task is not tied to MCP. It can also run on a [schedule, from an API call or from a webhook](https://qbash.com/docs-markdown/tasks/distribution.md).

## How teammates use it without seeing the key

qbash also lets you build [custom MCP servers](https://qbash.com/docs-markdown/mcp-servers/overview.md). They work as a permission layer for your teammates or agents.

1. Open **MCP Servers → New server**, choose **Add tools** and select the Customer lookup Task.
2. On **Access**, invite specific people with **Can connect**, or select **Organization**.
3. Each teammate adds the server's address to their AI tool and signs in with their own qbash account.

Teammates can call the tool. They can't edit the Task's code, and they never receive the token. Every run uses the Secret that is attached to the Task, so think about what that token allows before you share the tool. The server's **Logs** tab shows who called each tool and when.

## Limits
- **The API needs a public address.** qbash sends each request from its own servers and refuses private and internal addresses such as `10.0.0.5` or `localhost`. A Task can't reach an API that only answers inside your company network.
- **Each HTTP request waits 30 seconds by default.** Set `timeout` to change that. Responses over 50 MB are refused.
- **A run can last up to 15 minutes** on the Free and Developer plans.
- **A long run returns an execution ID first.** Over MCP, a Task call waits about 45 seconds. If the run is still going, the client gets an execution ID and collects the result with a status tool.
- **Plan and role limits on the client side still apply.** On ChatGPT Business, Enterprise and Edu workspaces and on Claude Team and Enterprise plans, an owner or admin has to add a custom MCP server first.

This setup isn't the right fit when the assistant should explore your whole API freely. A Task exposes the calls that you wrote, with the inputs that you defined. That is usually the point with an internal API, but it means each new operation is a change to the Task or a new Task.

## FAQ

### How do I let ChatGPT or Claude call my private API without exposing the API key?

Store the key as a qbash Secret and make the API call from a Task. The assistant calls the Task over MCP and gets the result. The key is filled in by qbash when the request is sent, so it is never in the conversation or in the client's configuration.

### Can the model read the key?

The Task's Python only holds a reference to the key, and qbash resolves the reference when it sends the HTTP request. The value never enters the Python runtime or the conversation. The value can't be viewed on the Secrets page after it's saved. The API that receives the key can still do whatever that key allows, so only send a Secret to a service you trust with it.

### Do I have to run or host an MCP server?

qbash hosts it. You connect your AI tool to the official server at `https://mcp.qbash.com/mcp`, or to a custom server that you create in qbash for your team.

### Can I use the same Task in ChatGPT, Claude and Cursor?

One Task serves every client that is connected to qbash. You connect each client once, and a change to the Task applies to all of them.

### My API uses an API key header instead of a bearer token. Does that work?

Use `qbash.http.auth.header("X-Api-Key", qbash.secrets["admin-api-token-3f9a"])` as the `auth` argument. Basic auth and query-parameter keys have their own helpers.

### Can it reach an API behind our firewall or VPN?

A Task can only call a public address. If the API is private, you need a public entry point for it, such as an API gateway that checks the key.

### How do I rotate the key?

Open the Secret, choose **⋯ → Edit**, replace the value and save. Tasks that use the Secret send the new value on their next request, with no code change.

## Next steps

- [Expose your internal API to your AI tools](https://qbash.com/start/internal-api) shows the same pattern with an inline prompt added.
- [Official MCP server](https://qbash.com/docs-markdown/mcp-servers/official-mcp-server.md) lists every tool your AI client gets, including the task builder.
- [MCP servers](https://qbash.com/docs-markdown/mcp-servers/overview.md) covers custom servers, access and logs.
- [Using Secrets](https://qbash.com/docs-markdown/tasks/using-secrets.md) covers attaching, sharing and rotating Secrets.
- [Moving a GPT Action before December 11](https://qbash.com/blog/gpts-retirement-actions) covers the custom GPT retirement.
