Skip to content

Cortex Analyst: Issues with Authentication? #4

Description

@mau-dra

Hi all,

I'm trying to follow your example to set up Cortex Analyst on a streamlit app and was initially able to get results but after Nov 12, I'm getting a new error. "Unauthorized to call Cortex Analyst"

Screenshot 2024-11-13 at 2 29 30 PM

this is what it looked like before:
Screenshot 2024-11-08 at 4 58 31 PM

I'm using the code from

resp = _snowflake.send_snow_api_request(

    resp = _snowflake.send_snow_api_request(
        "POST",  # method
        API_ENDPOINT,  # path
        {},  # headers
        {},  # params
        request_body,  # body
        None,  # request_guid
        API_TIMEOUT,  # timeout in milliseconds
    )

My app is being deployed in development mode to snowflake.

From reading the code in this repo, I'm under the impression that the code above should include authentication under the hood, else the examples here wouldn't work.

Additionally, I went ahead and attempted to fetch from the api outside of snowflake / streamlit by using the following code:

    resp = requests.post(
        url=f"https://{host}/api/v2/cortex/analyst/message",
        json=request_body,
        headers={
            "Authorization": f"Bearer {token}",
            "Content-Type": "application/json",
            "X-Snowflake-Authorization-Token-Type": "KEYPAIR_JWT",
        },
    )

where host is the https://{account_identifier}.snowflakecomputing.com
and I got a successful response.

I attempted to pass in the same headers to the _snowflake.send_snow_api_request but kept getting the same Unauthorized to call Cortex Analyst response.

Please let me know a good way to interact with the Cortex Analyst api within Snowflake / Streamlit.

Mauricio

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions