Created
December 6, 2025 01:39
-
-
Save blubberdiblub/0ee441a5f681a9ef231e4004a8e557d9 to your computer and use it in GitHub Desktop.
List Mistral AI models using an appropriate MISTRAL_API_KEY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import os | |
| import sys | |
| from shutil import get_terminal_size | |
| from mistralai import Mistral | |
| from mistralai.utils import BackoffStrategy, RetryConfig | |
| MISTRAL_API_KEY = os.getenv('MISTRAL_API_KEY', '').strip() or input("MISTRAL_API_KEY: ").strip() or None | |
| MISTRAL_API_URL = os.getenv('MISTRAL_API_URL', '').strip() or None # https://api.mistral.ai/ | |
| RETRY_CONFIG = RetryConfig('backoff', BackoffStrategy(1, 120, 2.1, 120), True) | |
| TIMEOUT_MS = 30000 | |
| HAS_CAPABILITY = "…✓" | |
| IS_DEPRECATED = " ✕" | |
| def main(*, limit_width: int = None) -> None: | |
| headers = tuple(h if len(h) <= 2 or h.isupper() else h.title() for h in ( | |
| "owned by", | |
| "type", | |
| "ID", | |
| "name", | |
| "context", | |
| "temp", | |
| "C", | |
| "A", | |
| "t", | |
| "f", | |
| "v", | |
| "c", | |
| "D", | |
| "replacement", | |
| "description", | |
| )) | |
| rows = [] | |
| with Mistral( | |
| api_key=MISTRAL_API_KEY, | |
| server_url=MISTRAL_API_URL, | |
| retry_config=RETRY_CONFIG, | |
| timeout_ms=TIMEOUT_MS, | |
| ) as mistral: | |
| for model in mistral.models.list().data or []: | |
| capabilities = model.capabilities | |
| rows.append( | |
| tuple(str(v) if isinstance(v, str) else repr(v) for v in ( | |
| model.owned_by, | |
| model.TYPE, | |
| model.id, | |
| model.name, | |
| f"{model.max_context_length:7}", | |
| model.default_model_temperature, | |
| HAS_CAPABILITY[bool(capabilities.completion_chat)], | |
| HAS_CAPABILITY[bool(capabilities.completion_fim)], | |
| HAS_CAPABILITY[bool(capabilities.function_calling)], | |
| HAS_CAPABILITY[bool(capabilities.fine_tuning)], | |
| HAS_CAPABILITY[bool(capabilities.vision)], | |
| HAS_CAPABILITY[bool(capabilities.classification)], | |
| IS_DEPRECATED[bool(model.deprecation)], | |
| model.deprecation_replacement_model, | |
| model.description, | |
| )) | |
| ) | |
| widths = tuple( | |
| max((len(r[i]) for r in rows), default=len(headers[i])) | |
| for i in range(len(headers)) | |
| ) | |
| lines = [ | |
| " ".join(s.ljust(w) for s, w in zip(headers, widths)), | |
| "\u2500" * (sum(widths) + len(widths) - 1), | |
| ] | |
| for row in rows: | |
| lines.append(" ".join(s.ljust(w) for s, w in zip(row, widths))) | |
| for line in lines: | |
| if limit_width is None: | |
| print(line) | |
| else: | |
| print(line[:limit_width]) | |
| if __name__ == '__main__': | |
| sys.exit( | |
| main(limit_width=get_terminal_size().columns if sys.stdout.isatty() | |
| else None) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment