import get_openai_callbackBASE_URL = "https://{endpoint}.openai.azure.com"API_KEY = "..."DEPLOYMENT_NAME = "gpt-35-turbo" # in Azure, this deployment has version 0613 - input and output tokens are counted separatelymodel = AzureChatOpenAI(    openai_api_base=BASE_URL,    openai_api_version="2023-05-15",    deployment_name=DEPLOYMENT_NAME,    openai_api_key=API_KEY,    openai_api_type="azure",)with get_openai_callback() as cb:    model(        [            HumanMessage(                content="Translate this sentence from English to French. I love programming."            )        ]    )    print(f"Total Cost (USD): ${format(cb.total_cost, '.6f')}") # without specifying the model version, flat-rate 0.002 USD per 1k input and output tokens is used    Total Cost (USD): $0.000054We can provide the model version to AzureChatOpenAI constructor. It will get appended to the model name returned by Azure OpenAI and cost will be counted correctly.model0613 = AzureChatOpenAI(    openai_api_base=BASE_URL,    openai_api_version="2023-05-15",    deployment_name=DEPLOYMENT_NAME,    openai_api_key=API_KEY,    openai_api_type="azure",    model_version="0613")with get_openai_callback() as cb:    model0613(        [            HumanMessage(                content="Translate this sentence from English to French. I love programming."            )        ]    )    print(f"Total Cost (USD): ${format(cb.total_cost, '.6f')}")    Total Cost (USD): $0.000044PreviousAnyscaleNextAzureML Chat Online EndpointModel VersionCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.
This notebook goes over how to connect to an Azure hosted OpenAI endpoint
This notebook goes over how to connect to an Azure hosted OpenAI endpoint ->: import get_openai_callbackBASE_URL = "https://{endpoint}.openai.azure.com"API_KEY = "..."DEPLOYMENT_NAME = "gpt-35-turbo" # in Azure, this deployment has version 0613 - input and output tokens are counted separatelymodel = AzureChatOpenAI(    openai_api_base=BASE_URL,    openai_api_version="2023-05-15",    deployment_name=DEPLOYMENT_NAME,    openai_api_key=API_KEY,    openai_api_type="azure",)with get_openai_callback() as cb:    model(        [            HumanMessage(                content="Translate this sentence from English to French. I love programming."            )        ]    )    print(f"Total Cost (USD): ${format(cb.total_cost, '.6f')}") # without specifying the model version, flat-rate 0.002 USD per 1k input and output tokens is used    Total Cost (USD): $0.000054We can provide the model version to AzureChatOpenAI constructor. It will get appended to the model name returned by Azure OpenAI and cost will be counted correctly.model0613 = AzureChatOpenAI(    openai_api_base=BASE_URL,    openai_api_version="2023-05-15",    deployment_name=DEPLOYMENT_NAME,    openai_api_key=API_KEY,    openai_api_type="azure",    model_version="0613")with get_openai_callback() as cb:    model0613(        [            HumanMessage(                content="Translate this sentence from English to French. I love programming."            )        ]    )    print(f"Total Cost (USD): ${format(cb.total_cost, '.6f')}")    Total Cost (USD): $0.000044PreviousAnyscaleNextAzureML Chat Online EndpointModel VersionCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.