- A function represents a task or agent in your application (e.g. “write a product description” or “answer a customer question”).
- A variant is a specific way to accomplish it: a choice of model, prompt, inference parameters, etc.
- Collect metrics and feedback: Track performance and gather feedback for optimization.
- Run A/B tests: Experiment with different models, prompts, and parameters.
- Create prompt templates: Decouple prompts from application code for easier iteration.
- Configure retries & fallbacks: Build systems that handle provider downtime gracefully.
- Use advanced inference strategies: Easily implement advanced inference-time optimizations like dynamic in-context-learning and best-of-N sampling.
Configure functions & variants
TensorZero supports two function types:chatis the typical chat interface used by most LLMs. It returns unstructured text responses.jsonis for structured outputs. It returns responses that conform to a JSON schema.
tensorzero.toml
tensorzero.toml
chat_completion, which is the typical chat completion format used by OpenAI and many other LLM providers.
TensorZero supports other variant types that implement inference-time optimizations.
You can define prompt templates in your variant configuration rather than sending prompts directly in your inference requests.
This decouples prompts from application code and enables easier experimentation and optimization.
See Create a prompt template for more details.
If you define multiple variants, TensorZero will randomly sample one of them at inference time.
You can define more advanced experimentation strategies (e.g. Run adaptive A/B tests), fallback-only variants (e.g. Retries & Fallbacks), and more.
Example
Let’s create a function calledanswer_customer with two variants: GPT-5 and Claude Sonnet 4.5.
tensorzero.toml
answer_customer function and TensorZero will randomly select one of the two variants for each request.
Make inference requests
Once you’ve configured a function and its variants, you can make inference requests to the TensorZero Gateway.- Python
- Python (OpenAI SDK)
- Node (OpenAI SDK)
- HTTP