<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Accessing a FastAPI endpoint using Personal Access Token (PAT) in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/accessing-a-fastapi-endpoint-using-personal-access-token-pat/m-p/9030#M4529</link>
    <description>&lt;P&gt;@Aakash Bhandari​&amp;nbsp;:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To send a request from a React App to a FastAPI endpoint on a Databricks cluster using a Personal Access Token (PAT), you can use the requests module in Python to make HTTP requests.&lt;/P&gt;&lt;P&gt;Here's an example of how to use requests to send a POST request to your FastAPI endpoint:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import requests
&amp;nbsp;
url = "http://0.0.0.0:8084/predict"
headers = {"Authorization": "Bearer &amp;lt;your PAT here&amp;gt;"}
data = {"input": "your input data here"}
&amp;nbsp;
response = requests.post(url, headers=headers, json=data)
&amp;nbsp;
if response.status_code == 200:
    result = response.json()
    # do something with the result
else:
    print("Request failed with status code:", response.status_code)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Replace &amp;lt;your PAT here&amp;gt; with your actual Personal Access Token. You can generate a PAT in your Databricks workspace by going to User Settings &amp;gt; Access Tokens and creating a new token with the appropriate permissions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this example, the data parameter is a dictionary containing the input data that you want to send to your endpoint. You can modify this dictionary to include any additional parameters that your endpoint requires.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, note that the headers parameter includes an Authorization header with the value "Bearer &amp;lt;your PAT here&amp;gt;". This header is required for authenticating with your Databricks cluster using the PAT.&lt;/P&gt;&lt;P&gt;Make sure to modify the url parameter to match the actual address of your FastAPI endpoint. If your Databricks cluster is behind a firewall or network security group, you may need to configure your firewall rules to allow traffic from your local computer to the cluster's IP address and port number.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope all these suggestions help you to come to the solution.&lt;/P&gt;</description>
    <pubDate>Fri, 31 Mar 2023 15:32:58 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-03-31T15:32:58Z</dc:date>
    <item>
      <title>Accessing a FastAPI endpoint using Personal Access Token (PAT)</title>
      <link>https://community.databricks.com/t5/data-engineering/accessing-a-fastapi-endpoint-using-personal-access-token-pat/m-p/9029#M4528</link>
      <description>&lt;P&gt;Hello Community,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a FastAPI endpoint on a cluster with addess 0.0.0.0:8084/predict. And I want to send a request to this endpoint from a React App which is locally hosted on my computer. I have a Personal access token for the workspace but dont know how to send the request using PAT. If anyone knows, please mention how can I hit &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;A href="http://0.0.0.0:8084/predict" target="test_blank"&gt;http://0.0.0.0:8084/predict&lt;/A&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; endpoint in a cluster so that I can do realtime prediction with low latency. Mentioning a URL template to hit would be a great help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PS. My current requirement does not allow me to use Model serving feature of Databricks.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2023 06:24:16 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/accessing-a-fastapi-endpoint-using-personal-access-token-pat/m-p/9029#M4528</guid>
      <dc:creator>Aakash_Bhandari</dc:creator>
      <dc:date>2023-02-21T06:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing a FastAPI endpoint using Personal Access Token (PAT)</title>
      <link>https://community.databricks.com/t5/data-engineering/accessing-a-fastapi-endpoint-using-personal-access-token-pat/m-p/9030#M4529</link>
      <description>&lt;P&gt;@Aakash Bhandari​&amp;nbsp;:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To send a request from a React App to a FastAPI endpoint on a Databricks cluster using a Personal Access Token (PAT), you can use the requests module in Python to make HTTP requests.&lt;/P&gt;&lt;P&gt;Here's an example of how to use requests to send a POST request to your FastAPI endpoint:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import requests
&amp;nbsp;
url = "http://0.0.0.0:8084/predict"
headers = {"Authorization": "Bearer &amp;lt;your PAT here&amp;gt;"}
data = {"input": "your input data here"}
&amp;nbsp;
response = requests.post(url, headers=headers, json=data)
&amp;nbsp;
if response.status_code == 200:
    result = response.json()
    # do something with the result
