> ## Documentation Index
> Fetch the complete documentation index at: https://portkey-docs-add-third-party-integration-issues-fixes.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Get started with Agent Gateway

<Info>
  Modify the API key permissions and turn on the toggle for **Agent Gateway** to enable Agent Gateway for your API key. Create or edit a key on the [API Keys](https://app.portkey.ai/api-keys) page, and enable the `agents.invoke` scope when you will invoke agents with that key. For how Portkey API keys and scopes work, see [API keys, authentication, and authorization](/product/enterprise-offering/org-management/api-keys-authn-and-authz).
</Info>

All you need to get started is an agent server.

For this quickstart, we will be using an [A2A agent](https://a2a-protocol.org/latest/topics/what-is-a2a/#understanding-the-agent-stack-a2a-mcp-agent-frameworks-and-models).

<Steps>
  <Step title="Fetch your server URL">
    Make use of one of the following agent servers and configure it as the
    upstream agent server. This is used to fetch the agent card and authenticate
    requests.

    <Columns cols={2}>
      <Card title="Hello world A2A Agent" icon="handshake">
        <a href="https://hello.a2aregistry.org">
          [https://hello.a2aregistry.org](https://hello.a2aregistry.org)
        </a>
      </Card>

      <Card title="Simple A2A Agent with tools and header based authentication" icon="key">
        <a href="https://a2a-header-auth.ayush-0a3.workers.dev">
          [https://a2a-header-auth.ayush-0a3.workers.dev](https://a2a-header-auth.ayush-0a3.workers.dev)
        </a>

        headers: `Authorization: Bearer secret-key-1`
      </Card>
    </Columns>

    <Card title="Host your own agent" icon="wrench" horizontal>
      You can host your own A2A Agent server following the instructions in the
      [Agent Server
      SDK](https://a2a-protocol.org/latest/tutorials/python/1-introduction/)
      documentation.
    </Card>
  </Step>

  <Step title="Add agent to registry">
    <Steps>
      <Step title="Configure the agent">
        Access the [Agent
        Registry](https://app.portkey.ai/agent-integrations/integrated) and
        configure the agent server URL.

        <Frame>
          <img src="https://mintcdn.com/portkey-docs-add-third-party-integration-issues-fixes/3puCm5_g-yS1XwLy/images/agent-gateway/create-new-integration.png?fit=max&auto=format&n=3puCm5_g-yS1XwLy&q=85&s=286231adc741dfe65856c3d9eddb6cf3" width="2930" height="1554" data-path="images/agent-gateway/create-new-integration.png" />
        </Frame>
      </Step>

      <Step title="Fetch agent card and validate">
        Validate transport and authentication schemes by clicking the `Fetch
                        Agent Card` button. The upstream URL must be a public `http`/`https` endpoint (Backend `v1.16.1+` applies SSRF protections and rejects private IPs, metadata hosts, and URLs with `#` fragments).

        <Frame>
          <img src="https://mintcdn.com/portkey-docs-add-third-party-integration-issues-fixes/3puCm5_g-yS1XwLy/images/agent-gateway/fetch-agent-card.png?fit=max&auto=format&n=3puCm5_g-yS1XwLy&q=85&s=15a917db84179b6db37894646445a2e5" width="2930" height="1554" data-path="images/agent-gateway/fetch-agent-card.png" />
        </Frame>
      </Step>

      <Step title="Provision workspaces">
        <Frame>
          <img src="https://mintcdn.com/portkey-docs-add-third-party-integration-issues-fixes/3puCm5_g-yS1XwLy/images/agent-gateway/provision-workspaces.png?fit=max&auto=format&n=3puCm5_g-yS1XwLy&q=85&s=13fe2bb553b97bbe589a425dade8f17c" width="2930" height="1554" data-path="images/agent-gateway/provision-workspaces.png" />
        </Frame>
      </Step>
    </Steps>
  </Step>

  <Step title="Verify your integration">
    <Steps>
      <Step title="Grab your Portkey API key">
        Head over to the [API Keys](https://app.portkey.ai/api-keys) page and
        create a new API key. Make sure the `agents.invoke` scope is enabled for
        your API key.

        <Frame>
          <img src="https://mintcdn.com/portkey-docs-add-third-party-integration-issues-fixes/3puCm5_g-yS1XwLy/images/agent-gateway/api-key-scopes-for-agent-invoke.png?fit=max&auto=format&n=3puCm5_g-yS1XwLy&q=85&s=3d039bd387f4fb155b128ab253ef0ce2" width="2880" height="1594" data-path="images/agent-gateway/api-key-scopes-for-agent-invoke.png" />
        </Frame>
      </Step>

      <Step title="Fetch the agent server URL from the agents tab">
        Open the [Agents](https://app.portkey.ai/agents) tab and fetch the
        corresponding agent server URL. This is the URL you will use to connect
        your agent to the Portkey Agent Gateway instead of the agent server URL.
        It looks something like this (you can replace the agent slug with your
        server's slug):
        `https://agents.portkey.ai/v1/agent/header-based-authentication`

        <Frame>
          <img src="https://mintcdn.com/portkey-docs-add-third-party-integration-issues-fixes/3puCm5_g-yS1XwLy/images/agent-gateway/agent-server.png?fit=max&auto=format&n=3puCm5_g-yS1XwLy&q=85&s=13e1cf87b39ad1d1fa56c1c8db45ce3c" width="2880" height="1594" data-path="images/agent-gateway/agent-server.png" />
        </Frame>
      </Step>
    </Steps>
  </Step>
</Steps>

## Interface with your agent

You can simply replace your agent server URL with the one you fetched
from the agents tab and test out the integration.

Alternatively, make use of one of the code snippets below!

<CodeGroup>
  ```shell cURL theme={null}
  curl --location --request POST 'https://agents.portkey.ai/v1/agent/{agent-slug}/.well-known/agent.json' \
  --header 'Content-Type: application/json' \
  --header 'x-portkey-api-key: {PORTKEY_API_KEY}'
  ```

  ```python python theme={null}
  import asyncio
  import json

  from a2a.client import A2ACardResolver
  import httpx

  BASE_URL = "https://agents.portkey.ai/v1/agent/{agent-slug}"
  API_KEY = "{PORTKEY_API_KEY}"


  async def log_httpx_request(request: httpx.Request) -> None:
      try:
          body = request.content.decode("utf-8") if request.content else "<empty>"
      except Exception:
          body = "<streaming or unreadable body>"
      print(f"[httpx] {request.method} {request.url}")
      print(f"[httpx] body: {body}\n")


  async def main() -> None:
      print(f"Fetching agent card from {BASE_URL}...")
      async with httpx.AsyncClient(
          base_url=BASE_URL,
          headers={"x-portkey-api-key": API_KEY},
          event_hooks={"request": [log_httpx_request]},
      ) as client:
          resolver = A2ACardResolver(httpx_client=client, base_url=BASE_URL)
          agent_card = await resolver.get_agent_card()
          print(json.dumps(agent_card.model_dump(mode="json", exclude_none=True), indent=2))


  if __name__ == "__main__":
      asyncio.run(main())
  ```

  ```javascript JavaScript theme={null}
  import {
    DefaultAgentCardResolver,
    ClientFactory,
    ClientFactoryOptions,
  } from "@a2a-js/sdk/client";

  const BASE_URL = "https://agents.portkey.ai/v1/agent/{agent-slug}";
  const API_KEY = "{PORTKEY_API_KEY}";

  class HeaderAuthInterceptor {
    async before(args) {
      args.options = {
        ...args.options,
        serviceParameters: {
          ...(args.options?.serviceParameters || {}),
          "x-portkey-api-key": API_KEY,
        },
      };
    }

    async after() {}
  }

  function createAuthenticatedFetch() {
    return async (input, init = {}) => {
      const headers = new Headers(init.headers || {});
      headers.set("x-portkey-api-key", API_KEY);
      return fetch(input, { ...init, headers });
    };
  }

  async function main() {
    console.log(`Fetching agent card from ${BASE_URL}...`);

    const authFetch = createAuthenticatedFetch();
    const resolverBaseUrl = BASE_URL.endsWith("/") ? BASE_URL : `${BASE_URL}/`;

    const options = ClientFactoryOptions.createFrom(
      ClientFactoryOptions.default,
      {
        cardResolver: new DefaultAgentCardResolver({
          fetchImpl: authFetch,
        }),
        clientConfig: { interceptors: [new HeaderAuthInterceptor()] },
      },
    );

    const factory = new ClientFactory(options);
    const client = await factory.createFromUrl(resolverBaseUrl);

    const card = client.agentCard;

    if (!card) {
      throw new Error("Unable to read agent card from SDK client instance.");
    }

    console.log(JSON.stringify(card, null, 2));
  }

  main().catch((error) => {
    console.error(error);
    process.exit(1);
  });
  ```
</CodeGroup>

## Further reading

<CardGroup cols={2}>
  <Card title="Agent Registry" icon="book" href="/product/agent-gateway/registry">
    Manage your agent integrations and control access to agents and their skills.
  </Card>

  <Card title="Agent Servers" icon="server" href="/product/agent-gateway/servers">
    Learn how virtual agent servers work and how to host your own.
  </Card>

  <Card title="Advanced code snippets and examples" icon="code" href="/product/agent-gateway/advanced-code-snippets-and-examples">
    Explore additional examples for fetching agent cards and invoking agents.
  </Card>

  <Card title="API Keys" icon="key" href="/product/enterprise-offering/org-management/api-keys-authn-and-authz">
    Configure API keys and scopes to securely invoke your agents.
  </Card>
</CardGroup>
