Skip to main content
Version: v2.0

Models

Models are the foundation of intelligence in the aiXplain ecosystem. They encapsulate capabilities such as language understanding, translation, summarisation, speech processing, and more. Models can be run directly or integrated as tools inside agents.

All models share a consistent SDK interface — swap one for another without rewriting pipelines.

Setup

pip install aixplain
from aixplain import Aixplain

aix = Aixplain(api_key="YOUR_API_KEY")

Quick start

model = aix.Model.get("openai/gpt-4o")

response = model.run(text="Why did the chicken cross the road?")
print(response.data)
Show output

Discovering models

# By keyword
llama_models = aix.Model.search("llama")["results"]

# By host, developer, or vendor
openai_models = aix.Model.search("", host="openai")["results"]
meta_models = aix.Model.search("", developer="meta")["results"]
anthropic_models = aix.Model.search("", vendor="anthropic")["results"]

for model in openai_models[:5]:
print(model.name, model.id)
Show output

search() returns a dict — access results via the "results" key.

Search parameters:

ParameterDescription
queryKeyword matched against name and description
hostHosting platform (e.g. "openai", "groq")
developerModel developer (e.g. "meta")
vendorModel vendor / supplier (e.g. "anthropic")

Get a specific model

# By path
model = aix.Model.get("openai/gpt-4o")

# By ID
model = aix.Model.get("6646261c6eb563165658bbb1")

print(model.name, model.id, model.host)
Show output

Running models

Synchronous

model = aix.Model.get("openai/gpt-4o")

response = model.run(text="Explain quantum computing in simple terms")
print(response.data)
print(response.status)
Show output

Supported input types

TypeExample
Textmodel.run(text="Your prompt") or model.run(data="file.txt")
Imagemodel.run(data="image.png")
Audiomodel.run(data="audio.wav")
Videomodel.run(data="video.mp4")
Structuredmodel.run({"text": "prompt", "context": "..."})
note

Image, audio, and video are not supported on-prem. Format and size limits vary by vendor — check the model's page in Studio.

Asynchronous

Use run_async() when you don't want to block on long-running tasks:

import time

model = aix.Model.get("openai/gpt-4o")

start = model.run_async(text="Summarise the history of computing.")

while True:
if not start.url: # task finished immediately
print(start.data)
break

result = model.poll(start.url)

if result.completed:
print(result.data)
break

time.sleep(5)
Show output

Batch async

Start multiple tasks in parallel, then poll until all complete:

import time

model = aix.Model.get("openai/gpt-4o")

prompts = [
"Summarise the benefits of cloud computing",
"Explain blockchain technology",
"Describe machine learning applications",
]

# Kick off all tasks
pending_urls = []
for prompt in prompts:
start = model.run_async(text=prompt)
if start.url:
pending_urls.append(start.url)
else:
print("Completed immediately:", start.data)

# Poll until all finish
results = []
while pending_urls:
for url in pending_urls[:]:
result = model.poll(url)
if result.completed:
results.append(result.data)
pending_urls.remove(url)
time.sleep(3)

for i, output in enumerate(results):
print(f"\n=== Result {i+1} ===\n{output}")
Show output

Configuring model parameters

Use model.inputs to set, inspect, and reset parameters before calling run(). The proxy supports dot notation, dict notation, and bulk updates.

model = aix.Model.get("openai/gpt-4o")

# Set parameters
model.inputs.temperature = 0.3 # dot notation
model.inputs['max_tokens'] = 1024 # dict notation
model.inputs.update(temperature=0.2, max_tokens=1200) # bulk

# Inspect
print(model.inputs.keys()) # all parameter names
print(model.inputs.get_required_parameters()) # required-only
print(model.inputs.get_all_parameters()) # current values as dict

# Reset
model.inputs.reset_parameter("temperature") # single param
model.inputs.reset_all_parameters() # all params
Show output
note

Models do not have .actions. Use model.inputs directly to configure parameters.

# Run with configured parameters
model.inputs.temperature = 0.3
model.inputs.max_tokens = 1024

response = model.run(text="Generate a product description")
print(response.data)
print(f"Completion tokens: {response.usage.completion_tokens}")
Show output

Common LLM parameters:

ParameterDescriptionRange
temperatureRandomness — lower is more deterministic0.02.0
max_tokensMaximum output length1 – model limit
top_pNucleus sampling threshold0.01.0
frequency_penaltyReduces token repetition-2.02.0
presence_penaltyEncourages new topics-2.02.0

Temperature guidance:

model.inputs.temperature = 0.9   # creative tasks (stories, brainstorming)
model.inputs.temperature = 0.3 # factual tasks (summaries, analysis)
model.inputs.temperature = 0.0 # deterministic tasks (code, math)

Using models with agents

Pass a model as the llm for an agent's reasoning loop, or attach it as a tool:

llm = aix.Model.get("openai/gpt-4o")

agent = aix.Agent(
name="Research Assistant",
description="Answers research questions thoroughly.",
instructions="Use the provided LLM to answer questions accurately.",
llm=llm,
)
agent.save()

response = agent.run(query="Explain the difference between supervised and unsupervised learning.")
print(response.data.output)
Show output

Advanced examples

Compare two models

gpt4   = aix.Model.get("openai/gpt-4o")
claude = aix.Model.get("anthropic/claude-3-5-sonnet-v2")

prompt = "Explain the concept of recursion in programming."

print("=== GPT-4o ===")
print(gpt4.run(text=prompt).data)

print("\n=== Claude ===")
print(claude.run(text=prompt).data)
Show output

Translation

translator = aix.Model.get("google/cloud-translation")

response = translator.run(
text="Hello, how are you?",
sourcelanguage="en",
targetlanguage="es",
)
print(response.data)
Show output

Temperature sweep

model = aix.Model.get("openai/gpt-4o")
prompt = "Complete this sentence: The future of AI is"

for temp in [0.0, 0.5, 1.0, 1.5]:
model.inputs.temperature = temp
print(f"\nTemperature {temp}:", model.run(text=prompt).data)
Show output

Troubleshooting

Model not found Verify the path or ID with aix.Model.search(). Check that your API key has access to the model.

Invalid parameters Confirm supported parameters and valid ranges on the model's Studio page. Not all models accept all parameters.

Async tasks timing out Increase the time.sleep() interval for long-running tasks. Check the aiXplain dashboard to confirm the task is still running.

Rate limiting Reduce concurrent requests or use run_async() for batch workloads.

Next steps