> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openformat.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# Get an API key

> Get an API key to authenticate your user in our API.

<Steps>
  <Step title="Generate a challenge">
    First, you need to use our `/key/challenge` endpoint
    to generate a challenge.

    You will pass your user 's Ethereum address to this endpoint.
    The response will contain a field `challenge` that you need for the next step.

    <CodeGroup>
      ```curl cURL theme={null}
      curl --request POST \
        --url https://api.openformat.tech/key/challenge \
        --header 'Content-Type: application/json' \
        --data '{
        "public_address": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
      }'
      ```

      ```json JSON Response theme={null}
      {
        "status": "success",
        "challenge": "b1c2903bea5b294543e751b1742256e7bd44002f6460c6b2a1f8643984d5b513"
      }
      ```
    </CodeGroup>
  </Step>

  <Step title="Sign the challenge">
    Next, you need to sign the challenge with the user 's private key.
    You can use our Metamask with our [signing tool](https://openformat-tools.vercel.app/) or the following scripts:

    <CodeGroup>
      ```tsx viem (Recommended) theme={null}
      import { privateKeyToAccount } from "viem/accounts";

      const account = privateKeyToAccount("YOUR_PRIVATE_KEY");

      // Challenge returned from /key/challenge endpoint
      const challenge = "7877fa9f42dd92bebfefa7d6469e774327afddf76718e93288182949af7d3ade";

      const signed = await account.signMessage({ message: challenge });

      console.log(signed);
      // 0x9fe5ad28c81419f5135aec3c....

      ```

      ```tsx ethers theme={null}
      import { ethers } from "ethers";

      const privateKey = "YOUR_PRIVATE_KEY";
      const wallet = new ethers.Wallet(privateKey);

      // Challenge returned from /key/challenge endpoint
      const challenge = "7877fa9f42dd92bebfefa7d6469e774327afddf76718e93288182949af7d3ade";

      const signed = await wallet.signMessage(challenge);

      console.log(signed);
      // 0x9fe5ad28c81419f5135aec3c....
      ```
    </CodeGroup>
  </Step>

  <Step title="Respond the challenge and get the API key">
    Send the result of previous step to the `/key/verify` endpoint and recieve
    the API key in the response. You need to send the `signature` and your user 's
    Ethereum address as field `public_address`.

    <CodeGroup>
      ```curl cURL theme={null}
      curl --request POST \
        --url https://api.openformat.tech/key/verify \
        --header 'Content-Type: application/json' \
        --data '{
        "signature": "0x860729b.....",
        "public_address": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
      }'
      ```

      ```json JSON Response theme={null}
      {
        "api_key": "5a2a5e28-1851-4029-b0db-987e4b235a35"
      }
      ```
    </CodeGroup>

    Save this API key in appropiate place with sufficient security.
  </Step>
</Steps>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.