else:
    print("Request failed with status code:", response.status_code)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Replace &amp;lt;your PAT here&amp;gt; with your actual Personal Access Token. You can generate a PAT in your Databricks workspace by going to User Settings &amp;gt; Access Tokens and creating a new token with the appropriate permissions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this example, the data parameter is a dictionary containing the input data that you want to send to your endpoint. You can modify this dictionary to include any additional parameters that your endpoint requires.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, note that the headers parameter includes an Authorization header with the value "Bearer &amp;lt;your PAT here&amp;gt;". This header is required for authenticating with your Databricks cluster using the PAT.&lt;/P&gt;&lt;P&gt;Make sure to modify the url parameter to match the actual address of your FastAPI endpoint. If your Databricks cluster is behind a firewall or network security group, you may need to configure your firewall rules to allow traffic from your local computer to the cluster's IP address and port number.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope all these suggestions help you to come to the solution.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2023 15:32:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/accessing-a-fastapi-endpoint-using-personal-access-token-pat/m-p/9030#M4529</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-03-31T15:32:58Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing a FastAPI endpoint using Personal Access Token (PAT)</title>
      <link>https://community.databricks.com/t5/data-engineering/accessing-a-fastapi-endpoint-using-personal-access-token-pat/m-p/9031#M4530</link>
      <description>&lt;P&gt;Thank you @Suteja Kanuri​&amp;nbsp;. Previously, I was using context create and command run APIs before for the work around. &lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2023 10:20:09 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/accessing-a-fastapi-endpoint-using-personal-access-token-pat/m-p/9031#M4530</guid>
      <dc:creator>Aakash_Bhandari</dc:creator>
      <dc:date>2023-04-10T10:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing a FastAPI endpoint using Personal Access Token (PAT)</title>
      <link>https://community.databricks.com/t5/data-engineering/accessing-a-fastapi-endpoint-using-personal-access-token-pat/m-p/9032#M4531</link>
      <description>&lt;P&gt;@Aakash Bhandari​&amp;nbsp;: I am glad my resolution helped you! Cheers~~Happy progressing. &lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2023 12:48:57 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/accessing-a-fastapi-endpoint-using-personal-access-token-pat/m-p/9032#M4531</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-04-10T12:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing a FastAPI endpoint using Personal Access Token (PAT)</title>
      <link>https://community.databricks.com/t5/data-engineering/accessing-a-fastapi-endpoint-using-personal-access-token-pat/m-p/9033#M4532</link>
      <description>&lt;P&gt;Hello @Suteja Kanuri​&amp;nbsp;&lt;/P&gt;&lt;P&gt;Following up on this, How would the request module know the URL request is for databricks. If we try to hit the url &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;A href="http://0.0.0.0:8080" target="test_blank"&gt;http://0.0.0.0:8080&lt;/A&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It will look into the computer's localhost to get the service running in 8080 port. Is there a way to address this?&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2023 06:07:04 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/accessing-a-fastapi-endpoint-using-personal-access-token-pat/m-p/9033#M4532</guid>
      <dc:creator>Aakash_Bhandari</dc:creator>
      <dc:date>2023-04-17T06:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing a FastAPI endpoint using Personal Access Token (PAT)</title>
      <link>https://community.databricks.com/t5/data-engineering/accessing-a-fastapi-endpoint-using-personal-access-token-pat/m-p/9034#M4533</link>
      <description>&lt;P&gt;@Aakash Bhandari​&amp;nbsp;:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You are correct that if you try to hit &lt;A href="http://0.0.0.0:8080" target="test_blank"&gt;http://0.0.0.0:8080&lt;/A&gt; from your React App, it will look for the service running on the local machine's localhost and not on the Databricks cluster.&lt;/P&gt;&lt;P&gt;To address this, you need to specify the URL of the cluster's FastAPI endpoint in the request. This URL will typically be of the form &lt;A href="https://&amp;lt;databricks-instance-name&amp;gt;.cloud.databricks.com:443/&amp;lt;path-to-your-endpoint&amp;gt;" target="test_blank"&gt;https://&amp;lt;databricks-instance-name&amp;gt;.cloud.databricks.com:443/&amp;lt;path-to-your-endpoint&amp;gt;&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's an example code snippet that shows how to make a POST request to a FastAPI endpoint hosted on a Databricks cluster:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import requests
import json
&amp;nbsp;
# Replace &amp;lt;databricks-instance-name&amp;gt; with the name of your Databricks instance
url = "https://&amp;lt;databricks-instance-name&amp;gt;.cloud.databricks.com:443/predict"
&amp;nbsp;
# Replace &amp;lt;token&amp;gt; with your Databricks Personal Access Token
headers = {"Authorization": f"Bearer &amp;lt;token&amp;gt;"}
&amp;nbsp;
# Example payload for the POST request
payload = {"data": {"age": 35, "income": 45000}}
&amp;nbsp;
# Send the request to the FastAPI endpoint
response = requests.post(url, headers=headers, data=json.dumps(payload))
&amp;nbsp;
# Print the response
print(response.json())&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Note that you need to replace &amp;lt;databricks-instance-name&amp;gt; with the name of your Databricks instance and &amp;lt;token&amp;gt; with your Databricks Personal Access Token. You also need to replace the example payload with your own JSON payload for the POST request.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2023 12:55:06 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/accessing-a-fastapi-endpoint-using-personal-access-token-pat/m-p/9034#M4533</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-04-17T12:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing a FastAPI endpoint using Personal Access Token (PAT)</title>
      <link>https://community.databricks.com/t5/data-engineering/accessing-a-fastapi-endpoint-using-personal-access-token-pat/m-p/9035#M4534</link>
      <description>&lt;P&gt;Hey @Suteja Kanuri​&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I implemented your code in my usecase but it is throwing 404 error as reponse. Below is the code I am using and dont know why it is not working. &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;header = {"Authorization": "Bearer " + os.getenv("PAT")}
context_response = requests.get(
    "https://&amp;lt;dtaabricks-instance&amp;gt;.gcp.databricks.com:443/api_health",
    headers=header
)
&amp;nbsp;
context_data = context_response.json()
print(context_data)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am running my fastAPI app in a notebook in one of the cluster. The app is running on port 8081. Could you please help me out where am I getting wrong here?&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 08:25:33 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/accessing-a-fastapi-endpoint-using-personal-access-token-pat/m-p/9035#M4534</guid>
      <dc:creator>Aakash_Bhandari</dc:creator>
      <dc:date>2023-04-19T08:25:33Z</dc:date>
    </item>
  </channel>
</rss>

