The config object is used to configure API interactions with various providers. It supports multiple modes such as single provider access, load balancing between providers, and fallback strategies.

The following JSON schema is used to validate the config object:

Example Configs

// Simple config with cache and retry
{
  "virtual_key": "***", // Your Virtual Key
  "cache": { // Optional
    "mode": "semantic",
    "max_age": 10000
  },
  "retry": { // Optional
    "attempts": 5,
    "on_status_codes": []
  }
}

// Load balancing with 2 OpenAI keys
{
  "strategy": {
      "mode": "loadbalance"
    },
  "targets": [
    {
      "provider": "openai",
      "api_key": "sk-***"
    },
    {
      "provider": "openai",
      "api_key": "sk-***"
    }
  ]
}

You can find more examples of schemas below.

Schema Details

Key NameDescriptionTypeRequiredEnum ValuesAdditional Info
strategyOperational strategy for the config or any individual targetobjectYes (if no provider or virtual_key)-See Strategy Object Details
providerName of the service providerstringYes (if no mode or virtual_key)“openai”, “anthropic”, “azure-openai”, “anyscale”, “cohere”-
api_keyAPI key for the service providerstringYes (if provider is specified)--
virtual_keyVirtual key identifierstringYes (if no mode or provider)--
cacheCaching configurationobjectNo-See Cache Object Details
retryRetry configurationobjectNo-See Retry Object Details
weightWeight for load balancingnumberNo-Used in loadbalance mode
on_status_codesStatus codes triggering fallbackarray of stringsNo-Used in fallback mode
targetsList of target configurationsarrayYes (if mode is specified)-Each item follows the config schema
request_timeoutRequest timeout configurationnumberNo--
custom_hostRoute to privately hosted modelstringNo-Used in combination with provider + api_key
forward_headersForward sensitive headers directlyarray of stringsNo--
override_paramsPass model name and other hyper parametersobjectNo“model”, “temperature”, “frequency_penalty”, “logit_bias”, “logprobs”, “top_logprobs”, “max_tokens”, “n”, “presence_penalty”, “response_format”, “seed”, “stop”, “top_p”, etc.Pass everything that’s typically part of the payload

Strategy Object Details

Key NameDescriptionTypeRequiredEnum ValuesAdditional Info
modestrategy mode for the configstringYes“loadbalance”, “fallback”
on_status_codesstatus codes to apply the strategy. This field is only used when strategy mode is “fallback”array of numbersNoOptional

Cache Object Details

Key NameDescriptionTypeRequiredEnum ValuesAdditional Info
modeCache modestringYes“simple”, “semantic”-
max_ageMaximum age for cache entriesintegerNo-Optional

Retry Object Details

Key NameDescriptionTypeRequiredEnum ValuesAdditional Info
attemptsNumber of retry attemptsintegerYes--
on_status_codesStatus codes to trigger retriesarray of stringsNo-Optional

Cloud Provider Params (Azure OpenAI, Google Vertex, AWS Bedrock)

Azure OpenAI

Key NameTypeRequired
azure_resource_namestringNo
azure_deployment_idstringNo
azure_api_versionstringNo
azure_model_namestringNo
Authorizationstring (“Bearer $API_KEY”)No

Google Vertex AI

Key NameTypeRequired
vertex_project_idstringNo
vertex_regionstringNo

AWS Bedrock

Key NameTypeRequired
aws_access_key_idstringNo
aws_secret_access_keystringNo
aws_regionstringNo
aws_session_tokenstringNo

Notes

  • The strategy mode key determines the operational mode of the config. If strategy mode is not specified, a single provider mode is assumed, requiring either provider and api_key or virtual_key.
  • In loadbalance and fallback modes, the targets array specifies the configurations for each target.
  • The cache and retry objects provide additional configurations for caching and retry policies, respectively.

Examples