Skip to content

slashml/gatewayz-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GatewayzApi Python SDK

A Python SDK for the GatewayzApi, auto-generated by docsalot from an OpenAPI specification.

Installation

From Source (Recommended)

Navigate to the SDK directory and install in editable mode:

cd /path/to/sdks/python
pip install -e .

Note: If you previously installed the package and it's not working, uninstall and reinstall:

pip uninstall gatewayz -y
pip install -e .

Verify Installation

After installation, run the test script to verify everything is working:

python test_install.py

Or test the import directly:

python -c "from gatewayz import GatewayzApi; print('Installation successful!')"

Requirements

  • Python 3.7+
  • httpx
  • pydantic (v2 compatible)

Quick Start

API Endpoint: https://api.gatewayz.ai Get Your API Key: Sign up at gatewayz.ai

1. Initialize the Client

from gatewayz import GatewayzApi

client = GatewayzApi(
    token="YOUR_API_TOKEN",  # Get from your Gatewayz dashboard
    base_url="https://api.gatewayz.ai"
)

2. Test Connectivity (No Auth Required)

# Health check
health = client.health_check_health_get()
print(f"✓ API Status: {health}")

# Ping test
pong = client.ping_ping_get()
print(f"✓ Ping: {pong}")

3. Common Operations

Get Available Models

# List AI models from the catalog
models = client.models.get_models(limit=10)
for model in models:
    print(f"Model: {model}")

Get Providers

# List available AI providers
providers = client.providers.get_providers()
print(f"Providers: {providers}")

Check Your Balance

# Get your account balance
balance = client.authentication.get_user_balance()
print(f"Balance: {balance}")

Get User Profile

# Retrieve your profile information
profile = client.authentication.get_user_profile()
print(f"Profile: {profile}")

Chat Completion

from gatewayz.types import Message

# Make a chat completion request
response = client.chat.chat_completions(
    model="gpt-3.5-turbo",
    messages=[
        Message(role="system", content="You are a helpful assistant."),
        Message(role="user", content="What is the capital of France?")
    ],
    max_tokens=100,
    temperature=0.7
)
print(f"Response: {response}")

4. Complete Working Example

from gatewayz import GatewayzApi
from gatewayz.types import Message
from gatewayz.core import ApiError

# Initialize client
client = GatewayzApi(
    token="your-api-token-here",
    base_url="https://api.gatewayz.ai"
)

try:
    # Test connection
    print("Testing connection...")
    health = client.health_check_health_get()
    print(f"✓ API is healthy")

    # Get balance
    balance = client.authentication.get_user_balance()
    print(f"✓ Balance: {balance}")

    # Get available models
    models = client.models.get_models(limit=5)
    print(f"✓ Found {len(models)} models")

    # Chat completion
    response = client.chat.chat_completions(
        model="gpt-3.5-turbo",
        messages=[Message(role="user", content="Hello!")],
        max_tokens=50
    )
    print(f"✓ Chat response received")

except ApiError as e:
    print(f"❌ API Error: {e.status_code} - {e.body}")
except Exception as e:
    print(f"❌ Error: {e}")

5. Async Usage

import asyncio
from gatewayz import AsyncGatewayzApi

async def main():
    client = AsyncGatewayzApi(
        token="YOUR_API_TOKEN",
        base_url="https://api.gatewayz.ai"
    )

    # Async requests
    health = await client.health_check_health_get()
    print(f"Health: {health}")

    balance = await client.authentication.get_user_balance()
    print(f"Balance: {balance}")

asyncio.run(main())

6. Error Handling

from gatewayz.core import ApiError
from gatewayz.errors import UnprocessableEntityError

try:
    response = client.chat.chat_completions(...)
except UnprocessableEntityError as e:
    print(f"Validation error: {e}")
except ApiError as e:
    print(f"API error: {e.status_code} - {e.body}")
except Exception as e:
    print(f"Unexpected error: {e}")

Authentication

The SDK supports token-based authentication. You can provide your token in two ways:

Static Token

client = GatewayzApi(
    token="your-api-token-here",
    base_url="https://api.gatewayz.ai"
)

Dynamic Token (Callable)

def get_token():
    # Your logic to fetch/refresh token
    return "your-api-token-here"

client = GatewayzApi(
    token=get_token,
    base_url="https://api.gatewayz.ai"
)

Available Modules

The SDK provides access to multiple API endpoints organized by functionality:

Chat

from gatewayz.types import Message

