Access 20+ large language models through Hyperbolic’s OpenAI-compatible chat completions API. Generate text, have conversations, write code, and more with state-of-the-art open-source models.
Messages are an array of objects with role and content fields:
{ "messages": [ {"role": "system", "content": "You are a helpful coding assistant."}, {"role": "user", "content": "Write a Python function to reverse a string."}, {"role": "assistant", "content": "Here's a function to reverse a string..."}, {"role": "user", "content": "Can you make it more efficient?"} ]}
Roles:
system: Sets the behavior and context for the assistant
user: Messages from the user
assistant: Previous responses from the model (for conversation history)
To maintain conversation context, include the full message history in each request:
Python
cURL
import requestsurl = "https://api.hyperbolic.xyz/v1/chat/completions"headers = { "Content-Type": "application/json", "Authorization": "Bearer YOUR_API_KEY"}# Maintain conversation historymessages = [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is the capital of France?"}, {"role": "assistant", "content": "The capital of France is Paris."}, {"role": "user", "content": "What is its population?"}]response = requests.post(url, headers=headers, json={ "model": "meta-llama/Llama-3.3-70B-Instruct", "messages": messages, "max_tokens": 256})print(response.json()["choices"][0]["message"]["content"])
curl -X POST "https://api.hyperbolic.xyz/v1/chat/completions" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ -d '{ "model": "meta-llama/Llama-3.3-70B-Instruct", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is the capital of France?"}, {"role": "assistant", "content": "The capital of France is Paris."}, {"role": "user", "content": "What is its population?"} ], "max_tokens": 256 }'
Use system prompts to set the model’s behavior, persona, or instructions:
messages = [ { "role": "system", "content": """You are an expert Python developer. Follow these guidelines:- Write clean, well-documented code- Include type hints- Add brief comments explaining complex logic- Suggest improvements when relevant""" }, {"role": "user", "content": "Write a function to find prime numbers."}]
Tool calling (also known as function calling) allows models to invoke external tools and APIs. The model generates structured JSON arguments that your application can use to call functions, then the results can be passed back to continue the conversation.
import requestsimport jsonurl = "https://api.hyperbolic.xyz/v1/chat/completions"headers = { "Content-Type": "application/json", "Authorization": "Bearer YOUR_API_KEY"}# Define available toolstools = [ { "type": "function", "function": { "name": "get_weather", "description": "Get the current weather for a location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "City and state, e.g. San Francisco, CA" }, "unit": { "type": "string", "enum": ["celsius", "fahrenheit"], "description": "Temperature unit" } }, "required": ["location"] } } }]data = { "model": "meta-llama/Llama-3.3-70B-Instruct", "messages": [ {"role": "user", "content": "What's the weather like in San Francisco?"} ], "tools": tools, "tool_choice": "auto"}response = requests.post(url, headers=headers, json=data)result = response.json()# Check if the model wants to call a toolmessage = result["choices"][0]["message"]if message.get("tool_calls"): tool_call = message["tool_calls"][0] print(f"Function: {tool_call['function']['name']}") print(f"Arguments: {tool_call['function']['arguments']}")
curl -X POST "https://api.hyperbolic.xyz/v1/chat/completions" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ -d '{ "model": "meta-llama/Llama-3.3-70B-Instruct", "messages": [ {"role": "user", "content": "What'\''s the weather like in San Francisco?"} ], "tools": [ { "type": "function", "function": { "name": "get_weather", "description": "Get the current weather for a location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "City and state, e.g. San Francisco, CA" }, "unit": { "type": "string", "enum": ["celsius", "fahrenheit"], "description": "Temperature unit" } }, "required": ["location"] } } } ], "tool_choice": "auto" }'
The tool_choice parameter controls how the model uses tools: "auto" lets the model decide, "none" disables tool use, or specify a tool name to force its use.