Int() argument must be a string, a bytes-like object or a real number, not 'dict'

I am using python 3.12 and openai version=1.82.0 and macbook

[[package]]
name = “openai”
version = “1.82.0”
source = { registry = “Simple index” }
dependencies = [
{ name = “anyio” },
{ name = “distro” },
{ name = “httpx” },
{ name = “jiter” },
{ name = “pydantic” },
{ name = “sniffio” },
{ name = “tqdm” },
{ name = “typing-extensions” },
]
sdist = { url = “https://files.pythonhosted.org/packages/3f/19/6b09bb3132f7e1a7a2291fd46fb33659bbccca041f863abd682e14ba86d7/openai-1.82.0.tar.gz”, hash = “sha256:b0a009b9a58662d598d07e91e4219ab4b1e3d8ba2db3f173896a92b9b874d1a7”, size = 461092, upload_time = “2025-05-22T20:08:07.282Z” }
wheels = [
{ url = “https://files.pythonhosted.org/packages/51/4b/a59464ee5f77822a81ee069b4021163a0174940a92685efc3cf8b4c443a3/openai-1.82.0-py3-none-any.whl”, hash = “sha256:8c40647fea1816516cb3de5189775b30b5f4812777e40b8768f361f232b61b30”, size = 720412, upload_time = “2025-05-22T20:08:05.637Z” },
]

Here is my code:

from openai import AzureOpenAI

def create_client(self, **kwargs) -> AzureOpenAI:
        """
        Creates a new AzureOpenAI client instance with given parameters.

        Parameters:
            **kwargs: Arbitrary keyword arguments to override default parameters.

        Returns:
            AzureOpenAI: An instance of AzureOpenAI client.
        """
        params = self.default_params.copy()
        params.update(kwargs)

        if self.is_gateway:
            token = self.token_manager.get_token()
            return AzureOpenAI(
                api_version=params["api_version"],
                azure_endpoint=params["azure_endpoint"],
                azure_ad_token=token,
            )

api_version’: ‘2024-02-15-preview’,
azure_endpoint: ‘[https://qa.api.***.com/@@/@@@@/@@/us6’]

I am getting the error as

create_client - 80 - ERROR - Error creating AzureOpenAI client: int() argument must be a string, a bytes-like object or a real number, not ‘dict’

Same exact code is working with python 3.10 and in windows.

Here are my dependencies:

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "ABCD"
version = "3.0.1"
description = "ABCD stands for Project"
readme = "README.md"
requires-python = "~=3.12"
dependencies = [
    "fpdf2~=2.8.2",
    "alembic>=1.15.0",
    "azure-ai-documentintelligence==1.0.0",
    "azure-identity>=1.19.0",
    "azure-keyvault-secrets>=4.9.0",
    "azure-search-documents==11.4.0",
    "azure-storage-blob==12.24.1",
    "beautifulsoup4>=4.12.3",
    "dbutils>=3.1.0",
    "deprecation==2.1.0",
    "docx2pdf==0.1.8",
    "faker>=32.1.0",
    "fastapi~=0.115.11",
    "flaml[automl]~=2.3.2",
    "httpx>=0.27.2",
    "langchain-community==0.2.19",
    "langchain-openai==0.1.8",
    "langchain==0.2.17",
    "markdown>=3.7",
    "mlflow>=2.17.2",
    "msal>=1.31.0",
    "pandas>=2.2.3",
    "pyautogen==0.2.28",
    "pymupdf>=1.24.13",
    "pyodbc>=5.2.0",
    "python-docx>=1.1.2",
    "python-dotenv>=1.0.1",
    "rouge-score==0.1.2",
    "sqlmodel>=0.0.24",
    "tiktoken>=0.8.0",
    "uvicorn>=0.32.0",
    "openpyxl>=3.1.5",
    "requests~=2.32.3",
    "python-multipart>=0.0.20",
    "apscheduler~=3.11.0",
    "azure-monitor-opentelemetry>=1.6.5",
    "XlsxWriter~=3.2.2",
    "croniter~=6.0.0",
    "PyPDF2~=3.0.1",
    "cron-descriptor~=1.4.5",
    "pypdf==5.4.0",
    "nh3>=0.2.21",
]


[tool.uv]
dev-dependencies = [
    "mypy>=1.15.0",
    "polylith-cli>=1.26.0",
    "pre-commit>=4.1.0",
    "pytest-env~=1.1.5",
    "pytest>=8.3.5",
    "pytest-cov>=6.0.0",
    "ruff~=0.9.10",
    "types-requests>=2.31.0.6",
    "pytest-asyncio>=0.25.3",
    "pypdf==5.4.0"
]

[tool.hatch.build]
dev-mode-dirs = ["components", "bases", "development", "."]

[tool.ruff]
exclude = [
    '.venv',
    'alembic',
    'development',
    'tests'
]
line-length = 120
target-version = "py310"

[tool.ruff.lint]
# 1. Enable flake8-bugbear (`B`) rules, in addition to the defaults.
select = [
    "E4",
    "E7",
    "E9",
    "I", # isort
    "F", # pyflakes
    "B", # flake8-bugbear
#    "UP", # pyupgrade
#    "ARG001" # unused arguments in functions
]

# 2. Avoid enforcing line-length violations (`E501`)
ignore = [
    "E501", # line too long, handled by black
    "B008", # do not perfromr function calls in argument defaults
    "B904" # Allow rising exceptions without from e, for HTTPException
]

# 3. Avoid trying to fix flake8-bugbear (`B`) violations.
unfixable = ["B"]

[tool.ruff.format]
# 5. Use single quotes in `ruff format`.
quote-style = "single"
docstring-code-format = true
docstring-code-line-length = 72

[tool.mypy]
plugins = [
    "pydantic.mypy"
]
strict=true
exclude=[
    "venv",
    ".venv",
    "alembic"
]
follow_imports = "silent"
warn_redundant_casts = true
warn_unused_ignores = true
disallow_any_generics = true
no_implicit_reexport = true
disallow_untyped_defs = true

[tool.pydantic-mypy]
init_forbid_extra = true
init_typed = true
warn_required_dynamic_aliases = true

Are you defining api_version etc only after they are used? Are they really in params not from default_params?

Although the forum messes up your paste, I’d look closer at the azure_endpoint value to see the proper use of quotes and that it is not a list.

You’ve got just a few arguments when setting up the client, and you can check that all inputs are strings yourself. print/log the value of kwargs, and the affected params. Make sure that quote characters haven’t snuck in around variables or become the wrong characters by directional quoting.

There’s no int casting in the python library. Maybe something like your endpoint is not closed, parsed wrong and a port is detected from more code..