从AC#程序中,我想称呼我的顶点AI端点用 api键 (通过“ Google cloud”/recertentials/api键“
>
:
curl -x帖子
-h“ apikey = .. mykey ...” -h“ content-type:application/json” https://...googleapis.com/v1/projects/ [Project_ID]端点/[endpoint_id]:预测
-d @image.json
错误:
“错误”: {
“代码”:401,
“消息”:“缺少请求,需要身份验证凭据。预期的OAuth 2访问令牌,登录cookie或其他有效的身份验证凭据。
}
我的问题:
有没有一种方法可以使用Apikey进行身份验证来验证顶点AI?
from a c# program i want to call my vertex ai endpoint for prediction with an api key (via "Google Cloud"/Credentials/API Keys" )). I gave the api key access to Vertex AI and as a test everything else too.
calling it with curl or c# i get the error that the service expects an "OAuth 2 access token " or something else.
CURL:
curl -X POST
-H "apikey=..mykey..." -H "Content-Type: application/json" https://.....googleapis.com/v1/projects/[PROJECT_ID]/locations/europe-west4/endpoints/[ENDPOINT_ID]:predict
-d @image.json
ERROR:
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. ...
}
MY QUESTION:
Is there a way to use the Apikey for authentication to vertex ai?
发布评论
评论(3)
您无法将API密钥用于凭据。您必须通过Google身份验证或Google Service帐户获得承载令牌,
此错误将显示您是否在此处使用API密钥
,我将显示如何生成携带者令牌: https://stackoverflow.com/a/75963509/11096674
You could not use the API key for credentials. You must get the Bearer token via Google authentication or Google Service account
This error will show if you are using API Key
Here I will show how to generate Bearer Token: https://stackoverflow.com/a/75963509/11096674
我看到这有点老了,但是我遇到了同样的问题,一周后能够解决它。
步骤
以下是使用此代码在我中使用此代码的
,邮件问题是your_access_token,这不是API密钥。
o获取访问令牌以调用顶点AI端点,您需要使用具有必要权限来调用端点的Google Cloud凭据进行身份验证。
以下是您可以使用Google Cloud SDK获取访问令牌的方式:
通过在此处按照说明安装Google Cloud SDK: https://cloud.google.com/sdk/install 。
打开终端或命令提示符,然后运行以下命令使用您的Google Cloud凭据进行身份验证:
请按照提示符登录到您的Google Cloud帐户,并将权限授予Google Cloud SDK。
经过身份验证后,您可以通过运行以下命令获得访问令牌:
这将输出一个访问令牌,您可以使用该命令来验证您的请求到顶点AI端点。
在我之前提供的示例代码片段中,将您使用上述步骤获得的访问令牌替换为your_access_token。
应该解决它
I see this is a bit old but I was having the same issue and after a week was able to solve it.
Here are the steps
Using this code in c#
for me the mail issue was the YOUR_ACCESS_TOKEN which is not the API key.
o obtain an access token for calling a Vertex AI endpoint, you need to authenticate using Google Cloud credentials that have the necessary permissions to call the endpoint.
Here's how you can obtain an access token using the Google Cloud SDK:
Install the Google Cloud SDK by following the instructions here: https://cloud.google.com/sdk/install.
Open a terminal or command prompt and run the following command to authenticate using your Google Cloud credentials:
Follow the prompts to log in to your Google Cloud account and grant permissions to the Google Cloud SDK.
Once you're authenticated, you can obtain an access token by running the following command:
This will output an access token that you can use to authenticate your requests to the Vertex AI endpoint.
In the example code snippets I provided earlier, replace YOUR_ACCESS_TOKEN with the access token you obtained using the above steps.
That should solve it
这是一个封闭的测试版,但是如果您有访问权限,现在可以使用Google MakerSuite生成一个简单的API密钥。参见在MakerSuite中为Vertexai生成API密钥,但目前处于封闭的beta中。然后只需使用& key = thatkey调用顶点AI API
It is a closed Beta, but if you have access, now you can use google makersuite to generate a simple api key. See step-by-step to generate API key for vertexAI in makersuite, but currently is on a closed beta. then just call the vertex AI api with &key=thatKey