#[SOLVED] Rate limits applied to Function

19 messages · Page 1 of 1 (latest)

coarse sequoia
#

Hello, I'm curios what statement is correct and is it a bug or not. Here is the documentation screenshot and my function execution logs.

"Rate limits do not apply when accessing Appwrite with a Server SDK authenticated using an API key." - Docs
"Error creating pending account: Rate limit for the current endpoint has been exceeded. Please try again after some time." - Cloud function log

viral siren
#

Error creating pending account doesn't seem to be an appwrite exception message.
can you show the relevant part of the code where you get this error?

coarse sequoia
#
async function processPendingAccountsBatch(databases, databaseId, pendingAccountsCollectionId, leads, userId, customer) {
  // Step 4: Create PendingAccount docs
  const pendingAccounts = await Promise.all(leads.map(async (leadDoc) => {
    try {
      const pendingAccount = await databases.createDocument(databaseId, pendingAccountsCollectionId, 'unique()', { status: 'pending', userId });
      console.error("Created pending account:", pendingAccount);
      return pendingAccount;
    } catch (error) {
      console.error("Error creating pending account:", error.message);
      return null;
    }
  }));
#

Hello Darshan Pandya, as you can see the error is raised by createDocument with the rate limit error

#

which should be impossible by design and documents provided

viral siren
#

is the Client using API Key or a Session? Can you share the code related to client? using API KEY should not throw a rate limit.

coarse sequoia
#

It's about API key, as it is a appwrite function

#

it's not from client

#

@viral siren Error creating pending account: Rate limit for the current endpoint has been exceeded. Please try again after some time.

#

"Rate limit for the current endpoint has been exceeded. Please try again after some time." - is this not a rate limit error thrown by appwrite?

viral siren
#

dynamic api key or a standard api key?
also share how you are creating the Client

coarse sequoia
#

standard api key

import { Client, Databases, Storage, ID, InputFile, Query } from 'node-appwrite';

// 3. Init Appwrite SDK
    const client = new Client()
      .setEndpoint('https://cloud.appwrite.io/v1')  // Provided by Appwrite
      .setProject('') // Provided by Appwrite
      .setKey(process.env.APPWRITE_API_KEY);               // Secret API key from Function's ENV
    const databases = new Databases(client);

loud crest
coarse sequoia
#

nope

loud crest
# coarse sequoia nope

Then you're interacting like if you did not have an API key. Consequently you're rate limited. You should have set the scopes for databases in the API Key settings

#

Or use dynamic API Keys

coarse sequoia
#

[SOLVED] Rate limits applied to Function

loud crest
#

@coarse sequoia So that worked, right? Make sure to not expose the API key accidentally as it overrides all permissions 😅