response = client.chat.chat_completions(
    model="gpt-4",
    messages=[
        Message(role="user", content="Hello, how are you?")
    ],
    session_id=123,
    max_tokens=100,
    temperature=0.7
)

Authentication

# Register a new user
from gatewayz.types import UserRegistrationRequest

user = client.authentication.register_user(
    request=UserRegistrationRequest(
        email="[email protected]",
        # ... other fields
    )
)

Providers

# List available providers
providers = client.providers.list_providers()

Models

# List available models
models = client.models.list_models()

Admin

# Admin operations (requires admin privileges)
users = client.admin.list_users()

Plans & Subscriptions

# Get plan information
plans = client.plans.list_plans()

# Manage subscriptions
subscription = client.subscription.get_subscription()

Stripe Payments

# Manage payment methods
payment_methods = client.stripe_payments.list_payment_methods()

Notifications

# Get notification preferences
preferences = client.notifications.get_preferences()

# Update preferences
client.notifications.update_preferences(
    email_enabled=True,
    push_enabled=False
)

Coupons

# List available coupons
coupons = client.coupons.list_available_coupons()

# Redeem a coupon
redemption = client.coupons.redeem_coupon(coupon_code="SAVE20")

Chat History

# Get chat history
history = client.chat_history.get_sessions(
    user_id="user123",
    limit=10
)

Activity

# Track user activity
activity = client.activity.get_activity(user_id="user123")

Ranking

# Get model rankings
rankings = client.ranking.get_rankings()

Trial

# Start a trial
trial = client.trial.start_trial()

Debug

# Debug endpoints
debug_info = client.debug.get_debug_info()

Advanced Configuration

Custom Timeout

client = GatewayzApi(
    token="YOUR_TOKEN",
    base_url="https://api.gatewayz.ai",
    timeout=120.0  # 120 seconds timeout
)

Custom Headers

client = GatewayzApi(
    token="YOUR_TOKEN",
    base_url="https://api.gatewayz.ai",
    headers={
        "X-Custom-Header": "custom-value"
    }
)

Custom httpx Client

import httpx

custom_client = httpx.Client(
    timeout=120.0,
    follow_redirects=True,
    verify=True
)

client = GatewayzApi(
    token="YOUR_TOKEN",
    base_url="https://api.gatewayz.ai",
    httpx_client=custom_client
)

Request Options

You can pass request-specific options to any method:

from gatewayz.core import RequestOptions

response = client.ping_ping_get(
    request_options=RequestOptions(
        timeout_in_seconds=30,
        max_retries=3,
        additional_headers={"X-Request-ID": "abc123"}
    )
)

Error Handling

from gatewayz.core import ApiError
from gatewayz.errors import UnprocessableEntityError

try:
    response = client.chat.chat_completions(
        model="gpt-4",
        messages=[...]
    )
except UnprocessableEntityError as e:
    print(f"Validation error: {e}")
except ApiError as e:
    print(f"API error: {e.status_code} - {e.body}")
except Exception as e:
    print(f"Unexpected error: {e}")

Type Safety

The SDK is fully typed and includes type stubs for better IDE support:

from gatewayz import GatewayzApi
from gatewayz.types import (
    Message,
    ChatSession,
    UserProfileResponse,
    PlanResponse,
    # ... and many more
)

# Your IDE will provide autocomplete and type checking
client: GatewayzApi = GatewayzApi(token="...", base_url="...")
response: UserProfileResponse = client.authentication.get_profile()

Development

Running Tests

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest tests/

Code Formatting

# Format code
black .

# Sort imports
isort .

Type Checking

# Run mypy for type checking
mypy .

SDK Structure

gatewayz/
├── __init__.py              # Main exports
├── client.py                # Main client classes
├── raw_client.py            # Raw HTTP client
├── core/                    # Core utilities
│   ├── http_client.py
│   ├── client_wrapper.py
│   └── ...
├── types/                   # Type definitions
│   ├── message.py
│   ├── chat_session.py
│   └── ...
├── errors/                  # Error classes
│   └── unprocessable_entity_error.py
└── [modules]/              # API endpoint modules
    ├── chat/
    ├── authentication/
    ├── providers/
    └── ...

Support

For issues and questions:

License

See LICENSE file for details.

Generated by docsalot

This SDK was automatically generated by docsalot from an OpenAPI specification. For more information about docsalot, visit docsalot.dev.

About

No description, website, or topics provided.

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages