# OpenAI conversation

Type: `conversation.openai`

Status: alpha

Reference: https://docs.dapr.io/reference/components-reference/supported-conversation/openai/

## Example

```
apiVersion: cra.diagrid.io/v1beta1
kind: Component
metadata:
  name: <name>
spec:
  type: conversation.openai
  version: v1
  metadata:
    # API key for OpenAI.
    - name: key
      value: | 
        **********
    # The type of API to use for the OpenAI service. This is required when using Azure OpenAI. (Optional)
    #- name: apiType
    #  value: "open_ai"
    # The API version to use for the Azure OpenAI service. This is required when using Azure OpenAI. (Optional)
    #- name: apiVersion
    #  value: "2025-01-01-preview"
    # A time-to-live value for a prompt cache to expire. Uses Golang durations (Optional)
    #- name: cacheTTL
    #  value: "10m"
    # Custom API endpoint URL for OpenAI API-compatible services. If not specified, the default OpenAI API endpoint will be used. (Optional)
    #- name: endpoint
    #  value: "https://api.openai.com/v1"
    # Default maximum number of tokens the model may generate per request. A request-level maxTokens value greater than zero overrides this default. When unset, no cap is sent and the provider's own default applies. (Optional)
    #- name: maxTokens
    #  value: "2048"
    # The OpenAI LLM to use. Configurable via OPENAI_MODEL environment variable. (Optional)
    #- name: model
    #  value: "gpt-5-nano"
    # Send the token cap as max_tokens instead of max_completion_tokens. Set this when endpoint points at an OpenAI-compatible service that does not recognise max_completion_tokens, otherwise the cap is ignored. (Optional)
    #- name: useLegacyMaxTokensField
    #  value: "false"
    # Send requests to OpenAI's Responses API (/v1/responses) instead of the Chat Completions API. Set this to use function tools with reasoning models that reject tools on Chat Completions. Not supported when apiType is azure. (Optional)
    #- name: useResponsesAPI
    #  value: "false"

```

## Authentication profiles

Available authentication profiles:

- API Key

### API Key

Authenticate using an API key

#### `key` (string)

**Required** - API key for OpenAI.

Example value:

```
**********
```

## Metadata

### `apiType` (string)

The type of API to use for the OpenAI service. This is required when using Azure OpenAI.

Default value: `open_ai`

Example value: `azure`

Allowed values:

- open_ai

- azure

### `apiVersion` (string)

The API version to use for the Azure OpenAI service. This is required when using Azure OpenAI.

Example value: `2025-01-01-preview`

### `cacheTTL` (string)

A time-to-live value for a prompt cache to expire. Uses Golang durations

Example value: `10m`

### `endpoint` (string)

Custom API endpoint URL for OpenAI API-compatible services. If not specified, the default OpenAI API endpoint will be used.

Example value: `https://api.openai.com/v1`

### `maxTokens` (number)

Default maximum number of tokens the model may generate per request. A request-level maxTokens value greater than zero overrides this default. When unset, no cap is sent and the provider's own default applies.

Example value: `2048`

### `model` (string)

The OpenAI LLM to use. Configurable via OPENAI_MODEL environment variable.

Default value: `gpt-5-nano`

Example value: `gpt-5-nano`

### `useLegacyMaxTokensField` (bool)

Send the token cap as max_tokens instead of max_completion_tokens. Set this when endpoint points at an OpenAI-compatible service that does not recognise max_completion_tokens, otherwise the cap is ignored.

Default value: `false`

Example value: `true`

### `useResponsesAPI` (bool)

Send requests to OpenAI's Responses API (/v1/responses) instead of the Chat Completions API. Set this to use function tools with reasoning models that reject tools on Chat Completions. Not supported when apiType is azure.

Default value: `false`

Example value: `true`
