---
title: "Creates a custom agent key association."
method: POST
path: "/agents/custom_agent_key_associations"
tags: ["Agents"]
---

# Creates a custom agent key association.

`POST /agents/custom_agent_key_associations`

## Request

- Base URL: `https://h2ogpte.genai.h2o.ai/api/v1`
- URL: `https://h2ogpte.genai.h2o.ai/api/v1/agents/custom_agent_key_associations`
- Auth: HTTP bearer
- TypeScript: <https://skmtc.dev/h2o/apis/h2ogpte-rest-api/docs/agents/custom_agent_key_associations/post.ts> (a function with typed inputs; its response is checked against the schema)

Associates an env var (from envs.json or user-added) with an agent key.

## Request body

- CreateCustomAgentKeyAssociationRequest
  - `agent_id` string, uuid, required: Custom agent UUID
  - `env_key_name` string, required: Env var name (from envs.json or user-added)
  - `key_id` string, uuid, required: Agent key UUID to associate

## Response `200`

Successful operation

- CustomAgentKeyAssociation
  - `id` string, uuid, required: Association UUID
  - `agent_id` string, uuid, required: Custom agent UUID
  - `env_key_name` string, required: Env var name (from envs.json or user-added)
  - `key_id` string, uuid, nullable: Agent key UUID (null for placeholder associations)
  - `user_id` string, uuid, required: User UUID who owns the association
  - `requirement_type` 'required' | 'optional_with_default' | 'optional_no_default' | 'custom', required: From envs.json value or custom if assigned after the fact
  - `key_name` string, nullable: Agent key name
  - `owner_email` string, nullable: Agent key owner email

## Other responses

- `400`: Bad request
- `401`: Unauthorized - Invalid or missing API key
- `500`: Internal server error
- `default`: Unexpected error

---

[API](https://skmtc.dev/h2o/apis/h2ogpte-rest-api.md) - [All operations](https://skmtc.dev/h2o/apis/h2ogpte-rest-api/llms.txt) - [OpenAPI document](https://skmtc.dev/h2o/apis/h2ogpte-rest-api/revisions/a82a117320f4?raw)
