OpenAI SDK Compatibility

Use Halfred as a drop-in replacement for OpenAI with existing OpenAI SDK libraries. Simply point your client to Halfred's endpoint.

Why Use OpenAI SDK with Halfred?

  • Ready-to-use SDKs: Access Halfred through battle-tested OpenAI SDKs available in most common programming languages (Go, PHP, Ruby, Java, .NET, Rust, and more)

  • Drop-in replacement: Use existing OpenAI code with zero modifications

  • Intelligent model routing: Benefit from Halfred's profile-based model selection

  • Cost optimization: Automatic selection of the best model for your use case

  • Multi-provider access: Access models from OpenAI, Anthropic, Google, and more through a single interface

  • Enhanced reliability: Built-in failover and load balancing

💡 Tip: For the most up-to-date OpenAI SDK documentation and library references for your programming language, visit the official OpenAI SDK libraries page. All official and community-maintained OpenAI SDKs listed there are compatible with Halfred.

Quick Setup

Base URL Configuration

Instead of using OpenAI's default endpoint, configure your client to use Halfred's API:

Base URL: https://api.halfred.ai/v1/
API Key: Your Halfred API key (starts with "halfred_")

Language-Specific Examples

JavaScript/TypeScript (Node.js)

Installation

Configuration

Environment Variables

Python

Installation

Configuration

Environment Variables

Go

Installation

Configuration

PHP

Installation

Configuration

Ruby

Installation

Configuration

Model Selection

When using the OpenAI SDK with Halfred, use Halfred's profile names instead of specific model names:

Available Models

Model Name
Halfred Profile
Description

lite

LITE

Fast and cost-effective for simple tasks

standard

STANDARD

Balanced performance for most applications

deepthink

DEEPTHINK

Advanced reasoning for complex tasks

dev

DEV

Free tier for development and testing

Alternative Model Names

You can also use the prefixed format:

  • halfred-lite

  • halfred-standard

  • halfred-deepthink

  • halfred-dev

Both formats are equivalent and will work identically.

Supported Features

✅ Fully Supported

  • Chat Completions: Full support for conversational AI

  • Message Roles: system, user, assistant roles

  • Temperature: Control randomness (0.0 to 2.0)

  • Response Format: JSON mode and structured outputs

  • Token Usage: Accurate token counting and usage statistics

Response Format

Halfred returns responses in the exact same format as OpenAI, with additional metadata:

Additional Fields

Halfred adds these extra fields to the standard OpenAI response:

  • provider: The underlying AI provider used (e.g., "openai", "anthropic")

  • profile: The Halfred profile that was selected

Migration from OpenAI

Step 1: Update Configuration

Replace your OpenAI configuration:

Step 2: Update Model Names

Replace specific OpenAI model names with Halfred profiles:

Step 3: Test Your Integration

Your existing code should work without any other changes. Test with a simple completion:

Best Practices

Model Selection Strategy

Error Handling

Troubleshooting

Common Issues

Authentication Error

Solution: Ensure you're using a valid Halfred API key (format: halfred_xxxx...).

Invalid Model Error

Solution: Use Halfred profile names (lite, standard, deepthink, dev) instead of specific model names.

Base URL Not Set

Solution: Make sure you've set the baseURL to https://api.halfred.ai/v1/.

Timeout Configuration

Retry Logic

Support

For OpenAI SDK compatibility issues:

Last updated