Skip to main content

Toolkit for fast and flexible integration with Azure OpenAI

Project description

PyPI Version PyPI Downloads GitHub Tag License Repo Size Python Version

Last Commit Commits Per Month Build Status Security Scan

GitHub Stars Contributors Open Issues Open PRs

Author LinkedIn


rsazure-openai-toolkit

A lightweight, independent toolkit (with CLI support) to simplify and accelerate integration with Azure OpenAI.


๐Ÿ“š Contents


โ“ Why This Project?

There are many tools for interacting with OpenAI โ€” but most are either too simplistic for real-world use, or too complex and tightly coupled to specific platforms.

This project was born out of the need for something in between:

  • ๐Ÿ” Transparent and auditable โ€” no magic, no vendor lock-in
  • โš™๏ธ Flexible โ€” can be used in scripts, production systems, or CI/CD pipelines
  • ๐Ÿงฉ Modular โ€” easy to extend or integrate with other workflows
  • ๐Ÿง  Smart โ€” includes retry logic, environment handling, and a developer-friendly CLI
  • ๐Ÿงช Lightweight โ€” zero dependencies beyond whatโ€™s needed, no bloat

Whether you're prototyping locally or running critical flows in production, this toolkit helps you do it faster, safer, and with full control.

Built by an engineer with real-world experience in AI, cloud, and software systems โ€” to solve real developer problems.


๐Ÿง  Design Principles

These principles define how this toolkit is designed, maintained, and expected to be used โ€” prioritizing security, clarity, and real-world applicability:

  • Security first: No telemetry, no hidden dependencies, and full code transparency โ€” always auditable and verifiable.
  • Simplicity over complexity: A minimal, no-friction interface that works out-of-the-box without overwhelming configuration.
  • Production-readiness: Built with reliability in mind โ€” includes retry logic, CLI validation, and clear error handling.
  • Explicit over implicit: All configurations are visible and controlled; no surprises behind the scenes.
  • Extendable by design: Modular and adaptable for integration into larger systems and workflows.
  • Developer & team friendly: Works great for individuals, but also for teams needing reproducibility and onboarding ease.

These principles are not just technical choices โ€” they're part of a commitment to making this toolkit secure, stable, and genuinely useful in professional environments.


๐Ÿš€ Key Features

This toolkit was designed with reliability and real-world use in mind:

  • โœ… Modular architecture โ€” easy to integrate and extend
  • โœ… Intelligent retry mechanism with exponential backoff (via tenacity)
  • โœ… Fully compatible with OpenAI-style request formats
  • โœ… CLI-first design โ€” includes rschat for terminal usage and rschat-tools for automation
  • โœ… Secure by design โ€” no telemetry, no external data sent
  • โœ… Production-ready โ€” suitable for professional, CI/CD-integrated environments
  • โœ… Transparent logging โ€” opt-in logging of all interactions with token usage and config
  • โœ… Smart token tracking โ€” includes input/output/total token count (with fallback)
  • โœ… Reproducible outputs โ€” seed-based generation for deterministic results
  • โœ… Config utilities โ€” reusable get_model_config() function to define model behavior

๐Ÿ” Security

Security is a core pillar of this project โ€” not an afterthought.

  • โœ… All code is fully open, auditable, and free from telemetry or tracking
  • โœ… No data is ever sent externally โ€” all logic executes locally and transparently
  • โœ… Direct pushes and unreviewed merges are blocked by default via GitHub branch protection
  • โœ… Releases are manually reviewed and published by the maintainer

If you discover any security vulnerabilities or have concerns:

This project follows responsible disclosure practices. Thank you for helping keep the ecosystem secure.


๐Ÿ“‹ Requirements

  • Python 3.9 or higher
  • An active Azure OpenAI resource and deployment

๐Ÿ“„ License

This project is open source and licensed under the MIT License, ensuring maximum flexibility and adoption.

You are free to use it in both personal and commercial projects.


๐Ÿงช Quick Start

โš ๏ธ Requires Python 3.9+ and internet access. ๐Ÿ“‚ View setup scripts

Don't want to deal with virtual environments or manual setup?

Set up your environment with one command:

โ–ถ๏ธ Windows (PowerShell):

iwr -useb https://raw.githubusercontent.com/renan-siqueira/rsazure-openai-toolkit/main/scripts/setup.ps1 | iex

๐Ÿง Linux/macOS (Bash):

curl -sSfL https://raw.githubusercontent.com/renan-siqueira/rsazure-openai-toolkit/main/scripts/setup.sh | bash

This will:

  • Create a virtual environment
  • Activate it
  • Install rsazure-openai-toolkit
  • Print usage instructions

