Method
client.tunings.get(
name: str,
config: Optional[GetTuningJobConfig] = None
) -> TuningJob
Retrieves detailed information about a specific tuning job by its resource name.
The resource name of the tuning job. Format:
- Vertex AI:
projects/{project}/locations/{location}/tuningJobs/{job_id}
- Gemini API:
tunedModels/{model_id}
Optional configuration for the requestShow Configuration Fields
Custom HTTP options for the request
Response
The resource name of the tuning job
Current state of the tuning job:
JOB_STATE_QUEUED
JOB_STATE_PENDING
JOB_STATE_RUNNING
JOB_STATE_SUCCEEDED
JOB_STATE_FAILED
JOB_STATE_CANCELLED
ISO 8601 timestamp when the job was created
ISO 8601 timestamp when the job started
ISO 8601 timestamp when the job completed
ISO 8601 timestamp of the last update
The base model that is being tuned
Information about the resulting tuned model (available after completion)
The resource name of the tuned model
The endpoint to use for the tuned model
Error information if the job failed
Description of the tuning job (Vertex AI only)
Statistics about the training data (Vertex AI only)
Usage
Check Job Status
from google import genai
client = genai.Client(api_key='your-api-key')
# Get tuning job details
tuning_job = client.tunings.get(
name='projects/my-project/locations/us-central1/tuningJobs/123456'
)
print(f"Job: {tuning_job.name}")
print(f"State: {tuning_job.state}")
print(f"Created: {tuning_job.create_time}")
if tuning_job.state == 'JOB_STATE_SUCCEEDED':
print(f"Tuned model: {tuning_job.tuned_model.model}")
Monitor Job Progress
import time
from google.genai import types
job_name = 'projects/my-project/locations/us-central1/tuningJobs/123456'
while True:
tuning_job = client.tunings.get(name=job_name)
print(f"Current state: {tuning_job.state}")
# Check if job is complete
if tuning_job.state in [
types.JobState.JOB_STATE_SUCCEEDED,
types.JobState.JOB_STATE_FAILED,
types.JobState.JOB_STATE_CANCELLED
]:
break
# Wait before checking again
time.sleep(60)
if tuning_job.state == types.JobState.JOB_STATE_SUCCEEDED:
print(f"Success! Tuned model: {tuning_job.tuned_model.model}")
else:
print(f"Job ended with state: {tuning_job.state}")
if tuning_job.error:
print(f"Error: {tuning_job.error}")
Handle Job Completion
from google.genai import types
tuning_job = client.tunings.get(name=job_name)
# Check job status and take action
if tuning_job.state == types.JobState.JOB_STATE_SUCCEEDED:
# Use the tuned model
model = tuning_job.tuned_model.model
response = client.models.generate_content(
model=model,
contents='Test the tuned model'
)
print(response.text)
elif tuning_job.state == types.JobState.JOB_STATE_FAILED:
print(f"Tuning failed: {tuning_job.error}")
elif tuning_job.state == types.JobState.JOB_STATE_RUNNING:
elapsed = tuning_job.update_time - tuning_job.start_time
print(f"Job still running, elapsed time: {elapsed}")
See Also