Skip to content
Back

The dynamic API key has expired

  • 0
  • Self Hosted
  • Functions
WhMonkey
15 Feb, 2025, 11:13

Error checking upload status for id: The dynamic API key has expired. Please don't use dynamic API keys for more than duration of the execution.

But it generates a new one each time?

For more context see here: https://discord.com/channels/564160730845151244/564160731327758347/1340278934528331808

TL;DR
Developers experiencing issue with dynamic API key expiring, likely due to code problem. Error occurs when triggering function on file creation event in a bucket. Running Python 3.9. Ensure key not expired before function timeout. Error message indicates key expiration. Check self-hosted version and key access method. Solution: Ensure dynamic API key generation on each request to prevent expiration.
WhMonkey
15 Feb, 2025, 11:15

I make it get the dynamic api key from the request header

Darshan Pandya
15 Feb, 2025, 11:17
  1. i see self-hosted, what version?
  2. how are you accessing the key?
  3. the key has an expiry of function's timeout too. make sure its not very less.
Darshan Pandya
15 Feb, 2025, 11:17

maybe also share some sample snippet that can reproduce this behaviour.

WhMonkey
15 Feb, 2025, 11:18
  1. latest (1.6.0)
  2. just fetching the request headers
  3. the timeout i haven't touched
WhMonkey
15 Feb, 2025, 11:18

one sec lemme get the code

WhMonkey
15 Feb, 2025, 11:19
TypeScript
def initialize_services(env, context):
    context.log("Setting up Appwrite services")
    client = Client()
    client.set_endpoint(env['API_ENDPOINT'])
    client.set_project(env['PROJECT_ID'])
    client.set_key(context.req.headers.get('x-appwrite-key'))

    storage = Storage(client)
    databases = Databases(client)

    try:
        context.log("Verifying database and storage access")
        databases.list_documents(env['DATABASE_ID'], env['OUTFIT_COLLECTION_ID'], [Query.limit(1)])
        storage.list_files(env['UPLOAD_BUCKET_ID'], [Query.limit(1)])
        context.log("Service initialization successful")
    except AppwriteException as e:
        err_msg = f"Service initialization failed: {str(e)}"
        context.error(err_msg)
        context.log(err_msg)
        return context.res.json({"error": err_msg})

    return storage, databases```
WhMonkey
15 Feb, 2025, 11:19

I'm running Python 3.9

WhMonkey
15 Feb, 2025, 11:20

The funciton is triggered on a file creation event in a bucket

Darshan Pandya
15 Feb, 2025, 11:20

code looks ok. how consistent is this issue?

WhMonkey
15 Feb, 2025, 11:20

First time it happens in this function

WhMonkey
15 Feb, 2025, 11:20

it's happened in another one before where it hung

WhMonkey
15 Feb, 2025, 11:20

but that might just be a code problem

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more