Ideal for both beginners and experienced developers ๐Ÿš€

๐Ÿ’ฌ Want to try it out quickly? Run rschat-tools samples after setup to see ready-to-run examples.


๐Ÿ’ป Manual Setup (Alternative)

From PyPI:

pip install rsazure-openai-toolkit

From GitHub:

pip install git+https://github.com/renan-siqueira/rsazure-openai-toolkit

Usage

from rsazure_openai_toolkit import call_azure_openai_handler

response = call_azure_openai_handler(
    api_key="your-api-key",
    azure_endpoint="https://your-resource.openai.azure.com/",
    api_version="2023-12-01-preview",
    deployment_name="gpt-35-turbo",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Summarize what artificial intelligence is."}
    ]
)

print(response)

Environment Configuration

To simplify local development and testing, this toolkit supports loading environment variables from a .env file.

Create a .env file in your project root (or copy the provided .env.example) and add your Azure OpenAI credentials:

AZURE_OPENAI_API_KEY=your-api-key
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
AZURE_OPENAI_API_VERSION=2023-12-01-preview
AZURE_DEPLOYMENT_NAME=your-deployment-name

In your script, load the environment variables before calling the handler:

from dotenv import load_dotenv
import os

load_dotenv()  # defaults to loading from .env in the current directory

from rsazure_openai_toolkit import call_azure_openai_handler

response = call_azure_openai_handler(
    api_key=os.getenv("AZURE_OPENAI_API_KEY"),
    azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
    api_version=os.getenv("AZURE_OPENAI_API_VERSION"),
    deployment_name=os.getenv("AZURE_DEPLOYMENT_NAME"),
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Summarize what artificial intelligence is."}
    ]
)

๐Ÿ“Š Logging and Usage Tracking

This toolkit gives you full control over logging behavior โ€” by default, no logs are saved unless explicitly configured.

To enable logging:

RSCHAT_LOG_MODE=jsonl      # or csv
RSCHAT_LOG_PATH=~/.rsazure/chat_logs.jsonl

What gets logged:

  • Prompt and response
  • Token usage (input, output, total)
  • Model used
  • Seed (if any)
  • Response time
  • Raw API response
  • Full model configuration

This helps with debugging, cost estimation, and auditability โ€” without compromising privacy.

If you set RSCHAT_LOG_MODE=none or omit both variables, no logs will be generated โ€” respecting user intent by design.


๐Ÿ”ง Advanced Configuration (Optional)

This toolkit provides a utility function called get_model_config() to help you explicitly configure OpenAI model behavior โ€” in a way that is transparent, reproducible, and easy to override.

It returns a dictionary of model parameters that can be passed directly into the call_azure_openai_handler.

โœ… Benefits:

  • Clear defaults for fast iteration
  • Full support for OpenAI parameters
  • Reproducible generation with optional seed
  • Easy to override only what you need

๐Ÿ” Supported Parameters

Parameter Description
temperature Controls randomness (0.0 = deterministic, 1.0 = more creative)
max_tokens Maximum number of tokens to generate
seed Makes generation deterministic for same input (if supported by model)
top_p Controls diversity via nucleus sampling
frequency_penalty Penalizes repetition
presence_penalty Encourages introduction of new topics
stop Sequence(s) to stop generation (e.g., "\nUser:")
user Optional user identifier (e.g., "rschat-cli")
logit_bias Bias certain tokens (e.g., {token_id: -100} to suppress a token)

โš™๏ธ Default Configuration

If you call get_model_config() with no arguments, you get:

from rsazure_openai_toolkit.utils.model_config_utils import get_model_config

model_config = get_model_config()

# Returns:
# {
#     "temperature": 0.7,
#     "max_tokens": 1024,
#     "seed": 1
# }

This ensures a balance of creativity, length, and reproducibility.


๐Ÿงฉ Custom Overrides

You can selectively override any parameter using the overrides argument:

# Adjust temperature and disable seed for non-deterministic behavior
config = get_model_config(overrides={"temperature": 0.5}, seed=None)

# Set a custom top_p and seed
config = get_model_config(overrides={"top_p": 0.9}, seed=42)

# Completely override everything
config = get_model_config(overrides={
    "temperature": 0.2,
    "max_tokens": 512,
    "seed": 123,
    "frequency_penalty": 0.5
})

If seed is provided as both an argument and inside overrides, the override takes precedence:

get_model_config(overrides={"seed": 99}, seed=1)  # โ†’ uses seed=99

๐Ÿ”„ Why This Matters

In production scenarios, controlling model behavior explicitly improves:

  • Cost and token budgeting
  • Debugging and reproducibility
  • Output consistency for testing and evaluation

