A keyspace in Unkey is a container for your keys. Head to your dashboard and create one, or use one you already have.Copy your API ID, it looks like api_xxxx.
Now let’s create a key that your users would use to authenticate:
curl -X POST https://api.unkey.com/v2/keys.createKey \ -H "Authorization: Bearer YOUR_ROOT_KEY" \ -H "Content-Type: application/json" \ -d '{ "apiId": "api_xxxx", "name": "My First Key" }'
import { Unkey } from "@unkey/api";const unkey = new Unkey({ rootKey: process.env.UNKEY_ROOT_KEY });try { const { meta, data } = await unkey.keys.createKey({ apiId: "api_xxxx", name: "My First Key", }); console.log(data.key); // This is the key to give to your user} catch (err) { console.error(err);}
from unkey import Unkeyunkey = Unkey(root_key="your_root_key")result = unkey.keys.create_key( api_id="api_xxxx", name="My First Key")print(result.key) # This is the key to give to your user
package mainimport ( "context" "fmt" "os" unkey "github.com/unkeyed/sdks/api/go/v2" "github.com/unkeyed/sdks/api/go/v2/models/components")func main() { ctx := context.Background() client := unkey.New( unkey.WithSecurity(os.Getenv("UNKEY_ROOT_KEY")), ) res, err := client.Keys.CreateKey(ctx, components.V2KeysCreateKeyRequestBody{ APIID: "api_xxxx", Name: stringPtr("My First Key"), }) if err != nil { panic(err) } fmt.Println(res.V2KeysCreateKeyResponseBody.Key) // Give this to your user}func stringPtr(s string) *string { return &s }
Save the returned key value, that’s what you’ll verify in the next step.