国内免费白嫖claude 3.5 api教程

国内免费白嫖claude 3.5 api教程


google的vertex-ai有一个模型广场,提供了主流的ai模型调用,新用户注册可送150美元的tokens,必须90天内用完。

1、注册登录/vertex-ai

打开https://cloud.google.com/vertex-ai

选择使用vertex ai free按钮


勾选条款


2、开启vertext api

成功后在页面中点击ennable vertext api


3、申请claude


进入model gardon模型广场,点开基础模型,一共78个,选择claude模型家族


4、找到基础模型



5、填写申请表


可以用这个工具生成以个非常逼真的虚假信息,工具地址:点击打开链接



申请成功了


6、创建service account

https://console.cloud.google.com/projectselector/iam-admin/serviceaccounts/create

选择你刚创立的项目


填写信息,注意授权vertex ai user和administrator给这个项目。


成功之后就可以创建key,key默认会自动下载到你的本地



7、cloudflare worker设置代理

登录cloudflare后台:https://dash.cloudflare.com/login

在cloudflare中新建一个worker,代码复制进去,最好绑定一个自己的域名,否则国内无法访问


const MODELS = {
  "claude-3-opus": {
      vertexName: "claude-3-opus@20240229",
      region: "us-east5",
  },
  "claude-3-sonnet": {
      vertexName: "claude-3-5-sonnet@20240620",
      region: "europe-west1",
  },
  "claude-3-haiku": {
      vertexName: "claude-3-haiku@20240307",
      region: "us-central1",
  },
  "claude-3-5-sonnet": {
      vertexName: "claude-3-5-sonnet@20240620",
      region: "us-east5",
  },
  "claude-3-opus-20240229": {
      vertexName: "claude-3-opus@20240229",
      region: "us-east5",
  },
  "claude-3-sonnet-20240229": {
      vertexName: "claude-3-sonnet@20240229",
      region: "us-central1",
  },
  "claude-3-haiku-20240307": {
      vertexName: "claude-3-haiku@20240307",
      region: "us-central1",
  },
  "claude-3-5-sonnet-20240620": {
      vertexName: "claude-3-5-sonnet@20240620",
      region: "us-east5",
  },
};

addEventListener("fetch", (event) => {
  event.respondWith(handleRequest(event.request));
});

async function handleRequest(request) {
  let headers = new Headers({
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Headers": "*",
      "Access-Control-Allow-Methods": "GET, POST, OPTIONS",
  });
  if (request.method === "OPTIONS") {
      return new Response(null, { headers });
  } else if (request.method === "GET") {
      return createErrorResponse(405, "invalid_request_error", "GET method is not allowed");
  }

  const apiKey = request.headers.get("x-api-key");
  if (!API_KEY || API_KEY !== apiKey) {
      return createErrorResponse(401, "authentication_error", "invalid x-api-key");
  }

  const signedJWT = await createSignedJWT(CLIENT_EMAIL, PRIVATE_KEY)
  const [token, err] = await exchangeJwtForAccessToken(signedJWT)
  if (token === null) {
      console.log(`Invalid jwt token: ${err}`)
      return createErrorResponse(500, "api_error", "invalid authentication credentials");
  }

  try {
      const url = new URL(request.url);
      const normalizedPathname = url.pathname.replace(/^(\/)+/, '/');
      switch(normalizedPathname) {
          case "/v1/v1/messages":
          case "/v1/messages":
          case "/messages":
              return handleMessagesEndpoint(request, token);
          default:
              return createErrorResponse(404, "not_found_error", "Not Found");
      }
  } catch (error) {
      console.error(error);
      return createErrorResponse(500, "api_error", "An unexpected error occurred");
  }
}

async function handleMessagesEndpoint(request, api_token) {
  const anthropicVersion = request.headers.get('anthropic-version');
  if (anthropicVersion && anthropicVersion !== '2023-06-01') {
      return createErrorResponse(400, "invalid_request_error", "API version not supported");
  }

  let payload;
  try {
      payload = await request.json();
  } catch (err) {
      return createErrorResponse(400, "invalid_request_error", "The request body is not valid JSON.");
  }

  payload.anthropic_version = "vertex-2023-10-16";

  if (!payload.model) {
      return createErrorResponse(400, "invalid_request_error", "Missing model in the request payload.");
  } else if (!MODELS[payload.model]) {
      return createErrorResponse(400, "invalid_request_error", `Model \`${payload.model}\` not found.`);
  }

  const stream = payload.stream || false;
  const mode...

点击查看剩余70%

{{collectdata}}

网友评论0