Youโ€™re always in control โ€” no hidden defaults.


๐Ÿ’ก This function powers the CLI (rschat) under the hood, and you can reuse it in your own apps or pipelines.


๐Ÿ’ป CLI Usage (rschat)

After installing the package, you can interact with Azure OpenAI directly from your terminal using:

rschat "What can you do for me?"

Make sure you have a valid .env file with your Azure credentials configured:

AZURE_OPENAI_API_KEY=your-api-key
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
AZURE_OPENAI_API_VERSION=2023-12-01-preview
AZURE_DEPLOYMENT_NAME=your-deployment-name

You can also ask in Portuguese (or any supported language):

rschat "Resuma o que รฉ inteligรชncia artificial"

If any required variable is missing, the CLI will exit with a clear error message.

๐Ÿ“ Logging with CLI

To enable logging while using the CLI:

RSCHAT_LOG_MODE=jsonl
RSCHAT_LOG_PATH=~/.rsazure/chat_logs.jsonl

This will record your interactions, including prompt, response, token usage, seed, and full configuration.

To disable logging:

RSCHAT_LOG_MODE=none
# Or omit RSCHAT_LOG_MODE and RSCHAT_LOG_PATH variables

๐Ÿงฐ Developer Tools (rschat-tools)

The toolkit includes a companion CLI called rschat-tools to assist with setup and onboarding.

To generate sample projects in your current directory, run:

rschat-tools samples

You'll see an interactive menu like this:

[0] Exit
[1] Basic Usage
[2] Advanced Usage
[3] Env Usage
[4] Env + Advanced Usage
[all] Generate All

Choose an option, and a folder will be created inside ./samples/ containing ready-to-run scripts and configurations.

๐Ÿ’ก Samples that include a chat loop will clearly display: Type 'exit' to quit
This ensures the CLI is friendly even for non-developers who might not be familiar with Ctrl+C.

You can generate all examples at once using:

rschat-tools samples
# then select: all

This is the fastest way to explore real usage examples and start integrating Azure OpenAI with minimal setup.


๐Ÿšจ Possible Issues

  • Invalid API Key or Endpoint
    Ensure your AZURE_OPENAI_API_KEY and AZURE_OPENAI_ENDPOINT are correctly set in your .env file.

  • Deployment Not Found
    Check that your deployment_name matches exactly the name defined in your Azure OpenAI resource.

  • Timeouts or 5xx Errors
    The toolkit includes automatic retries with exponential backoff via tenacity. If errors persist, verify network access or Azure service status.

  • Missing Environment Variables
    Always ensure load_dotenv() is called before accessing os.getenv(...), especially when testing locally.


๐Ÿ“ฆ Changelog

We follow semantic versioning to ensure predictable upgrades.

  • ๐Ÿ”Ž Check the full CHANGELOG.md for detailed release notes
  • ๐Ÿ“Œ Visit the Releases Page to explore version history

๐Ÿ‘จโ€๐Ÿ’ป About the Author

I'm a software engineer with real-world experience across backend, frontend, DevOps, cloud, and AI โ€” building solutions that are designed to last.

Today, my passion is helping teams make AI development more accessible, maintainable, and truly production-ready โ€” with full control, transparency, and respect for sound engineering principles.

I believe that great tools should be simple, powerful, and built to empower โ€” not to lock people in. Thatโ€™s the mindset behind everything I build and share.


๐Ÿ“ฌ Contact

I'm always open to feedback, ideas, or professional collaboration.

Feel free to connect or open an issue.
Suggestions, contributions, and responsible disclosures are always welcome.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rsazure_openai_toolkit-0.4.0.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rsazure_openai_toolkit-0.4.0-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file rsazure_openai_toolkit-0.4.0.tar.gz.

File metadata

  • Download URL: rsazure_openai_toolkit-0.4.0.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for rsazure_openai_toolkit-0.4.0.tar.gz
Algorithm Hash digest
SHA256 ad6c290f14fbd729d00fe39b1bf7ab13bb041961ed3283c63ccfc3e700cb4e99
MD5 5360d030e28f4d35680f032d0961964e
BLAKE2b-256 f69c4235f21a56ccbcc03d10328c40647f80e22e4a6af9bd7d3ec0804e05e775

See more details on using hashes here.

File details

Details for the file rsazure_openai_toolkit-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for rsazure_openai_toolkit-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4330c18f7ad081d0f63ec78df813d2f83ab13384754eb04e12fec77855820e85
MD5 f800a00af59353e02c335a4f5221692c
BLAKE2b-256 f7a74fbecd05dcccb307d1ebdcdf0c167fb486304b5e2961304a07fc489c0c5c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page