> For the complete documentation index, see [llms.txt](https://partner-docs.covergenius.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://partner-docs.covergenius.com/elements/reference/api-reference.md).

# API Reference

Every export of @covergenius/elements.

### `registerElements(config)`

Registers the `<cg-elements>` custom element and creates the SDK context. Call it once for each page, before `getElement()`.

```ts
registerElements(config: RegisterElementsConfig): void
```

The call is safe to repeat. It does nothing when no `customElements` registry exists, for example on a server.

#### `RegisterElementsConfig`

| Field            | Type                                    | Required | Default      | Purpose                                  |
| ---------------- | --------------------------------------- | -------- | ------------ | ---------------------------------------- |
| `environment`    | `'production'`, `'uat'`, or `'develop'` | Yes      | `production` | Selects the SDK environment.             |
| `currencyConfig` | `CurrencyFormatOptions`                 | No       | none         | Price format. See Currency and Language. |
| `scheme`         | `'light'` or `'dark'`                   | No       | `light`      | The active color scheme.                 |
| `debug`          | `boolean`                               | No       | `false`      | Writes SDK logs to the browser console.  |

### `getElement(ref?)`

Returns the client for one placement.

```ts
getElement(ref?: string): Client | undefined
```

| Argument | Purpose                                                                             |
| -------- | ----------------------------------------------------------------------------------- |
| `ref`    | The `data-presentation-ref` value of the placement. Omit it for a single placement. |

It returns `undefined` when `registerElements()` has not run. It also returns `undefined` outside a browser.

### Client

The object that `getElement()` returns.

#### Methods

| Method                    | Purpose                                                                                |
| ------------------------- | -------------------------------------------------------------------------------------- |
| `render(response)`        | Renders or renders again from the Create Offer response.                               |
| `on(event, handler)`      | Sets the handler for an event. A new call for the same event replaces the old handler. |
| `selection.set(optionId)` | Chooses an option.                                                                     |
| `selection.get()`         | Returns the last selected option ID, or `null`.                                        |
| `selection.getAll()`      | Returns all selected option IDs in order.                                              |
| `selection.reset()`       | Clears the selection and the required prompt.                                          |
| `selection.required()`    | Shows the required prompt while nothing is selected.                                   |
| `unmount()`               | Clears handlers, selection, and state. Hides the element.                              |

#### Events

| Event    | Payload                                                                        |
| -------- | ------------------------------------------------------------------------------ |
| `ready`  | None.                                                                          |
| `change` | `{ selectedOption: string, selectedProductIDs: string[], declined?: boolean }` |
| `error`  | `{ code: string, message: string }`                                            |

### Attributes

| Attribute                   | On              | Purpose                                                 |
| --------------------------- | --------------- | ------------------------------------------------------- |
| `data-presentation-ref`     | `<cg-elements>` | Names a placement. Use the value of `presentation.ref`. |
| `data-cg-elements-state`    | `<cg-elements>` | Read-only. Holds `loading`, `rendered`, or `error`.     |
| `data-cg-elements-required` | `<cg-elements>` | Read-only. Present while the required prompt shows.     |

### Package entry points

| Entry                              | Purpose                         |
| ---------------------------------- | ------------------------------- |
| `@covergenius/elements`            | The SDK. ESM and CommonJS.      |
| `@covergenius/elements/loader.css` | The optional loading animation. |

### Offer response fields that the SDK reads

<table><thead><tr><th width="179">Field</th><th>Use</th></tr></thead><tbody><tr><td><code>currency</code></td><td>The currency code for all prices.</td></tr><tr><td><code>products[]</code></td><td>The quotes. Each has an <code>id</code>, price details, and a policy wording URL.</td></tr><tr><td><code>product_rules[]</code></td><td>How many options the customer can choose, and which options show or hide others.</td></tr><tr><td><code>content</code></td><td>The customer-facing text.</td></tr><tr><td><code>presentation</code></td><td>The <code>schema_version</code>, <code>ref</code>, <code>layout</code>, and <code>theme</code>.</td></tr></tbody></table>

The SDK needs a non-empty `presentation` field and a supported `schema_version`. The current version is `1.0`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://partner-docs.covergenius.com/elements/reference/api-reference.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
